postmark 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b07a5971093718b77a48cb6a5917167ba39d2d6e
4
- data.tar.gz: a3f227ff7b37009da8a05fef39ae9a971fefe990
3
+ metadata.gz: 7d65fe77b30becc8c00a0e19a057d885176f20dd
4
+ data.tar.gz: df33b575861a790eaea91e65ff7d937fd7c0be03
5
5
  SHA512:
6
- metadata.gz: 1dc9c40d2e9c7410c371d681cebcf90d27b25898c932a729d6dabb8f9391e9060cfa38d8a36b9abde7218ca0be45d8d048af36e91bfeb456980c9690fe8f3ee3
7
- data.tar.gz: ef0e6f6cb70ba23b0ad301eac397a2f26287b66131986c2bce421d0b9a5dffc66538d4f53c644db54791de0b0689777234436048d2e5a11f473bdb2480d47221
6
+ metadata.gz: 001d1b715e69f99ee6eb3a7f1dc63f282f51ef1b8dbe3acf42344e4c421cbc8d5cd23f269c2525460499d4d8ece1f7060355e747bb758024f0ffbcfe9aa5bf5e
7
+ data.tar.gz: 83ad3ace1faa7086fd327afdd2676737aeae6130fe4f9013e79e291984e0a8bab0f47e44247aa518f41d49fca04aed686e5afa9ced07ba4821621debc1131569
@@ -1,5 +1,9 @@
1
1
  = Changelog
2
2
 
3
+ == 1.12.0
4
+
5
+ * Added support for attaching metadata to messages.
6
+
3
7
  == 1.11.0
4
8
 
5
9
  * New, improved, and backwards-compatible gem errors (see README).
