class MnoEnterprise::MailAdapters::SparkpostAdapter

SparkPost Adapter for MnoEnterprise::MailClient

Public Class Methods

client() click to toggle source

Return a sparkpost client configured with the right API key api key is set in ENV through ENV @return [SparkPost::Client]

# File lib/mno_enterprise/mail_adapters/sparkpost_adapter.rb, line 12
def client
  @client ||= SparkPost::Client.new
end
deliver(template, from, to, vars={}, opts={}) click to toggle source

Send a template @see Adapter#deliver

# 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) click to toggle source

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

# 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

Private Class Methods

prepare_recipients(recipients) click to toggle source

TODO: Use delegate?

# File lib/mno_enterprise/mail_adapters/sparkpost_adapter.rb, line 50
def prepare_recipients(recipients)
  client.transmission.prepare_recipients(recipients)
end