Class: Axene::Mailer::Resources::Emails
- Inherits:
-
Object
- Object
- Axene::Mailer::Resources::Emails
- Defined in:
- lib/axene/mailer/resources/emails.rb
Overview
The emails resource: send, look up, search, schedule, and inspect messages. Accessed as client.emails.
Instance Method Summary collapse
-
#cancel_scheduled(id) ⇒ Hash
Cancel a scheduled email.
-
#events(id) ⇒ Array<Hash>
List delivery / open / click / bounce events for an email.
-
#get(id) ⇒ Hash
Fetch a single email with its bodies and events.
-
#get_saved_searches ⇒ Array<Hash>
Get the caller’s saved searches.
-
#initialize(transport) ⇒ Emails
constructor
A new instance of Emails.
-
#list(status: nil, page: 0, limit: 20) ⇒ Array<Hash>
List recent emails, newest first.
-
#list_scheduled ⇒ Array<Hash>
List emails scheduled for future delivery, soonest first.
-
#retry(id) ⇒ Hash
Re-send a bounced, rejected, or failed email as a new message.
-
#search(q: nil, status: nil, tag: nil, page: 0, limit: 20) ⇒ Array<Hash>
Search emails.
-
#send(message = {}, **kwargs) ⇒ Hash
Send a single email.
-
#send_batch(messages) ⇒ Hash
Send up to your plan’s batch limit in one call.
-
#send_scheduled_now(id) ⇒ Hash
Send a scheduled email immediately instead of waiting.
-
#set_saved_searches(searches) ⇒ Array<Hash>
Replace the caller’s saved searches (max 50).
-
#updates(since) ⇒ Array<Hash>
Poll for emails whose status changed at or after
since(ISO 8601 string or a Time). -
#validate(message = {}, **kwargs) ⇒ Hash
Dry-run a send: check whether
messagewould be accepted without actually sending it.
Constructor Details
#initialize(transport) ⇒ Emails
Returns a new instance of Emails.
10 11 12 |
# File 'lib/axene/mailer/resources/emails.rb', line 10 def initialize(transport) @transport = transport end |
Instance Method Details
#cancel_scheduled(id) ⇒ Hash
Cancel a scheduled email.
105 106 107 |
# File 'lib/axene/mailer/resources/emails.rb', line 105 def cancel_scheduled(id) @transport.request(:delete, "/v1/emails/scheduled/#{escape(id)}") end |
#events(id) ⇒ Array<Hash>
List delivery / open / click / bounce events for an email.
68 69 70 |
# File 'lib/axene/mailer/resources/emails.rb', line 68 def events(id) @transport.request(:get, "/v1/emails/#{escape(id)}/events") end |
#get(id) ⇒ Hash
Fetch a single email with its bodies and events.
60 61 62 |
# File 'lib/axene/mailer/resources/emails.rb', line 60 def get(id) @transport.request(:get, "/v1/emails/#{escape(id)}") end |
#get_saved_searches ⇒ Array<Hash>
Get the caller’s saved searches.
130 131 132 |
# File 'lib/axene/mailer/resources/emails.rb', line 130 def get_saved_searches @transport.request(:get, "/v1/emails/saved-searches")[:searches] end |
#list(status: nil, page: 0, limit: 20) ⇒ Array<Hash>
List recent emails, newest first.
52 53 54 |
# File 'lib/axene/mailer/resources/emails.rb', line 52 def list(status: nil, page: 0, limit: 20) @transport.request(:get, "/v1/emails/", query: { status: status, page: page, limit: limit }) end |
#list_scheduled ⇒ Array<Hash>
List emails scheduled for future delivery, soonest first.
97 98 99 |
# File 'lib/axene/mailer/resources/emails.rb', line 97 def list_scheduled @transport.request(:get, "/v1/emails/scheduled") end |
#retry(id) ⇒ Hash
Re-send a bounced, rejected, or failed email as a new message.
76 77 78 |
# File 'lib/axene/mailer/resources/emails.rb', line 76 def retry(id) @transport.request(:post, "/v1/emails/#{escape(id)}/retry") end |
#search(q: nil, status: nil, tag: nil, page: 0, limit: 20) ⇒ Array<Hash>
Search emails. q supports inline tokens (to:, from:, status:, domain:, tag:); leftover words are matched as free text.
89 90 91 92 |
# File 'lib/axene/mailer/resources/emails.rb', line 89 def search(q: nil, status: nil, tag: nil, page: 0, limit: 20) @transport.request(:get, "/v1/emails/search", query: { q: q, status: status, tag: tag, page: page, limit: limit }) end |
#send(message = {}, **kwargs) ⇒ Hash
Send a single email.
Accepts keyword arguments or a Hash. The from field is exposed cleanly and mapped to the wire name from_. A bare String is accepted anywhere an address is expected and becomes { email: … }.
22 23 24 25 |
# File 'lib/axene/mailer/resources/emails.rb', line 22 def send( = {}, **kwargs) body = serialize_send(.empty? ? kwargs : ) @transport.request(:post, "/v1/emails/", body: body) end |
#send_batch(messages) ⇒ Hash
Send up to your plan’s batch limit in one call. The API accepts a bare array of messages and returns a per-message result set.
32 33 34 |
# File 'lib/axene/mailer/resources/emails.rb', line 32 def send_batch() @transport.request(:post, "/v1/emails/batch", body: .map { |m| serialize_send(m) }) end |
#send_scheduled_now(id) ⇒ Hash
Send a scheduled email immediately instead of waiting.
113 114 115 |
# File 'lib/axene/mailer/resources/emails.rb', line 113 def send_scheduled_now(id) @transport.request(:post, "/v1/emails/scheduled/#{escape(id)}/send-now") end |
#set_saved_searches(searches) ⇒ Array<Hash>
Replace the caller’s saved searches (max 50).
138 139 140 |
# File 'lib/axene/mailer/resources/emails.rb', line 138 def set_saved_searches(searches) @transport.request(:put, "/v1/emails/saved-searches", body: { searches: searches })[:searches] end |
#updates(since) ⇒ Array<Hash>
Poll for emails whose status changed at or after since (ISO 8601 string or a Time). Capped at 50 rows.
122 123 124 125 |
# File 'lib/axene/mailer/resources/emails.rb', line 122 def updates(since) iso = since.respond_to?(:iso8601) ? since.iso8601 : since @transport.request(:get, "/v1/emails/updates", query: { since: iso }) end |
#validate(message = {}, **kwargs) ⇒ Hash
Dry-run a send: check whether message would be accepted without actually sending it. Uses the full send body.
41 42 43 44 |
# File 'lib/axene/mailer/resources/emails.rb', line 41 def validate( = {}, **kwargs) body = serialize_send(.empty? ? kwargs : ) @transport.request(:post, "/v1/emails/validate", body: body) end |