Class: DMCourier::Services::Mandrill

Inherits:
Object
  • Object
show all
Includes:
MessageHelper
Defined in:
lib/dm_courier/services/mandrill.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageHelper

#attachments, #attachments?, #extract_params, #fallback_options, #from, #from_address, #from_email, #from_name, #html_part, #nil_true_false?, #return_string_value, #subject, #text_part

Constructor Details

#initialize(mail, options = {}) ⇒ Mandrill

Returns a new instance of Mandrill.



13
14
15
16
17
18
# File 'lib/dm_courier/services/mandrill.rb', line 13

def initialize(mail, options = {})
  @mail = mail
  @api_key = options.fetch(:api_key)
  @async = options.fetch(:async, false)
  @options = options
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



11
12
13
# File 'lib/dm_courier/services/mandrill.rb', line 11

def api_key
  @api_key
end

#asyncObject (readonly)

Returns the value of attribute async.



11
12
13
# File 'lib/dm_courier/services/mandrill.rb', line 11

def async
  @async
end

#mailObject (readonly)

Returns the value of attribute mail.



11
12
13
# File 'lib/dm_courier/services/mandrill.rb', line 11

def mail
  @mail
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/dm_courier/services/mandrill.rb', line 11

def options
  @options
end

Instance Method Details

#deliver!Object



24
25
26
27
# File 'lib/dm_courier/services/mandrill.rb', line 24

def deliver!
  mandrill_api = ::Mandrill::API.new(api_key)
  mandrill_api.messages.send(mandrill_message, async)
end

#mandrill_messageObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dm_courier/services/mandrill.rb', line 29

def mandrill_message
  message = extract_params(nil_true_false: { auto_html: :auto_html,
                                             auto_text: :auto_text,
                                             important: :important,
                                             inline_css: :inline_css,
                                             track_clicks: :track_clicks,
                                             track_opens: :track_opens,
                                             url_strip_qs: :track_url_without_query_string,
                                             view_content_link: :log_content },
                           string: { bcc_address: :bcc_address,
                                     return_path_domain: :return_path_domain,
                                     signing_domain: :signing_domain,
                                     subaccount: :subaccount,
                                     tracking_domain: :tracking_domain })

  message[:important] ||= false

  message.merge!(from_email: from_email,
                 from_name: from_name,
                 headers: headers,
                 html: html_part,
                 subject: subject,
                 tags: tags,
                 text: text_part,
                 to: to)

  message[:attachments] = regular_attachments if attachments?(inline: false)
  message[:images] = inline_attachments if attachments?(inline: true)
  message
end

#nameObject



20
21
22
# File 'lib/dm_courier/services/mandrill.rb', line 20

def name
  :mandrill
end