class MandrillDm::DeliveryMethod

Attributes

response[RW]
settings[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/mandrill_dm/delivery_method.rb, line 5
def initialize(options = {})
  @settings = {
    api_key: MandrillDm.configuration.api_key
  }.merge!(options)
end

Public Instance Methods

deliver!(mail) click to toggle source

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize

# File lib/mandrill_dm/delivery_method.rb, line 13
def deliver!(mail)
  mandrill_api = Mandrill::API.new(settings[:api_key])
  message = Message.new(mail)
  @response = if message.template
                mandrill_api.messages.send_template(
                  message.template,
                  message.template_content,
                  message.to_json,
                  MandrillDm.configuration.async,
                  message.ip_pool || MandrillDm.configuration.ip_pool,
                  message.send_at
                )
              else
                mandrill_api.messages.send(
                  message.to_json,
                  MandrillDm.configuration.async,
                  message.ip_pool || MandrillDm.configuration.ip_pool,
                  message.send_at
                )
              end
end