Class: MandrillDm::DeliveryMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/mandrill_dm/delivery_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DeliveryMethod

Returns a new instance of DeliveryMethod.



5
6
7
8
9
# File 'lib/mandrill_dm/delivery_method.rb', line 5

def initialize(options = {})
  @settings = {
    api_key: MandrillDm.configuration.api_key
  }.merge!(options)
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/mandrill_dm/delivery_method.rb', line 3

def response
  @response
end

#settingsObject

Returns the value of attribute settings.



3
4
5
# File 'lib/mandrill_dm/delivery_method.rb', line 3

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mandrill_dm/delivery_method.rb', line 13

def deliver!(mail)
  logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
  logger.error '!!! MIGRATE from Mandrill IMMEDIATELY: https://github.com/kshnurov/mandrill_dm/blob/master/MIGRATE'

  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