data/README.md CHANGED
@@ -97,6 +97,22 @@ client.deliver(from: 'sheldon@bigbangtheory.com',
97
97
  # => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:51:08.8789433-04:00", :message_id=>"75c28987-564e-xxxx-b6eb-e8071873ac06", :error_code=>0, :message=>"OK"}
98
98
  ```
99
99
 
100
+ ## Sending a message with metadata
101
+
102
+ To send metadata for emails you send, all you need to do is provide metadata for your messages in form of hash map.
103
+
104
+ ``` ruby
105
+ client.deliver(from: 'sheldon@bigbangtheory.com',
106
+ to: 'Leonard Hofstadter <leonard@bigbangtheory.com>',
107
+ subject: 'Re: What, to you, is a large crowd?',
108
+ html_body: '<p>Any group big enough to trample me to death. ' \
109
+ 'General <a href="http://www.example.com">rule of thumb</a> is 36 adults or 70 ' \
110
+ 'children.</p>',
111
+ text_body: 'Any group big enough to trample me to death. General rule of thumb is 36 adults or 70 children - http://www.example.com.',
112
+ metadata: {'Example1' => 'value', 'Example2' => 'value'})
113
+ # => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:51:08.8789433-04:00", :message_id=>"75c28987-564e-xxxx-b6eb-e8071873ac06", :error_code=>0, :message=>"OK"}
114
+ ```
115
+
100
116
  ## Sending a message with attachments
101
117
 
102
118
  You can add
@@ -451,6 +467,24 @@ message.deliver
451
467
  # => #<Mail::Message:70355902117460, Multipart: true, Headers: <From: sheldon@bigbangtheory.com>, <To: leonard@bigbangtheory.com>, <Message-ID: 1a1370a1-6c21-4304-a03c-320a54cc59f7>, <Subject: Re: What, to you, is a large crowd?>, <Content-Type: multipart/alternative; boundary=--==_mimepart_58380d6029b17_20543fd48543fa14977a>, <TRACK-LINKS: HtmlAndText>>
452
468
  ```
453
469
 
470
+ ## Message with metadata
471
+
472
+ ``` ruby
473
+ message = Mail.new do
474
+ from 'leonard@bigbangtheory.com'
475
+ to 'Dr. Sheldon Cooper <sheldon@bigbangtheory.com>'
476
+ subject 'Have you seen these pictures of yours?'
477
+ body 'You look like a real geek!'
478
+ add_file '1.jpeg'
479
+ metadata {"Example1"=>"value","Example2"=>"value"}
480
+
481
+ delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
482
+ end
483
+
484
+ message.deliver
485
+ # => #<Mail::Message:70185826686240, Multipart: true, Headers: <From: leonard@bigbangtheory.com>, <To: sheldon@bigbangtheory.com>, <Message-ID: ba644cc1-b5b1-4bcb-aaf8-2f290b5aad80>, <Subject: Have you seen these pictures of yours?>, <Content-Type: multipart/mixed; boundary=--==_mimepart_5121f9f1ec653_12c53fd569035ad817726>>
486
+ ```
487
+
454
488
  ## Message with attachments
455
489
 
456
490
  ``` ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.11.0
1
+ 1.12.0
@@ -13,5 +13,5 @@ group :test do
13
13
  gem 'mime-types', '~> 1.25.1'
14
14
  gem 'activesupport', '~> 3.2.0'
15
15
  gem 'i18n', '~> 0.6.0'
16
- gem 'yajl-ruby', '~> 1.0', :platforms => [:mingw, :mswin, :ruby]
16
+ gem 'yajl-ruby', '~> 1.0', '< 1.4.0', :platforms => [:mingw, :mswin, :ruby]
17
17
  end
@@ -31,7 +31,8 @@ module Postmark
31
31
  'Headers' => @message.export_headers,
32
32
  'Tag' => @message.tag.to_s,
33
33
  'TrackOpens' => (cast_to_bool(@message.track_opens) unless @message.track_opens.empty?),
34
- 'TrackLinks' => (::Postmark::Inflector.to_postmark(@message.track_links) unless @message.track_links.empty?)
34
+ 'TrackLinks' => (::Postmark::Inflector.to_postmark(@message.track_links) unless @message.track_links.empty?),
35
+ 'Metadata' => (@message.metadata unless @message.metadata.nil?)
35
36
  }
36
37
  end
37
38
 
@@ -33,6 +33,15 @@ module Mail
33
33
  header['TRACK-OPENS'] = (!!val).to_s
34
34
  end
35
35
 
36
+ def metadata(val = nil)
37
+ @metadata=val unless val.nil?
38
+ @metadata
39
+ end
40
+
41
+ def metadata=(val)
42
+ @metadata = val
43
+ end
44
+
36
45
  def postmark_attachments=(value)
37
46
  Kernel.warn("Mail::Message#postmark_attachments= is deprecated and will " \
38
47
  "be removed in the future. Please consider using the native " \
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.11.0'
2
+ VERSION = '1.12.0'
3
3
  end
@@ -104,20 +104,27 @@ describe Postmark::MessageHelper do
104
104
  expect(subject.to_postmark(message_with_headers_and_attachments)).to eq postmark_message_with_headers_and_attachments
105
105
  end
106
106
 
107
- context 'open tracking flag set' do
107
+ context 'open tracking' do
108
108
 
109
- it 'true' do
109
+ it 'converts messages with open tracking flag set to true correctly' do
110
110
  expect(subject.to_postmark(message_with_open_tracking)).to eq(postmark_message_with_open_tracking)
111
111
  end
112
112
 
113
- it 'false' do
113
+ it 'converts messages with open tracking flag set to false correctly' do
114
114
  expect(subject.to_postmark(message_with_open_tracking_false)).to eq(postmark_message_with_open_tracking_false)
115
115
  end
116
116
 
117
117
  end
118
118
 
119
- context 'link tracking flag set' do
119
+ context 'metadata' do
120
+ it 'converts messages with metadata correctly' do
121
+ metadata = {"test" => "value"}
122
+ data= message.merge(:metadata => metadata)
123
+ expect(subject.to_postmark(data)).to include(postmark_message.merge("Metadata" => metadata))
124
+ end
125
+ end
120
126
 
127
+ context 'link tracking' do
121
128
  let(:message_with_link_tracking_html) { message.merge(:track_links => :html_only) }
122
129
  let(:message_with_link_tracking_text) { message.merge(:track_links => :text_only) }
123
130
  let(:message_with_link_tracking_all) { message.merge(:track_links => :html_and_text) }
@@ -128,24 +135,22 @@ describe Postmark::MessageHelper do
128
135
  let(:postmark_message_with_link_tracking_all) { postmark_message.merge("TrackLinks" => 'HtmlAndText') }
129
136
  let(:postmark_message_with_link_tracking_none) { postmark_message.merge("TrackLinks" => 'None') }
130
137
 
131
- it 'html' do
138
+ it 'converts html body link tracking to Postmark format' do
132
139
  expect(subject.to_postmark(message_with_link_tracking_html)).to eq(postmark_message_with_link_tracking_html)
133
140
  end
134
141
 
135
- it 'text' do
142
+ it 'converts text body link tracking to Postmark format' do
136
143
  expect(subject.to_postmark(message_with_link_tracking_text)).to eq(postmark_message_with_link_tracking_text)
137
144
  end
138
145
 
139
- it 'html and text' do
146
+ it 'converts html and text body link tracking to Postmark format' do
140
147
  expect(subject.to_postmark(message_with_link_tracking_all)).to eq(postmark_message_with_link_tracking_all)
141
148
  end
142
149
 
143
- it 'none' do
150
+ it 'converts no link tracking to Postmark format' do
144
151
  expect(subject.to_postmark(message_with_link_tracking_none)).to eq(postmark_message_with_link_tracking_none)
145
152
  end
146
-
147
153
  end
148
-
149
154
  end
150
155
 
151
156
  describe ".headers_to_postmark" do
@@ -159,7 +164,6 @@ describe Postmark::MessageHelper do
159
164
  end
160
165
 
161
166
  describe ".attachments_to_postmark" do
162
-
163
167
  it 'converts attachments to Postmark format' do
164
168
  expect(subject.attachments_to_postmark(attachments)).to eq postmark_attachments
165
169
  end
@@ -167,7 +171,6 @@ describe Postmark::MessageHelper do
167
171
  it 'accepts single attachment as a non-array' do
168
172
  expect(subject.attachments_to_postmark(attachments.first)).to eq [postmark_attachments.first]
169
173
  end
170
-
171
174
  end
172
175
 
173
176
  end
@@ -225,11 +225,9 @@ describe Postmark::MailMessageConverter do
225
225
  "ReplyTo" => 'Penny The Neighbor <penny@bigbangtheory.com>'}
226
226
  end
227
227
 
228
- context 'recognizes open tracking' do
229
-
228
+ context 'open tracking' do
230
229
  context 'setup inside of mail' do
231
-
232
- it 'enabled' do
230
+ it 'converts open tracking enabled messages correctly' do
233
231
  expect(subject.new(mail_message_with_open_tracking).run).to eq ({
234
232
  "From" => "sheldon@bigbangtheory.com",
235
233
  "Subject" => "Hello!",
@@ -238,7 +236,7 @@ describe Postmark::MailMessageConverter do
238
236
  "TrackOpens" => true})
239
237
  end
240
238
 
241
- it 'disabled' do
239
+ it 'converts open tracking disabled messages correctly' do
242
240
  expect(subject.new(mail_message_with_open_tracking_disabled).run).to eq ({
243
241
  "From" => "sheldon@bigbangtheory.com",
244
242
  "Subject" => "Hello!",
@@ -246,12 +244,10 @@ describe Postmark::MailMessageConverter do
246
244
  "To" => "lenard@bigbangtheory.com",
247
245
  "TrackOpens" => false})
248
246
  end
249
-
250
247
  end
251
248
 
252
249
  context 'setup with tracking variable' do
253
-
254
- it 'enabled' do
250
+ it 'converts open tracking enabled messages correctly' do
255
251
  expect(subject.new(mail_message_with_open_tracking_set_variable).run).to eq ({
256
252
  "From" => "sheldon@bigbangtheory.com",
257
253
  "Subject" => "Hello!",
@@ -260,7 +256,7 @@ describe Postmark::MailMessageConverter do
260
256
  "TrackOpens" => true})
261
257
  end
262
258
 
263
- it 'disabled' do
259
+ it 'converts open tracking disabled messages correctly' do
264
260
  expect(subject.new(mail_message_with_open_tracking_disabled_set_variable).run).to eq ({
265
261
  "From" => "sheldon@bigbangtheory.com",
266
262
  "Subject" => "Hello!",
@@ -268,14 +264,11 @@ describe Postmark::MailMessageConverter do
268
264
  "To" => "lenard@bigbangtheory.com",
269
265
  "TrackOpens" => false})
270
266
  end
271
-
272
267
  end
273
-
274
268
  end
275
269
 
276
270
  context 'link tracking' do
277
-
278
- it 'html and text' do
271
+ it 'converts html and text link tracking enabled messages correctly' do
279
272
  expect(subject.new(mail_message_with_link_tracking_all).run).to eq ({
280
273
  "From" => "sheldon@bigbangtheory.com",
281
274
  "Subject" => "Hello!",
@@ -284,7 +277,7 @@ describe Postmark::MailMessageConverter do
284
277
  "TrackLinks" => 'HtmlAndText'})
285
278
  end
286
279
 
287
- it 'html only' do
280
+ it 'converts html only link tracking enabled messages correctly' do
288
281
  expect(subject.new(mail_message_with_link_tracking_html).run).to eq ({
289
282
  "From" => "sheldon@bigbangtheory.com",
290
283
  "Subject" => "Hello!",
@@ -293,7 +286,7 @@ describe Postmark::MailMessageConverter do
293
286
  "TrackLinks" => 'HtmlOnly'})
294
287
  end
295
288
 
296
- it 'text only' do
289
+ it 'converts text only link tracking enabled messages correctly' do
297
290
  expect(subject.new(mail_message_with_link_tracking_text).run).to eq ({
298
291
  "From" => "sheldon@bigbangtheory.com",
299
292
  "Subject" => "Hello!",
@@ -302,7 +295,7 @@ describe Postmark::MailMessageConverter do
302
295
  "TrackLinks" => 'TextOnly'})
303
296
  end
304
297
 
305
- it 'none' do
298
+ it 'converts link tracking disabled messages correctly' do
306
299
  expect(subject.new(mail_message_with_link_tracking_none).run).to eq ({
307
300
  "From" => "sheldon@bigbangtheory.com",
308
301
  "Subject" => "Hello!",
@@ -316,7 +309,30 @@ describe Postmark::MailMessageConverter do
316
309
  msg[:track_links] = :html_and_text
317
310
  expect(subject.new(msg).run).to include('TrackLinks' => 'HtmlAndText')
318
311
  end
312
+ end
313
+
314
+ context 'metadata' do
315
+ it 'converts single metadata field' do
316
+ metadata = {:test => 'test'}
317
+ msg = mail_html_message
318
+ msg.metadata = metadata
319
+ expect(subject.new(msg).run).to include('Metadata' => metadata)
320
+ end
321
+
322
+ it 'converts unicode metadata field metadata' do
323
+ metadata = {:test => "Велик"}
324
+ msg = mail_html_message
325
+ msg.metadata = metadata
326
+ expect(subject.new(msg).run).to include('Metadata' => metadata)
327
+ end
319
328
 
329
+ it 'converts multiple metadata fields' do
330
+ metadata = {}
331
+ metadata = 10.times { |i| metadata["test#{i+1}"] = "t"*80 }
332
+ msg = mail_html_message
333
+ msg.metadata = metadata
334
+ expect(subject.new(msg).run).to include('Metadata' => metadata)
335
+ end
320
336
  end
321
337
 
322
338
  it 'correctly decodes unicode in messages transfered as quoted-printable' do
@@ -58,27 +58,23 @@ describe Mail::Message do
58
58
  end
59
59
 
60
60
  describe '#track_opens' do
61
+ it 'returns nil if unset' do
62
+ expect(mail_message.track_opens).to eq ''
63
+ end
61
64
 
62
- context 'flag set on track_opens=' do
63
-
64
- it 'true' do
65
+ context 'when assigned via #track_opens=' do
66
+ it 'returns assigned value to track opens' do
65
67
  mail_message.track_opens = true
66
68
  expect(mail_message.track_opens).to eq 'true'
67
69
  end
68
70
 
69
- it 'false' do
71
+ it 'returns assigned value to not track opens' do
70
72
  mail_message.track_opens = false
71
73
  expect(mail_message.track_opens).to eq 'false'
72
74
  end
73
-
74
- it 'not set' do
75
- expect(mail_message.track_opens).to eq ''
76
- end
77
-
78
75
  end
79
76
 
80
77
  context 'flag set on track_opens()' do
81
-
82
78
  it 'true' do
83
79
  mail_message.track_opens(true)
84
80
  expect(mail_message.track_opens).to eq 'true'
@@ -88,35 +84,49 @@ describe Mail::Message do
88
84
  mail_message.track_opens(false)
89
85
  expect(mail_message.track_opens).to eq 'false'
90
86
  end
91
-
92
87
  end
93
-
94
88
  end
95
89
 
96
- describe '#track_links' do
90
+ describe '#metadata' do
91
+ let(:metadata) {{:test => "test"}}
97
92
 
98
- context 'flag set on track_links=' do
93
+ it 'returns nil if unset' do
94
+ expect(mail_message.metadata).to eq nil
95
+ end
99
96
 
100
- it 'set' do
101
- mail_message.track_links=:html_only
102
- expect(mail_message.track_links).to eq 'HtmlOnly'
97
+ context 'when assigned via #metadata=' do
98
+ it 'returns assigned value' do
99
+ mail_message.metadata=metadata
100
+ expect(mail_message.metadata).to eq metadata
103
101
  end
102
+ end
104
103
 
105
- it 'not set' do
106
- expect(mail_message.track_links).to eq ''
104
+ context 'when assigned via metadata()' do
105
+ it 'returns assigned value' do
106
+ mail_message.metadata(metadata)
107
+ expect(mail_message.metadata).to eq metadata
107
108
  end
109
+ end
110
+ end
108
111
 
112
+ describe '#track_links' do
113
+ it 'return empty string when if unset' do
114
+ expect(mail_message.track_links).to eq ''
109
115
  end
110
116
 
111
- context 'flag set on track_links()' do
117
+ context 'when assigned via #track_links=' do
118
+ it 'returns track html only body value in Postmark format' do
119
+ mail_message.track_links=:html_only
120
+ expect(mail_message.track_links).to eq 'HtmlOnly'
121
+ end
122
+ end
112
123
 
113
- it 'set' do
124
+ context 'when assigned via track_links()' do
125
+ it 'returns track html only body value in Postmark format' do
114
126
  mail_message.track_links(:html_only)
115
127
  expect(mail_message.track_links).to eq 'HtmlOnly'
116
128
  end
117
-
118
129
  end
119
-
120
130
  end
121
131
 
122
132
  describe "#html?" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petyo Ivanov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-03-14 00:00:00.000000000 Z
13
+ date: 2018-07-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake