Class: Sendara::Resources::Emails
- Inherits:
-
Sendara::Resource
- Object
- Sendara::Resource
- Sendara::Resources::Emails
- Defined in:
- lib/sendara/resources/emails.rb
Instance Method Summary collapse
- #send(to:, from: nil, subject: nil, html: nil, text: nil, message_type: nil, template_id: nil, template_vars: nil, metadata: nil, store_payload: nil, test_send: nil, idempotency_key: nil) ⇒ Object
- #send_batch(requests) ⇒ Object
- #send_raw(request) ⇒ Object
Methods inherited from Sendara::Resource
Constructor Details
This class inherits a constructor from Sendara::Resource
Instance Method Details
#send(to:, from: nil, subject: nil, html: nil, text: nil, message_type: nil, template_id: nil, template_vars: nil, metadata: nil, store_payload: nil, test_send: nil, idempotency_key: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sendara/resources/emails.rb', line 6 def send(to:, from: nil, subject: nil, html: nil, text: nil, message_type: nil, template_id: nil, template_vars: nil, metadata: nil, store_payload: nil, test_send: nil, idempotency_key: nil) = .nil? ? {} : .dup ["from_email"] = from unless from.nil? body = { "channel" => "email", "idempotency_key" => idempotency_key || Client.generate_idempotency_key, "destination" => { "email" => to }, "payload" => { "subject" => subject, "body_html" => html, "body_text" => text }, "metadata" => } body["message_type"] = unless .nil? body["template_id"] = template_id unless template_id.nil? body["template_vars"] = template_vars unless template_vars.nil? body["store_payload"] = store_payload unless store_payload.nil? body["test_send"] = test_send unless test_send.nil? send_raw(body) end |
#send_batch(requests) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/sendara/resources/emails.rb', line 39 def send_batch(requests) body = requests.map do |req| req = req.dup req["idempotency_key"] ||= Client.generate_idempotency_key req end request(:post, "/v1/send/batch", body: body) || [] end |
#send_raw(request) ⇒ Object
33 34 35 36 37 |
# File 'lib/sendara/resources/emails.rb', line 33 def send_raw(request) request = request.dup request["idempotency_key"] ||= Client.generate_idempotency_key request(:post, "/v1/send", body: request) || {} end |