Class: MultiMail::Message::Mandrill
- Defined in:
- lib/multi_mail/mandrill/message.rb
Overview
Instance Method Summary collapse
-
#mandrill_attachments ⇒ Array<Faraday::UploadIO>
Returns the message's attachments in Mandrill format.
-
#mandrill_headers ⇒ Hash
Returns the message headers in Mandrill format.
-
#mandrill_to ⇒ Array<Hash>
Returns the To header in Mandrill format.
-
#to_mandrill_hash ⇒ Hash
Returns the message as parameters to POST to Mandrill.
Constructor Details
This class inherits a constructor from MultiMail::Message::Base
Instance Method Details
#mandrill_attachments ⇒ Array<Faraday::UploadIO>
Returns the message's attachments in Mandrill format.
40 41 42 43 44 45 46 47 48 |
# File 'lib/multi_mail/mandrill/message.rb', line 40 def .map do || { 'type' => .content_type, 'name' => .filename, 'content' => Base64.encode64(.body.decoded) } end end |
#mandrill_headers ⇒ Hash
Returns the message headers in Mandrill format.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/multi_mail/mandrill/message.rb', line 24 def mandrill_headers hash = {} header_fields.each do |field| key = field.name.downcase # Mandrill only allows Reply-To and X-* headers currently. # https://mandrillapp.com/api/docs/messages.ruby.html if key == 'reply-to' || key.start_with?('x-') hash[field.name] = field.value end end hash end |
#mandrill_to ⇒ Array<Hash>
Returns the To header in Mandrill format.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/multi_mail/mandrill/message.rb', line 8 def mandrill_to if to to.each_with_index.map do |value,index| { 'email' => value, 'name' => self[:to].display_names[index] } end else [] end end |
#to_mandrill_hash ⇒ Hash
Returns the message as parameters to POST to Mandrill.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/multi_mail/mandrill/message.rb', line 53 def to_mandrill_hash images, = .partition do || ['type'].start_with?('image/') end hash = { 'html' => body_html, 'text' => body_text, 'subject' => subject, 'from_email' => from && from.first, 'from_name' => from && self[:from].display_names.first, 'to' => mandrill_to, 'headers' => mandrill_headers, 'attachments' => , 'images' => images, 'tags' => , } normalize(hash) end |