Class: Bento::Emails
- Inherits:
-
Object
- Object
- Bento::Emails
- Extended by:
- Validators::Base, Validators::EmailValidators
- Defined in:
- lib/bento/resources/emails.rb
Class Method Summary collapse
-
.send(to:, from:, subject:, html_body:, personalizations: {}) ⇒ Object
Send an email that honors subscription status.
- .send_bulk(emails) ⇒ Object
-
.send_transactional(to:, from:, subject:, html_body:, personalizations: {}) ⇒ Object
Send a transactional email that always sends, even if user is unsubscribed.
Methods included from Validators::EmailValidators
Methods included from Validators::Base
validate_email, validate_fields, validate_type
Class Method Details
permalink .send(to:, from:, subject:, html_body:, personalizations: {}) ⇒ Object
Send an email that honors subscription status
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bento/resources/emails.rb', line 7 def send(to:, from:, subject:, html_body:, personalizations: {}) validate_email(to) (from) payload = { to: to, from: from, subject: subject, html_body: html_body, personalizations: personalizations } send_bulk([payload]) end |
permalink .send_bulk(emails) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/bento/resources/emails.rb', line 39 def send_bulk(emails) raise ArgumentError, 'Emails must be an array' unless emails.is_a?(Array) emails.each { |email| validate_email(email[:to]); validate_email(email[:from]) } payload = { emails: emails }.to_json response = client.post("api/v1/batch/emails?#{URI.encode_www_form(default_params)}", payload) Bento::Response.new(response) end |
permalink .send_transactional(to:, from:, subject:, html_body:, personalizations: {}) ⇒ Object
Send a transactional email that always sends, even if user is unsubscribed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bento/resources/emails.rb', line 23 def send_transactional(to:, from:, subject:, html_body:, personalizations: {}) validate_email(to) (from) payload = { to: to, from: from, subject: subject, html_body: html_body, personalizations: personalizations, transactional: true } send_bulk([payload]) end |