Class: MultiMail::Message::Mailgun
- Defined in:
- lib/multi_mail/mailgun/message.rb
Overview
Instance Attribute Summary collapse
-
#content_id_map ⇒ Object
Returns the value of attribute content_id_map.
-
#stripped_html ⇒ Object
Returns the value of attribute stripped_html.
-
#stripped_signature ⇒ Object
Returns the value of attribute stripped_signature.
-
#stripped_text ⇒ Object
Returns the value of attribute stripped_text.
Instance Method Summary collapse
-
#mailgun_attachments ⇒ Multimap
Returns the message's attachments in Mailgun format.
-
#mailgun_headers ⇒ Hash
Returns the message headers in Mailgun format.
-
#to_mailgun_hash ⇒ Hash
Returns the message as parameters to POST to Mailgun.
Constructor Details
This class inherits a constructor from MultiMail::Message::Base
Instance Attribute Details
#content_id_map ⇒ Object
Returns the value of attribute content_id_map.
5 6 7 |
# File 'lib/multi_mail/mailgun/message.rb', line 5 def content_id_map @content_id_map end |
#stripped_html ⇒ Object
Returns the value of attribute stripped_html.
5 6 7 |
# File 'lib/multi_mail/mailgun/message.rb', line 5 def stripped_html @stripped_html end |
#stripped_signature ⇒ Object
Returns the value of attribute stripped_signature.
5 6 7 |
# File 'lib/multi_mail/mailgun/message.rb', line 5 def stripped_signature @stripped_signature end |
#stripped_text ⇒ Object
Returns the value of attribute stripped_text.
5 6 7 |
# File 'lib/multi_mail/mailgun/message.rb', line 5 def stripped_text @stripped_text end |
Instance Method Details
#mailgun_attachments ⇒ Multimap
Returns the message's attachments in Mailgun format.
32 33 34 35 36 37 38 39 |
# File 'lib/multi_mail/mailgun/message.rb', line 32 def map = Multimap.new .each do || key = .content_type.start_with?('image/') ? 'inline' : 'attachment' map[key] = Faraday::UploadIO.new(StringIO.new(.body.decoded), .content_type, .filename) end map end |
#mailgun_headers ⇒ Hash
Returns the message headers in Mailgun format.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/multi_mail/mailgun/message.rb', line 10 def mailgun_headers map = Multimap.new hash = Hash.new header_fields.each do |field| key = field.name.downcase unless %w(from to cc bcc subject tag).include?(key) if key == 'reply-to' hash["h:#{field.name}"] = field.value else map["h:#{field.name}"] = field.value end end end map.to_hash.merge(hash) end |
#to_mailgun_hash ⇒ Hash
Returns the message as parameters to POST to Mailgun.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/multi_mail/mailgun/message.rb', line 45 def to_mailgun_hash map = Multimap.new hash = Hash.new %w(from subject).each do |field| if self[field] map[field] = self[field].value end end %w(to cc bcc).each do |field| if self[field] if self[field].value.respond_to?(:each) self[field].value.each do |value| map[field] = value end else map[field] = self[field].value end end end if body_text && !body_text.empty? map['text'] = body_text end if body_html && !body_html.empty? map['html'] = body_html end .each do |tag| map['o:tag'] = tag end normalize(map.merge().to_hash.merge(mailgun_headers).merge(hash)) end |