Class: MandrillDm::Message
- Inherits:
-
Object
- Object
- MandrillDm::Message
- Defined in:
- lib/mandrill_dm/message.rb
Overview
rubocop:disable ClassLength
Instance Attribute Summary collapse
-
#mail ⇒ Object
readonly
Returns the value of attribute mail.
Instance Method Summary collapse
-
#attachments ⇒ Object
Returns a Mandrill API compatible attachment hash.
- #auto_html ⇒ Object
- #auto_text ⇒ Object
- #bcc_address ⇒ Object
- #from_email ⇒ Object
- #from_name ⇒ Object
- #global_merge_vars ⇒ Object
- #headers ⇒ Object
- #html ⇒ Object
-
#images ⇒ Object
Mandrill uses a different hash for inlined image attachments.
- #important ⇒ Object
-
#initialize(mail) ⇒ Message
constructor
A new instance of Message.
- #inline_css ⇒ Object
- #ip_pool ⇒ Object
- #merge ⇒ Object
- #merge_language ⇒ Object
- #merge_vars ⇒ Object
- #metadata ⇒ Object
- #preserve_recipients ⇒ Object
- #return_path_domain ⇒ Object
- #send_at ⇒ Object
-
#send_at_formatted_string(obj) ⇒ Object
mandrill expects ‘send_at` in UTC as `YYYY-MM-DD HH:MM:SS`.
- #signing_domain ⇒ Object
- #subaccount ⇒ Object
- #subject ⇒ Object
- #tags ⇒ Object
- #template ⇒ Object
- #template_content ⇒ Object
- #text ⇒ Object
- #to ⇒ Object
-
#to_json ⇒ Object
rubocop:disable MethodLength, AbcSize.
- #track_clicks ⇒ Object
- #track_opens ⇒ Object
- #tracking_domain ⇒ Object
- #url_strip_qs ⇒ Object
- #view_content_link ⇒ Object
Constructor Details
#initialize(mail) ⇒ Message
Returns a new instance of Message.
7 8 9 |
# File 'lib/mandrill_dm/message.rb', line 7 def initialize(mail) @mail = mail end |
Instance Attribute Details
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
5 6 7 |
# File 'lib/mandrill_dm/message.rb', line 5 def mail @mail end |
Instance Method Details
#attachments ⇒ Object
Returns a Mandrill API compatible attachment hash
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mandrill_dm/message.rb', line 12 def = mail..reject(&:inline?) .collect do || { name: .filename, type: .mime_type, content: Base64.encode64(.body.decoded) } end end |
#auto_html ⇒ Object
39 40 41 |
# File 'lib/mandrill_dm/message.rb', line 39 def auto_html nil_true_false?(:auto_html) end |
#auto_text ⇒ Object
35 36 37 |
# File 'lib/mandrill_dm/message.rb', line 35 def auto_text nil_true_false?(:auto_text) end |
#bcc_address ⇒ Object
43 44 45 |
# File 'lib/mandrill_dm/message.rb', line 43 def bcc_address return_string_value(:bcc_address) end |
#from_email ⇒ Object
47 48 49 |
# File 'lib/mandrill_dm/message.rb', line 47 def from_email from.address end |
#from_name ⇒ Object
51 52 53 |
# File 'lib/mandrill_dm/message.rb', line 51 def from_name from.display_name end |
#global_merge_vars ⇒ Object
55 56 57 |
# File 'lib/mandrill_dm/message.rb', line 55 def global_merge_vars get_value(:global_merge_vars) end |
#headers ⇒ Object
59 60 61 62 63 |
# File 'lib/mandrill_dm/message.rb', line 59 def headers mail.header_fields.reduce({}) do |acc, field| acc.merge(field.name => field.value) end end |
#html ⇒ Object
65 66 67 68 |
# File 'lib/mandrill_dm/message.rb', line 65 def html return mail.html_part.body.decoded if mail.html_part return_decoded_body('text/html') end |
#images ⇒ Object
Mandrill uses a different hash for inlined image attachments
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mandrill_dm/message.rb', line 24 def images = mail..select(&:inline?) .collect do || { name: .cid, type: .mime_type, content: Base64.encode64(.body.decoded) } end end |
#important ⇒ Object
78 79 80 |
# File 'lib/mandrill_dm/message.rb', line 78 def important mail[:important].to_s == 'true' end |
#inline_css ⇒ Object
82 83 84 |
# File 'lib/mandrill_dm/message.rb', line 82 def inline_css nil_true_false?(:inline_css) end |
#ip_pool ⇒ Object
86 87 88 |
# File 'lib/mandrill_dm/message.rb', line 86 def ip_pool return_string_value(:ip_pool) end |
#merge ⇒ Object
90 91 92 |
# File 'lib/mandrill_dm/message.rb', line 90 def merge nil_true_false?(:merge) end |
#merge_language ⇒ Object
94 95 96 |
# File 'lib/mandrill_dm/message.rb', line 94 def merge_language return_string_value(:merge_language) end |
#merge_vars ⇒ Object
98 99 100 |
# File 'lib/mandrill_dm/message.rb', line 98 def merge_vars get_value(:merge_vars) end |
#metadata ⇒ Object
102 103 104 |
# File 'lib/mandrill_dm/message.rb', line 102 def get_value(:metadata) end |
#preserve_recipients ⇒ Object
106 107 108 |
# File 'lib/mandrill_dm/message.rb', line 106 def preserve_recipients nil_true_false?(:preserve_recipients) end |
#return_path_domain ⇒ Object
110 111 112 |
# File 'lib/mandrill_dm/message.rb', line 110 def return_path_domain return_string_value(:return_path_domain) end |
#send_at ⇒ Object
114 115 116 117 |
# File 'lib/mandrill_dm/message.rb', line 114 def send_at value = get_value(:send_at) value ? send_at_formatted_string(value) : nil end |
#send_at_formatted_string(obj) ⇒ Object
mandrill expects ‘send_at` in UTC as `YYYY-MM-DD HH:MM:SS`
120 121 122 123 124 125 126 127 |
# File 'lib/mandrill_dm/message.rb', line 120 def send_at_formatted_string(obj) return obj if obj.is_a?(String) obj = obj.to_time if obj.is_a?(DateTime) return obj.utc.strftime('%Y-%m-%d %H:%M:%S') if obj.is_a?(Time) raise ArgumentError, 'send_at should be Time/DateTime or String' end |
#signing_domain ⇒ Object
129 130 131 |
# File 'lib/mandrill_dm/message.rb', line 129 def signing_domain return_string_value(:signing_domain) end |
#subaccount ⇒ Object
133 134 135 |
# File 'lib/mandrill_dm/message.rb', line 133 def subaccount return_string_value(:subaccount) end |
#subject ⇒ Object
137 138 139 |
# File 'lib/mandrill_dm/message.rb', line 137 def subject mail.subject end |
#tags ⇒ Object
141 142 143 |
# File 'lib/mandrill_dm/message.rb', line 141 def end |
#template ⇒ Object
70 71 72 |
# File 'lib/mandrill_dm/message.rb', line 70 def template return_string_value(:template) end |
#template_content ⇒ Object
74 75 76 |
# File 'lib/mandrill_dm/message.rb', line 74 def template_content get_value(:template_content) end |
#text ⇒ Object
145 146 147 148 |
# File 'lib/mandrill_dm/message.rb', line 145 def text return mail.text_part.body.decoded if mail.text_part return_decoded_body('text/plain') end |
#to ⇒ Object
150 151 152 |
# File 'lib/mandrill_dm/message.rb', line 150 def to combine_address_fields.reject(&:nil?).flatten end |
#to_json ⇒ Object
rubocop:disable MethodLength, AbcSize
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/mandrill_dm/message.rb', line 174 def to_json # rubocop:disable MethodLength, AbcSize json_hash = { auto_html: auto_html, auto_text: auto_text, bcc_address: bcc_address, from_email: from_email, from_name: from_name, global_merge_vars: global_merge_vars, headers: headers, html: html, important: important, inline_css: inline_css, merge: merge, merge_language: merge_language, merge_vars: merge_vars, metadata: , preserve_recipients: preserve_recipients, return_path_domain: return_path_domain, signing_domain: signing_domain, subaccount: subaccount, subject: subject, tags: , text: text, to: to, track_clicks: track_clicks, track_opens: track_opens, tracking_domain: tracking_domain, url_strip_qs: url_strip_qs, view_content_link: view_content_link } json_hash[:attachments] = if json_hash[:images] = images if json_hash end |
#track_clicks ⇒ Object
154 155 156 |
# File 'lib/mandrill_dm/message.rb', line 154 def track_clicks nil_true_false?(:track_clicks) end |
#track_opens ⇒ Object
158 159 160 |
# File 'lib/mandrill_dm/message.rb', line 158 def track_opens nil_true_false?(:track_opens) end |
#tracking_domain ⇒ Object
162 163 164 |
# File 'lib/mandrill_dm/message.rb', line 162 def tracking_domain return_string_value(:tracking_domain) end |
#url_strip_qs ⇒ Object
166 167 168 |
# File 'lib/mandrill_dm/message.rb', line 166 def url_strip_qs nil_true_false?(:url_strip_qs) end |
#view_content_link ⇒ Object
170 171 172 |
# File 'lib/mandrill_dm/message.rb', line 170 def view_content_link nil_true_false?(:view_content_link) end |