Class: MnoEnterprise::MailAdapters::SparkpostAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/mno_enterprise/mail_adapters/sparkpost_adapter.rb

Overview

SparkPost Adapter for MnoEnterprise::MailClient

Class Method Summary collapse

Methods inherited from Adapter

base_deliveries, test?

Class Method Details

.clientSparkPost::Client

Return a sparkpost client configured with the right API key api key is set in ENV through ENV

Returns:

  • (SparkPost::Client)


12
13
14
# File 'lib/mno_enterprise/mail_adapters/sparkpost_adapter.rb', line 12

def client
  @client ||= SparkPost::Client.new
end

.deliver(template, from, to, vars = {}, opts = {}) ⇒ Object

Send a template

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mno_enterprise/mail_adapters/sparkpost_adapter.rb', line 18

def deliver(template, from, to, vars={}, opts={})
  # Prepare message from args
  message = {
    recipients: prepare_recipients(to),
    content: {
      from: from,
      template_id: template
    },
    substitution_data: vars
  }

  # Merge additional options
  message.merge!(opts)

  # Send
  send_template(template,[],message)
end

.send_template(template_name, _, message) ⇒ Object

Send the provided template with options SparkpostClient.send_template(template_name(string), template_content(array), message(hash))



38
39
40
41
42
43
44
45
# File 'lib/mno_enterprise/mail_adapters/sparkpost_adapter.rb', line 38

def send_template(template_name, _, message)
  if test?
    base_deliveries.push([template_name, message])
  else
    message[:content][:template_id] = template_name
    client.transmission.send_payload(message)
  end
end