Class: Unitpost::Resources::Email

Inherits:
Base
  • Object
show all
Defined in:
lib/unitpost/resources.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Email

Returns a new instance of Email.



52
53
54
55
56
57
58
# File 'lib/unitpost/resources.rb', line 52

def initialize(http)
  super
  @topics = Topics.new(http)
  @campaigns = Campaigns.new(http)
  @templates = Templates.new(http)
  @domains = Domains.new(http)
end

Instance Attribute Details

#campaignsObject (readonly)

Returns the value of attribute campaigns.



50
51
52
# File 'lib/unitpost/resources.rb', line 50

def campaigns
  @campaigns
end

#domainsObject (readonly)

Returns the value of attribute domains.



50
51
52
# File 'lib/unitpost/resources.rb', line 50

def domains
  @domains
end

#templatesObject (readonly)

Returns the value of attribute templates.



50
51
52
# File 'lib/unitpost/resources.rb', line 50

def templates
  @templates
end

#topicsObject (readonly)

Returns the value of attribute topics.



50
51
52
# File 'lib/unitpost/resources.rb', line 50

def topics
  @topics
end

Instance Method Details

#batch(body, idempotency_key: nil) ⇒ Object

Send up to 100 emails in one request (all-or-nothing validation). Like send, when no idempotency_key is given the SDK generates one so a transient retry is safe: the server dedupes the batch on the key and replays the original result instead of re-sending. Pass your own to dedupe across separate batch calls.



72
73
74
# File 'lib/unitpost/resources.rb', line 72

def batch(body, idempotency_key: nil)
  @http.request("POST", "/email/batch", body: body, idempotency_key: idempotency_key || SecureRandom.uuid)
end

#cancel_batch(id) ⇒ Object



80
81
82
# File 'lib/unitpost/resources.rb', line 80

def cancel_batch(id)
  @http.request("POST", "/email/batches/#{enc(id)}/cancel")
end

#get(id) ⇒ Object



92
93
94
# File 'lib/unitpost/resources.rb', line 92

def get(id)
  @http.request("GET", "/email/#{enc(id)}")
end

#get_batch(id) ⇒ Object



76
77
78
# File 'lib/unitpost/resources.rb', line 76

def get_batch(id)
  @http.request("GET", "/email/batches/#{enc(id)}")
end

#list(limit: nil, after: nil, before: nil, **filters) ⇒ Object



84
85
86
# File 'lib/unitpost/resources.rb', line 84

def list(limit: nil, after: nil, before: nil, **filters)
  @http.request("GET", "/email", query: list_params(limit: limit, after: after, before: before, **filters))
end

#list_all(**params) ⇒ Object



88
89
90
# File 'lib/unitpost/resources.rb', line 88

def list_all(**params)
  paginate("/email", params)
end

#received_attachment_url(id, attachment_id) ⇒ Object



114
115
116
# File 'lib/unitpost/resources.rb', line 114

def received_attachment_url(id, attachment_id)
  @http.request("GET", "/email/received/#{enc(id)}/attachments/#{enc(attachment_id)}")
end

#received_get(id) ⇒ Object



110
111
112
# File 'lib/unitpost/resources.rb', line 110

def received_get(id)
  @http.request("GET", "/email/received/#{enc(id)}")
end

#received_list(limit: nil, after: nil, before: nil) ⇒ Object



106
107
108
# File 'lib/unitpost/resources.rb', line 106

def received_list(limit: nil, after: nil, before: nil)
  @http.request("GET", "/email/received", query: list_params(limit: limit, after: after, before: before))
end

#send(body, idempotency_key: nil) ⇒ Object

Send or schedule a transactional email. When no idempotency_key is given the SDK generates one so a transient retry can't double-send; pass your own to dedupe across separate send calls.



63
64
65
# File 'lib/unitpost/resources.rb', line 63

def send(body, idempotency_key: nil)
  @http.request("POST", "/email", body: body, idempotency_key: idempotency_key || SecureRandom.uuid)
end

#stats(days: nil) ⇒ Object

Deliverability/engagement aggregates over a rolling window (days: 1–365, defaults to 30 server-side).



102
103
104
# File 'lib/unitpost/resources.rb', line 102

def stats(days: nil)
  @http.request("GET", "/email/stats", query: { days: days })
end

#update(id, body) ⇒ Object



96
97
98
# File 'lib/unitpost/resources.rb', line 96

def update(id, body)
  @http.request("PATCH", "/email/#{enc(id)}", body: body)
end