Class: Bento::Emails

Inherits:
Object
  • Object
show all
Extended by:
Validators::Base, Validators::EmailValidators
Defined in:
lib/bento/resources/emails.rb

Class Method Summary collapse

Methods included from Validators::EmailValidators

validate_author

Methods included from Validators::Base

validate_email, validate_fields, validate_type

Class Method Details

.send(to:, from:, subject:, html_body:, personalizations: {}) ⇒ Object

Send an email that honors subscription status

[View source]

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)
  validate_author(from)

  payload = {
    to: to,
    from: from,
    subject: subject,
    html_body: html_body,
    personalizations: personalizations
  }

  send_bulk([payload])
end

.send_bulk(emails) ⇒ Object

Raises:

[View source]

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

.send_transactional(to:, from:, subject:, html_body:, personalizations: {}) ⇒ Object

Send a transactional email that always sends, even if user is unsubscribed

[View source]

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)
  validate_author(from)

  payload = {
    to: to,
    from: from,
    subject: subject,
    html_body: html_body,
    personalizations: personalizations,
    transactional: true
  }

  send_bulk([payload])
end