Class: Quolle::Resources::Emails
- Inherits:
-
Object
- Object
- Quolle::Resources::Emails
- Defined in:
- lib/quolle/resources/emails.rb
Overview
Send and manage emails.
Instance Method Summary collapse
-
#cancel(id) ⇒ Hash
Cancel a scheduled email that has not yet been sent.
-
#get(id) ⇒ Hash
Retrieve a single email by ID.
-
#initialize(client) ⇒ Emails
constructor
A new instance of Emails.
-
#send(idempotency_key: nil, **params) ⇒ Hash
Queue an email for immediate or scheduled delivery.
-
#send_batch(emails, idempotency_key: nil) ⇒ Hash
Send up to 100 emails in one all-or-nothing request.
Constructor Details
#initialize(client) ⇒ Emails
Returns a new instance of Emails.
7 8 9 |
# File 'lib/quolle/resources/emails.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#cancel(id) ⇒ Hash
Cancel a scheduled email that has not yet been sent.
43 44 45 |
# File 'lib/quolle/resources/emails.rb', line 43 def cancel(id) @client.request("DELETE", "/v1/emails/#{escape(id)}/cancel") end |
#get(id) ⇒ Hash
Retrieve a single email by ID.
36 37 38 39 |
# File 'lib/quolle/resources/emails.rb', line 36 def get(id) resp = @client.request("GET", "/v1/emails/#{escape(id)}") resp["email"] || resp end |
#send(idempotency_key: nil, **params) ⇒ Hash
Queue an email for immediate or scheduled delivery.
Provide either :html (with :subject) or a :template slug (with
optional :variables). Pass idempotency_key: to make retries safe.
19 20 21 22 |
# File 'lib/quolle/resources/emails.rb', line 19 def send(idempotency_key: nil, **params) headers = idempotency_key ? { "Idempotency-Key" => idempotency_key } : {} @client.request("POST", "/v1/emails/send", body: normalize(params), headers: headers) end |
#send_batch(emails, idempotency_key: nil) ⇒ Hash
Send up to 100 emails in one all-or-nothing request.
28 29 30 31 32 |
# File 'lib/quolle/resources/emails.rb', line 28 def send_batch(emails, idempotency_key: nil) headers = idempotency_key ? { "Idempotency-Key" => idempotency_key } : {} body = { emails: emails.map { |e| normalize(e) } } @client.request("POST", "/v1/emails/batch", body: body, headers: headers) end |