postmark 1.20.0 → 1.21.4

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
  SHA256:
3
- metadata.gz: 587a749e850a9a9fc2e70087fd13fa79d926844246f8030942d116ac6fbbcaec
4
- data.tar.gz: 20fc00b9b8b59d45afe4722abd859cc4248f63ce487d190167aec0b957bd3c76
3
+ metadata.gz: 27b284da8c78da623e294bfea463e876cf18e370d395b681548af71a0071afe8
4
+ data.tar.gz: f12aba5cb688c265455578d011d6f917d405dac949003d2286fec6949c79367d
5
5
  SHA512:
6
- metadata.gz: d4049417165d062f7d923a0b84e1c4b31791930e24c6c58d1171bbc0cb189cdbbe53736ee720b994c2a467d94afba7225512c39975f6fcd7d56d63b7c7cc567e
7
- data.tar.gz: 7fce7304875e3a7877a73e697450fb82bfbdb2404a44337dfe6591e099476e7d57ead59ce9e30182f01825b4cfc7ca61ff49a1871cf9368b13bf74fe39753e05
6
+ metadata.gz: d8881a25fa5bec51bdb8b2db632f3a5a3d1aa1457dd13df1d6e274758b8c4da992cc74ad2b512e4dc771a23c3fafba197bc5c9a979302032114fc5486f49a98d
7
+ data.tar.gz: e9be7104643c2b9e9ec7fff821af17675afccb51dfe717e72cd1975e6cdf713f322302a18e3df16943e53976e11bb0d80adb5e685faaeff98ff9ec4d1dafaa2c
@@ -0,0 +1,68 @@
1
+ # In order for builds to pass, in CircleCI you must have following environment variables setub:
2
+ # POSTMARK_API_KEY,POSTMARK_ACCOUNT_API_KEY,POSTMARK_CI_RECIPIENT,POSTMARK_CI_SENDER
3
+
4
+ version: 2.1
5
+
6
+ workflows:
7
+ ruby-tests:
8
+ jobs:
9
+ - unit-tests:
10
+ matrix:
11
+ parameters:
12
+ version: ["2", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7"]
13
+ - unit-tests-legacy:
14
+ matrix:
15
+ parameters:
16
+ version: ["kneip/ree-1.8.7-2012.02","ruby:1.9.3","circleci/jruby:9"]
17
+
18
+ orbs:
19
+ ruby: circleci/ruby@0.1.2
20
+
21
+ jobs:
22
+ unit-tests:
23
+ parallelism: 1
24
+ parameters:
25
+ version:
26
+ type: string
27
+ docker:
28
+ - image: circleci/ruby:<< parameters.version >>
29
+ steps:
30
+ - checkout
31
+ - run:
32
+ name: Versions
33
+ command: |
34
+ echo "ruby: $(ruby --version)"
35
+
36
+ - run:
37
+ name: Install dependencies
38
+ command: bundle install
39
+
40
+ - run:
41
+ name: Run tests
42
+ command: bundle exec rake spec
43
+
44
+ unit-tests-legacy:
45
+ parallelism: 1
46
+ environment:
47
+ BUNDLE_GEMFILE: ./gemfiles/Gemfile.legacy
48
+ parameters:
49
+ version:
50
+ type: string
51
+ docker:
52
+ - image: << parameters.version >>
53
+ steps:
54
+ - checkout
55
+ - run:
56
+ name: Versions
57
+ command: |
58
+ echo "ruby: $(ruby --version)"
59
+
60
+ - run:
61
+ name: Install dependencies
62
+ command: |
63
+ gem install bundler --version 1.17.3
64
+ bundle install
65
+
66
+ - run:
67
+ name: Run tests
68
+ command: bundle exec rake spec
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ pkg/*
7
7
  .idea
8
8
  bin/*
9
9
  *.swp
10
+ .DS_Store
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,25 @@
1
1
  = Changelog
2
2
 
3
+ == 1.21.4
4
+
5
+ * Fixed Postmark::ApiClient#deliver_messages_with_templates (#104)
6
+
7
+ == 1.21.3
8
+
9
+ * Remove default SSL version setting and rely on Net::HTTP/OpenSSL default.
10
+
11
+ == 1.21.2
12
+
13
+ * Ensure sending via message stream uses the correct message stream
14
+
15
+ == 1.21.1
16
+
17
+ * Fixed Postmark::ApiClient#get_message_streams
18
+
19
+ == 1.21.0
20
+
21
+ * Added support for message streams and suppressions
22
+
3
23
  == 1.20.0
4
24
 
5
25
  * Removed deprecated trigger endpoints
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  </a>
4
4
 
5
5
  # Postmark Ruby Gem
6
- [![Build Status](https://travis-ci.org/wildbit/postmark-gem.svg?branch=master)](https://travis-ci.org/wildbit/postmark-gem) [![Code Climate](https://codeclimate.com/github/wildbit/postmark-gem/badges/gpa.svg)](https://codeclimate.com/github/wildbit/postmark-gem)
6
+ [![Build Status](https://circleci.com/gh/wildbit/postmark-gem.svg?style=shield)](https://circleci.com/gh/wildbit/postmark-gem)
7
+ [![Code Climate](https://codeclimate.com/github/wildbit/postmark-gem/badges/gpa.svg)](https://codeclimate.com/github/wildbit/postmark-gem)
7
8
  [![License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](http://www.opensource.org/licenses/MIT)
8
9
  [![Gem Version](https://badge.fury.io/rb/postmark.svg)](https://badge.fury.io/rb/postmark)
9
10
 
@@ -62,4 +63,4 @@ Refer to the [LICENSE](https://github.com/wildbit/postmark-gem/blob/master/LICEN
62
63
 
63
64
  ## Copyright
64
65
 
65
- Copyright © 2018 Wildbit LLC.
66
+ Copyright © 2021 Wildbit LLC.
data/RELEASE.md ADDED
@@ -0,0 +1,12 @@
1
+ New versions of the gem are cut by the Postmark team, this is a quick guide to ensuring a smooth release.
2
+
3
+ 1. Verify all builds are passing on CircleCI for your branch.
4
+ 1. Merge in your branch to master.
5
+ 1. Update VERSION and lib/postmark/version.rb with the new version.
6
+ 1. Update CHANGELOG.rdoc with a brief description of the changes.
7
+ 1. Commit to git with a comment of "Bump version to x.y.z".
8
+ 1. run `rake release` - This will push to github(with the version tag) and rubygems with the version in lib/postmark/version.rb.
9
+ *Note that if you're on Bundler 1.17 there's a bug that hides the prompt for your OTP. If it hangs after adding the tag then it's asking for your OTP, enter your OTP and press Enter. Bundler 2.x and beyond resolved this issue. *
10
+ 1. Verify the new version is on [github](https://github.com/wildbit/postmark-gem) and [rubygems](https://rubygems.org/gems/postmark).
11
+ 1. Create a new release for the version on [Github releases](https://github.com/wildbit/postmark-gem/releases).
12
+ 1. Add or update any related content to the [wiki](https://github.com/wildbit/postmark-gem/wiki).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.20.0
1
+ 1.21.4
@@ -81,7 +81,8 @@ module Postmark
81
81
  end
82
82
 
83
83
  in_batches(messages) do |batch, offset|
84
- data = serialize(batch.map { |m| m.to_postmark_hash })
84
+ mapped = batch.map { |m| m.to_postmark_hash }
85
+ data = serialize(:Messages => mapped)
85
86
 
86
87
  with_retries do
87
88
  http_client.post("email/batchWithTemplates", data).tap do |response|
@@ -328,6 +329,44 @@ module Postmark
328
329
  format_response http_client.delete("webhooks/#{id}")
329
330
  end
330
331
 
332
+ def get_message_streams(options = {})
333
+ _, batch = load_batch('message-streams', 'MessageStreams', options)
334
+ batch
335
+ end
336
+
337
+ def message_streams(options = {})
338
+ find_each('message-streams', 'MessageStreams', options)
339
+ end
340
+
341
+ def get_message_stream(id)
342
+ format_response(http_client.get("message-streams/#{id}"))
343
+ end
344
+
345
+ def create_message_stream(attributes = {})
346
+ data = serialize(HashHelper.to_postmark(attributes))
347
+ format_response(http_client.post('message-streams', data))
348
+ end
349
+
350
+ def update_message_stream(id, attributes)
351
+ data = serialize(HashHelper.to_postmark(attributes))
352
+ format_response(http_client.patch("message-streams/#{id}", data))
353
+ end
354
+
355
+ def dump_suppressions(stream_id, options = {})
356
+ _, batch = load_batch("message-streams/#{stream_id}/suppressions/dump", 'Suppressions', options)
357
+ batch
358
+ end
359
+
360
+ def create_suppressions(stream_id, email_addresses)
361
+ data = serialize(:Suppressions => Array(email_addresses).map { |e| HashHelper.to_postmark(:email_address => e) })
362
+ format_response(http_client.post("message-streams/#{stream_id}/suppressions", data))
363
+ end
364
+
365
+ def delete_suppressions(stream_id, email_addresses)
366
+ data = serialize(:Suppressions => Array(email_addresses).map { |e| HashHelper.to_postmark(:email_address => e) })
367
+ format_response(http_client.post("message-streams/#{stream_id}/suppressions/delete", data))
368
+ end
369
+
331
370
  protected
332
371
 
333
372
  def in_batches(messages)
@@ -18,8 +18,7 @@ module Postmark
18
18
  :secure => true,
19
19
  :path_prefix => '/',
20
20
  :http_read_timeout => 15,
21
- :http_open_timeout => 5,
22
- :http_ssl_version => :TLSv1
21
+ :http_open_timeout => 5
23
22
  }
24
23
 
25
24
  def initialize(api_token, options = {})
@@ -37,6 +36,10 @@ module Postmark
37
36
  do_request { |client| client.put(url_path(path), data, headers) }
38
37
  end
39
38
 
39
+ def patch(path, data = '')
40
+ do_request { |client| client.patch(url_path(path), data, headers) }
41
+ end
42
+
40
43
  def get(path, query = {})
41
44
  do_request { |client| client.get(url_path(path + to_query_string(query)), headers) }
42
45
  end
@@ -103,7 +106,7 @@ module Postmark
103
106
  http.read_timeout = self.http_read_timeout
104
107
  http.open_timeout = self.http_open_timeout
105
108
  http.use_ssl = !!self.secure
106
- http.ssl_version = self.http_ssl_version if http.respond_to?(:ssl_version=)
109
+ http.ssl_version = self.http_ssl_version if self.http_ssl_version && http.respond_to?(:ssl_version=)
107
110
  http
108
111
  end
109
112
  end
@@ -34,7 +34,8 @@ module Postmark
34
34
  'TrackLinks' => (::Postmark::Inflector.to_postmark(@message.track_links) unless @message.track_links.empty?),
35
35
  'Metadata' => @message.metadata,
36
36
  'TemplateAlias' => @message.template_alias,
37
- 'TemplateModel' => @message.template_model
37
+ 'TemplateModel' => @message.template_model,
38
+ 'MessageStream' => @message.message_stream
38
39
  }
39
40
  end
40
41
 
@@ -72,6 +72,15 @@ module Mail
72
72
  @template_model = model
73
73
  end
74
74
 
75
+ def message_stream(val = nil)
76
+ self.message_stream = val unless val.nil?
77
+ header['MESSAGE-STREAM'].to_s
78
+ end
79
+
80
+ def message_stream=(val)
81
+ header['MESSAGE-STREAM'] = val
82
+ end
83
+
75
84
  def templated?
76
85
  !!template_alias
77
86
  end
@@ -182,6 +191,7 @@ module Mail
182
191
  attachment to
183
192
  track-opens track-links
184
193
  postmark-template-alias
194
+ message-stream
185
195
  ]
186
196
  end
187
197
 
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.20.0'
2
+ VERSION = '1.21.4'
3
3
  end
@@ -33,6 +33,10 @@ RSpec::Matchers.define :json_representation_of do |x|
33
33
  match { |actual| Postmark::Json.decode(actual) == x }
34
34
  end
35
35
 
36
+ RSpec::Matchers.define :match_json do |x|
37
+ match { |actual| Postmark::Json.encode(x) == actual }
38
+ end
39
+
36
40
  RSpec::Matchers.define :be_serialized_to do |json|
37
41
  match do |mail_message|
38
42
  Postmark.convert_message_to_options_hash(mail_message) == JSON.parse(json)
@@ -18,9 +18,9 @@ describe Postmark::ApiClient do
18
18
  template_model :name => "Sheldon"
19
19
  end
20
20
  end
21
+ let(:http_client) {api_client.http_client}
21
22
 
22
- let(:api_client) {Postmark::ApiClient.new(api_token)}
23
- subject {api_client}
23
+ subject(:api_client) {Postmark::ApiClient.new(api_token)}
24
24
 
25
25
  context "attr readers" do
26
26
  it { expect(subject).to respond_to(:http_client) }
@@ -62,7 +62,6 @@ describe Postmark::ApiClient do
62
62
  describe "#deliver" do
63
63
  let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
64
64
  let(:email_json) {Postmark::Json.encode(email)}
65
- let(:http_client) {subject.http_client}
66
65
  let(:response) {{"MessageID" => 42}}
67
66
 
68
67
  it 'converts message hash to Postmark format and posts it to /email' do
@@ -86,7 +85,6 @@ describe Postmark::ApiClient do
86
85
  let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
87
86
  let(:emails) {[email, email, email]}
88
87
  let(:emails_json) {Postmark::Json.encode(emails)}
89
- let(:http_client) {subject.http_client}
90
88
  let(:response) {[{'ErrorCode' => 0}, {'ErrorCode' => 0}, {'ErrorCode' => 0}]}
91
89
 
92
90
  it 'turns array of messages into a JSON document and posts it to /email/batch' do
@@ -104,7 +102,6 @@ describe Postmark::ApiClient do
104
102
  describe "#deliver_message" do
105
103
  let(:email) {message.to_postmark_hash}
106
104
  let(:email_json) {Postmark::Json.encode(email)}
107
- let(:http_client) {subject.http_client}
108
105
 
109
106
  it 'raises an error when given a templated message' do
110
107
  expect { subject.deliver_message(templated_message) }.
@@ -139,7 +136,6 @@ describe Postmark::ApiClient do
139
136
  describe "#deliver_message_with_template" do
140
137
  let(:email) {templated_message.to_postmark_hash}
141
138
  let(:email_json) {Postmark::Json.encode(email)}
142
- let(:http_client) {subject.http_client}
143
139
 
144
140
  it 'raises an error when given a non-templated message' do
145
141
  expect { subject.deliver_message_with_template(message) }.
@@ -175,7 +171,6 @@ describe Postmark::ApiClient do
175
171
  let(:email) {message.to_postmark_hash}
176
172
  let(:emails) {[email, email, email]}
177
173
  let(:emails_json) {Postmark::Json.encode(emails)}
178
- let(:http_client) {subject.http_client}
179
174
  let(:response) {[{}, {}, {}]}
180
175
 
181
176
  it 'raises an error when given a templated message' do
@@ -206,8 +201,7 @@ describe Postmark::ApiClient do
206
201
  describe "#deliver_messages_with_templates" do
207
202
  let(:email) {templated_message.to_postmark_hash}
208
203
  let(:emails) {[email, email, email]}
209
- let(:emails_json) {Postmark::Json.encode(emails)}
210
- let(:http_client) {subject.http_client}
204
+ let(:emails_json) {Postmark::Json.encode(:Messages => emails)}
211
205
  let(:response) {[{}, {}, {}]}
212
206
  let(:messages) { Array.new(3) { templated_message } }
213
207
 
@@ -237,7 +231,6 @@ describe Postmark::ApiClient do
237
231
  end
238
232
 
239
233
  describe "#delivery_stats" do
240
- let(:http_client) {subject.http_client}
241
234
  let(:response) {{"Bounces" => [{"Foo" => "Bar"}]}}
242
235
 
243
236
  it 'requests data at /deliverystats' do
@@ -276,8 +269,6 @@ describe Postmark::ApiClient do
276
269
  end
277
270
 
278
271
  describe '#get_messages' do
279
- let(:http_client) {subject.http_client}
280
-
281
272
  context 'given outbound' do
282
273
  let(:response) {{"TotalCount" => 1, "Messages" => [{}]}}
283
274
 
@@ -325,7 +316,6 @@ describe Postmark::ApiClient do
325
316
 
326
317
  describe '#get_message' do
327
318
  let(:id) {'8ad0e8b0-xxxx-xxxx-951d-223c581bb467'}
328
- let(:http_client) {subject.http_client}
329
319
  let(:response) {{"To" => "leonard@bigbangtheory.com"}}
330
320
 
331
321
  context 'given outbound' do
@@ -349,7 +339,6 @@ describe Postmark::ApiClient do
349
339
 
350
340
  describe '#dump_message' do
351
341
  let(:id) {'8ad0e8b0-xxxx-xxxx-951d-223c581bb467'}
352
- let(:http_client) {subject.http_client}
353
342
  let(:response) {{"Body" => "From: <leonard@bigbangtheory.com> \r\n ..."}}
354
343
 
355
344
  context 'given outbound' do
@@ -387,7 +376,6 @@ describe Postmark::ApiClient do
387
376
  end
388
377
 
389
378
  describe "#get_bounces" do
390
- let(:http_client) {subject.http_client}
391
379
  let(:options) {{:foo => :bar}}
392
380
  let(:response) {{"Bounces" => []}}
393
381
 
@@ -399,7 +387,6 @@ describe Postmark::ApiClient do
399
387
  end
400
388
 
401
389
  describe "#get_bounce" do
402
- let(:http_client) {subject.http_client}
403
390
  let(:id) {42}
404
391
 
405
392
  it 'requests a single bounce by ID at /bounces/:id' do
@@ -409,7 +396,6 @@ describe Postmark::ApiClient do
409
396
  end
410
397
 
411
398
  describe "#dump_bounce" do
412
- let(:http_client) {subject.http_client}
413
399
  let(:id) {42}
414
400
 
415
401
  it 'requests a specific bounce data at /bounces/:id/dump' do
@@ -419,7 +405,6 @@ describe Postmark::ApiClient do
419
405
  end
420
406
 
421
407
  describe "#activate_bounce" do
422
- let(:http_client) {subject.http_client}
423
408
  let(:id) {42}
424
409
  let(:response) {{"Bounce" => {}}}
425
410
 
@@ -456,7 +441,6 @@ describe Postmark::ApiClient do
456
441
  end
457
442
 
458
443
  describe '#get_opens' do
459
- let(:http_client) {subject.http_client}
460
444
  let(:options) {{:offset => 5}}
461
445
  let(:response) {{'Opens' => [], 'TotalCount' => 0}}
462
446
 
@@ -468,7 +452,6 @@ describe Postmark::ApiClient do
468
452
  end
469
453
 
470
454
  describe '#get_clicks' do
471
- let(:http_client) {subject.http_client}
472
455
  let(:options) {{:offset => 5}}
473
456
  let(:response) {{'Clicks' => [], 'TotalCount' => 0}}
474
457
 
@@ -480,7 +463,6 @@ describe Postmark::ApiClient do
480
463
  end
481
464
 
482
465
  describe '#get_opens_by_message_id' do
483
- let(:http_client) {subject.http_client}
484
466
  let(:message_id) {42}
485
467
  let(:options) {{:offset => 5}}
486
468
  let(:response) {{'Opens' => [], 'TotalCount' => 0}}
@@ -493,7 +475,6 @@ describe Postmark::ApiClient do
493
475
  end
494
476
 
495
477
  describe '#get_clicks_by_message_id' do
496
- let(:http_client) {subject.http_client}
497
478
  let(:message_id) {42}
498
479
  let(:options) {{:offset => 5}}
499
480
  let(:response) {{'Clicks' => [], 'TotalCount' => 0}}
@@ -536,8 +517,6 @@ describe Postmark::ApiClient do
536
517
  end
537
518
 
538
519
  describe '#create_trigger' do
539
- let(:http_client) {subject.http_client}
540
-
541
520
  context 'inbound rules' do
542
521
  let(:options) {{:rule => 'example.com'}}
543
522
  let(:response) {{'Rule' => 'example.com'}}
@@ -556,7 +535,6 @@ describe Postmark::ApiClient do
556
535
  end
557
536
 
558
537
  describe '#get_trigger' do
559
- let(:http_client) {subject.http_client}
560
538
  let(:id) {42}
561
539
 
562
540
  it 'performs a GET request to /triggers/tags/:id' do
@@ -571,8 +549,6 @@ describe Postmark::ApiClient do
571
549
  end
572
550
 
573
551
  describe '#delete_trigger' do
574
- let(:http_client) {subject.http_client}
575
-
576
552
  context 'tags' do
577
553
  let(:id) {42}
578
554
 
@@ -603,7 +579,6 @@ describe Postmark::ApiClient do
603
579
  end
604
580
 
605
581
  describe '#get_triggers' do
606
- let(:http_client) {subject.http_client}
607
582
  let(:options) {{:offset => 5}}
608
583
 
609
584
  context 'inbound rules' do
@@ -631,7 +606,6 @@ describe Postmark::ApiClient do
631
606
  end
632
607
 
633
608
  describe "#server_info" do
634
- let(:http_client) {subject.http_client}
635
609
  let(:response) {{"Name" => "Testing",
636
610
  "Color" => "blue",
637
611
  "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
@@ -644,7 +618,6 @@ describe Postmark::ApiClient do
644
618
  end
645
619
 
646
620
  describe "#update_server_info" do
647
- let(:http_client) {subject.http_client}
648
621
  let(:response) {{"Name" => "Testing",
649
622
  "Color" => "blue",
650
623
  "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
@@ -658,7 +631,6 @@ describe Postmark::ApiClient do
658
631
  end
659
632
 
660
633
  describe '#get_templates' do
661
- let(:http_client) {subject.http_client}
662
634
  let(:response) do
663
635
  {
664
636
  'TotalCount' => 31,
@@ -702,7 +674,6 @@ describe Postmark::ApiClient do
702
674
  end
703
675
 
704
676
  describe '#get_template' do
705
- let(:http_client) {subject.http_client}
706
677
  let(:response) do
707
678
  {
708
679
  'Name' => 'Template Name',
@@ -727,7 +698,6 @@ describe Postmark::ApiClient do
727
698
  end
728
699
 
729
700
  describe '#create_template' do
730
- let(:http_client) {subject.http_client}
731
701
  let(:response) do
732
702
  {
733
703
  'TemplateId' => 123,
@@ -749,7 +719,6 @@ describe Postmark::ApiClient do
749
719
  end
750
720
 
751
721
  describe '#update_template' do
752
- let(:http_client) {subject.http_client}
753
722
  let(:response) do
754
723
  {
755
724
  'TemplateId' => 123,
@@ -771,7 +740,6 @@ describe Postmark::ApiClient do
771
740
  end
772
741
 
773
742
  describe '#delete_template' do
774
- let(:http_client) {subject.http_client}
775
743
  let(:response) do
776
744
  {
777
745
  'ErrorCode' => 0,
@@ -789,8 +757,6 @@ describe Postmark::ApiClient do
789
757
  end
790
758
 
791
759
  describe '#validate_template' do
792
- let(:http_client) {subject.http_client}
793
-
794
760
  context 'when template is valid' do
795
761
  let(:response) do
796
762
  {
@@ -886,7 +852,6 @@ describe Postmark::ApiClient do
886
852
 
887
853
  describe "#deliver_with_template" do
888
854
  let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
889
- let(:http_client) {subject.http_client}
890
855
  let(:response) {{"MessageID" => 42}}
891
856
 
892
857
  it 'converts message hash to Postmark format and posts it to /email/withTemplate' do
@@ -911,7 +876,6 @@ describe Postmark::ApiClient do
911
876
  describe '#deliver_in_batches_with_templates' do
912
877
  let(:max_batch_size) {50}
913
878
  let(:factor) {3.5}
914
- let(:http_client) {subject.http_client}
915
879
  let(:postmark_response) do
916
880
  {
917
881
  'ErrorCode' => 0,
@@ -971,7 +935,6 @@ describe Postmark::ApiClient do
971
935
  "BounceRate" => 10.406,
972
936
  }
973
937
  end
974
- let(:http_client) {subject.http_client}
975
938
 
976
939
  it 'converts response to ruby format' do
977
940
  expect(http_client).to receive(:get).with('stats/outbound', {:tag => 'foo'}) {response}
@@ -1005,7 +968,6 @@ describe Postmark::ApiClient do
1005
968
  "Sent" => 615
1006
969
  }
1007
970
  end
1008
- let(:http_client) {subject.http_client}
1009
971
 
1010
972
  it 'converts response to ruby format' do
1011
973
  expect(http_client).to receive(:get).with('stats/outbound/sends', {:tag => 'foo'}) {response}
@@ -1040,4 +1002,295 @@ describe Postmark::ApiClient do
1040
1002
  expect(first_day).to have_key(:sent)
1041
1003
  end
1042
1004
  end
1005
+
1006
+ describe '#get_message_streams' do
1007
+ subject(:result) { api_client.get_message_streams(:offset => 22, :count => 33) }
1008
+
1009
+ before do
1010
+ allow(http_client).to receive(:get).
1011
+ with('message-streams', :offset => 22, :count => 33).
1012
+ and_return({ 'TotalCount' => 1, 'MessageStreams' => [{'Name' => 'abc'}]})
1013
+ end
1014
+
1015
+ it { is_expected.to be_an(Array) }
1016
+
1017
+ describe 'returned item' do
1018
+ subject { result.first }
1019
+
1020
+ it { is_expected.to match(:name => 'abc') }
1021
+ end
1022
+ end
1023
+
1024
+ describe '#message_streams' do
1025
+ subject { api_client.message_streams }
1026
+
1027
+ it { is_expected.to be_kind_of(Enumerable) }
1028
+
1029
+ it 'requests data at /message-streams' do
1030
+ allow(http_client).to receive(:get).
1031
+ with('message-streams', anything).
1032
+ and_return('TotalCount' => 1, 'MessageStreams' => [{}])
1033
+ expect(subject.first(5).count).to eq(1)
1034
+ end
1035
+ end
1036
+
1037
+ describe '#get_message_stream' do
1038
+ subject(:result) { api_client.get_message_stream(123) }
1039
+
1040
+ before do
1041
+ allow(http_client).to receive(:get).
1042
+ with('message-streams/123').
1043
+ and_return({
1044
+ 'Id' => 'xxx',
1045
+ 'Name' => 'My Stream',
1046
+ 'ServerID' => 321,
1047
+ 'MessageStreamType' => 'Transactional'
1048
+ })
1049
+ end
1050
+
1051
+ it {
1052
+ is_expected.to match(
1053
+ :id => 'xxx',
1054
+ :name => 'My Stream',
1055
+ :server_id => 321,
1056
+ :message_stream_type => 'Transactional'
1057
+ )
1058
+ }
1059
+ end
1060
+
1061
+ describe '#create_message_stream' do
1062
+ subject { api_client.create_message_stream(attrs) }
1063
+
1064
+ let(:attrs) do
1065
+ {
1066
+ :name => 'My Stream',
1067
+ :id => 'my-stream',
1068
+ :message_stream_type => 'Broadcasts'
1069
+ }
1070
+ end
1071
+
1072
+ let(:response) do
1073
+ {
1074
+ 'Name' => 'My Stream',
1075
+ 'Id' => 'my-stream',
1076
+ 'MessageStreamType' => 'Broadcasts',
1077
+ 'ServerId' => 222,
1078
+ 'CreatedAt' => '2020-04-01T03:33:33.333-03:00'
1079
+ }
1080
+ end
1081
+
1082
+ before do
1083
+ allow(http_client).to receive(:post) { response }
1084
+ end
1085
+
1086
+ specify do
1087
+ expect(http_client).to receive(:post).
1088
+ with('message-streams',
1089
+ json_representation_of({
1090
+ 'Name' => 'My Stream',
1091
+ 'Id' => 'my-stream',
1092
+ 'MessageStreamType' => 'Broadcasts'
1093
+ }))
1094
+ subject
1095
+ end
1096
+
1097
+ it {
1098
+ is_expected.to match(
1099
+ :id => 'my-stream',
1100
+ :name => 'My Stream',
1101
+ :server_id => 222,
1102
+ :message_stream_type => 'Broadcasts',
1103
+ :created_at => '2020-04-01T03:33:33.333-03:00'
1104
+ )
1105
+ }
1106
+ end
1107
+
1108
+ describe '#update_message_stream' do
1109
+ subject { api_client.update_message_stream('xxx', attrs) }
1110
+
1111
+ let(:attrs) do
1112
+ {
1113
+ :name => 'My Stream XXX'
1114
+ }
1115
+ end
1116
+
1117
+ let(:response) do
1118
+ {
1119
+ 'Name' => 'My Stream XXX',
1120
+ 'Id' => 'xxx',
1121
+ 'MessageStreamType' => 'Broadcasts',
1122
+ 'ServerId' => 222,
1123
+ 'CreatedAt' => '2020-04-01T03:33:33.333-03:00'
1124
+ }
1125
+ end
1126
+
1127
+ before do
1128
+ allow(http_client).to receive(:patch) { response }
1129
+ end
1130
+
1131
+ specify do
1132
+ expect(http_client).to receive(:patch).
1133
+ with('message-streams/xxx',
1134
+ match_json({
1135
+ :Name => 'My Stream XXX',
1136
+ }))
1137
+ subject
1138
+ end
1139
+
1140
+ it {
1141
+ is_expected.to match(
1142
+ :id => 'xxx',
1143
+ :name => 'My Stream XXX',
1144
+ :server_id => 222,
1145
+ :message_stream_type => 'Broadcasts',
1146
+ :created_at => '2020-04-01T03:33:33.333-03:00'
1147
+ )
1148
+ }
1149
+ end
1150
+
1151
+ describe '#create_suppressions' do
1152
+ let(:email_addresses) { nil }
1153
+ let(:message_stream_id) { 'outbound' }
1154
+
1155
+ subject { api_client.create_suppressions(message_stream_id, email_addresses) }
1156
+
1157
+ context '1 email address as string' do
1158
+ let(:email_addresses) { 'A@example.com' }
1159
+
1160
+ specify do
1161
+ expect(http_client).to receive(:post).
1162
+ with('message-streams/outbound/suppressions',
1163
+ match_json({
1164
+ :Suppressions => [
1165
+ { :EmailAddress => 'A@example.com' }
1166
+ ]}))
1167
+ subject
1168
+ end
1169
+ end
1170
+
1171
+ context '1 email address as string & non-default stream' do
1172
+ let(:email_addresses) { 'A@example.com' }
1173
+ let(:message_stream_id) { 'xxxx' }
1174
+
1175
+ specify do
1176
+ expect(http_client).to receive(:post).
1177
+ with('message-streams/xxxx/suppressions',
1178
+ match_json({
1179
+ :Suppressions => [
1180
+ { :EmailAddress => 'A@example.com' }
1181
+ ]}))
1182
+ subject
1183
+ end
1184
+ end
1185
+
1186
+ context '1 email address as array of strings' do
1187
+ let(:email_addresses) { ['A@example.com'] }
1188
+
1189
+ specify do
1190
+ expect(http_client).to receive(:post).
1191
+ with('message-streams/outbound/suppressions',
1192
+ match_json({
1193
+ :Suppressions => [
1194
+ { :EmailAddress => 'A@example.com' }
1195
+ ]}))
1196
+ subject
1197
+ end
1198
+ end
1199
+
1200
+ context 'many email addresses as array of strings' do
1201
+ let(:email_addresses) { ['A@example.com', 'B@example.com'] }
1202
+
1203
+ specify do
1204
+ expect(http_client).to receive(:post).
1205
+ with('message-streams/outbound/suppressions',
1206
+ match_json({
1207
+ :Suppressions => [
1208
+ { :EmailAddress => 'A@example.com' },
1209
+ { :EmailAddress => 'B@example.com' }
1210
+ ]}))
1211
+ subject
1212
+ end
1213
+ end
1214
+ end
1215
+
1216
+ describe '#delete_suppressions' do
1217
+ let(:email_addresses) { nil }
1218
+ let(:message_stream_id) { 'outbound' }
1219
+
1220
+ subject { api_client.delete_suppressions(message_stream_id, email_addresses) }
1221
+
1222
+ context '1 email address as string' do
1223
+ let(:email_addresses) { 'A@example.com' }
1224
+
1225
+ specify do
1226
+ expect(http_client).to receive(:post).
1227
+ with('message-streams/outbound/suppressions/delete',
1228
+ match_json({
1229
+ :Suppressions => [
1230
+ { :EmailAddress => 'A@example.com' },
1231
+ ]}))
1232
+ subject
1233
+ end
1234
+ end
1235
+
1236
+ context '1 email address as string & non-default stream' do
1237
+ let(:email_addresses) { 'A@example.com' }
1238
+ let(:message_stream_id) { 'xxxx' }
1239
+
1240
+ specify do
1241
+ expect(http_client).to receive(:post).
1242
+ with('message-streams/xxxx/suppressions/delete',
1243
+ match_json({
1244
+ :Suppressions => [
1245
+ { :EmailAddress => 'A@example.com' }
1246
+ ]}))
1247
+ subject
1248
+ end
1249
+ end
1250
+
1251
+ context '1 email address as array of strings' do
1252
+ let(:email_addresses) { ['A@example.com'] }
1253
+
1254
+ specify do
1255
+ expect(http_client).to receive(:post).
1256
+ with('message-streams/outbound/suppressions/delete',
1257
+ match_json({
1258
+ :Suppressions => [
1259
+ { :EmailAddress => 'A@example.com' }
1260
+ ]}))
1261
+ subject
1262
+ end
1263
+ end
1264
+
1265
+ context 'many email addresses as array of strings' do
1266
+ let(:email_addresses) { ['A@example.com', 'B@example.com'] }
1267
+
1268
+ specify do
1269
+ expect(http_client).to receive(:post).
1270
+ with('message-streams/outbound/suppressions/delete',
1271
+ match_json({
1272
+ :Suppressions => [
1273
+ { :EmailAddress => 'A@example.com' },
1274
+ { :EmailAddress => 'B@example.com' }
1275
+ ]}))
1276
+ subject
1277
+ end
1278
+ end
1279
+ end
1280
+
1281
+ describe '#dump_suppressions' do
1282
+ let(:message_stream_id) { 'xxxx' }
1283
+
1284
+ subject { api_client.dump_suppressions(message_stream_id, :count => 123) }
1285
+
1286
+ before do
1287
+ allow(http_client).to receive(:get).and_return({'TotalCount' => 0, 'Suppressions' => []})
1288
+ end
1289
+
1290
+ specify do
1291
+ expect(http_client).to receive(:get).
1292
+ with('message-streams/xxxx/suppressions/dump', { :count => 123, :offset => 0 })
1293
+ subject
1294
+ end
1295
+ end
1043
1296
  end
@@ -42,9 +42,9 @@ describe Postmark::HttpClient do
42
42
  its(:http_read_timeout) { is_expected.to eq 15 }
43
43
  its(:http_open_timeout) { is_expected.to eq 5 }
44
44
 
45
- it 'use default TLS encryption', :skip_ruby_version => ['1.8.7'] do
45
+ it 'does not provide a default which utilizes the Net::HTTP default', :skip_ruby_version => ['1.8.7'] do
46
46
  http_client = subject.http
47
- expect(http_client.ssl_version).to eq :TLSv1
47
+ expect(http_client.ssl_version).to eq nil
48
48
  end
49
49
  end
50
50
 
@@ -140,7 +140,7 @@ describe Postmark::HttpClient do
140
140
  :status => [ "485", "Custom HTTP response status" ])
141
141
  expect { subject.post(target_path) }.to raise_error Postmark::UnknownError
142
142
  end
143
-
143
+
144
144
  end
145
145
 
146
146
  describe "#get" do
@@ -180,7 +180,7 @@ describe Postmark::HttpClient do
180
180
  :status => [ "485", "Custom HTTP response status" ])
181
181
  expect { subject.get(target_path) }.to raise_error Postmark::UnknownError
182
182
  end
183
-
183
+
184
184
  end
185
185
 
186
186
  describe "#put" do
@@ -223,4 +223,4 @@ describe Postmark::HttpClient do
223
223
  expect { subject.put(target_path) }.to raise_error Postmark::UnknownError
224
224
  end
225
225
  end
226
- end
226
+ end
@@ -173,7 +173,7 @@ describe Postmark::MailMessageConverter do
173
173
  end
174
174
 
175
175
  it 'converts plain text messages correctly' do
176
- expect(subject.new(mail_message).run).to eq ({
176
+ expect(subject.new(mail_message).run).to eq({
177
177
  "From" => "sheldon@bigbangtheory.com",
178
178
  "Subject" => "Hello!",
179
179
  "TextBody" => "Hello Sheldon!",
@@ -181,7 +181,7 @@ describe Postmark::MailMessageConverter do
181
181
  end
182
182
 
183
183
  it 'converts tagged text messages correctly' do
184
- expect(subject.new(tagged_mail_message).run).to eq ({
184
+ expect(subject.new(tagged_mail_message).run).to eq({
185
185
  "From" => "sheldon@bigbangtheory.com",
186
186
  "Subject" => "Hello!",
187
187
  "TextBody" => "Hello Sheldon!",
@@ -190,14 +190,14 @@ describe Postmark::MailMessageConverter do
190
190
  end
191
191
 
192
192
  it 'converts plain text messages without body correctly' do
193
- expect(subject.new(mail_message_without_body).run).to eq ({
193
+ expect(subject.new(mail_message_without_body).run).to eq({
194
194
  "From" => "sheldon@bigbangtheory.com",
195
195
  "Subject" => "Hello!",
196
196
  "To" => "lenard@bigbangtheory.com"})
197
197
  end
198
198
 
199
199
  it 'converts html messages correctly' do
200
- expect(subject.new(mail_html_message).run).to eq ({
200
+ expect(subject.new(mail_html_message).run).to eq({
201
201
  "From" => "sheldon@bigbangtheory.com",
202
202
  "Subject" => "Hello!",
203
203
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -205,7 +205,7 @@ describe Postmark::MailMessageConverter do
205
205
  end
206
206
 
207
207
  it 'converts multipart messages correctly' do
208
- expect(subject.new(mail_multipart_message).run).to eq ({
208
+ expect(subject.new(mail_multipart_message).run).to eq({
209
209
  "From" => "sheldon@bigbangtheory.com",
210
210
  "Subject" => "Hello!",
211
211
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -214,7 +214,7 @@ describe Postmark::MailMessageConverter do
214
214
  end
215
215
 
216
216
  it 'converts messages with attachments correctly' do
217
- expect(subject.new(mail_message_with_attachment).run).to eq ({
217
+ expect(subject.new(mail_message_with_attachment).run).to eq({
218
218
  "From" => "sheldon@bigbangtheory.com",
219
219
  "Subject" => "Hello!",
220
220
  "Attachments" => [{"Name" => "empty.gif",
@@ -225,7 +225,7 @@ describe Postmark::MailMessageConverter do
225
225
  end
226
226
 
227
227
  it 'converts messages with named addresses correctly' do
228
- expect(subject.new(mail_message_with_named_addresses).run).to eq ({
228
+ expect(subject.new(mail_message_with_named_addresses).run).to eq({
229
229
  "From" => "Sheldon <sheldon@bigbangtheory.com>",
230
230
  "Subject" => "Hello!",
231
231
  "TextBody" => "Hello Sheldon!",
@@ -244,7 +244,7 @@ describe Postmark::MailMessageConverter do
244
244
  context 'open tracking' do
245
245
  context 'setup inside of mail' do
246
246
  it 'converts open tracking enabled messages correctly' do
247
- expect(subject.new(mail_message_with_open_tracking).run).to eq ({
247
+ expect(subject.new(mail_message_with_open_tracking).run).to eq({
248
248
  "From" => "sheldon@bigbangtheory.com",
249
249
  "Subject" => "Hello!",
250
250
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -253,7 +253,7 @@ describe Postmark::MailMessageConverter do
253
253
  end
254
254
 
255
255
  it 'converts open tracking disabled messages correctly' do
256
- expect(subject.new(mail_message_with_open_tracking_disabled).run).to eq ({
256
+ expect(subject.new(mail_message_with_open_tracking_disabled).run).to eq({
257
257
  "From" => "sheldon@bigbangtheory.com",
258
258
  "Subject" => "Hello!",
259
259
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -264,7 +264,7 @@ describe Postmark::MailMessageConverter do
264
264
 
265
265
  context 'setup with tracking variable' do
266
266
  it 'converts open tracking enabled messages correctly' do
267
- expect(subject.new(mail_message_with_open_tracking_set_variable).run).to eq ({
267
+ expect(subject.new(mail_message_with_open_tracking_set_variable).run).to eq({
268
268
  "From" => "sheldon@bigbangtheory.com",
269
269
  "Subject" => "Hello!",
270
270
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -273,7 +273,7 @@ describe Postmark::MailMessageConverter do
273
273
  end
274
274
 
275
275
  it 'converts open tracking disabled messages correctly' do
276
- expect(subject.new(mail_message_with_open_tracking_disabled_set_variable).run).to eq ({
276
+ expect(subject.new(mail_message_with_open_tracking_disabled_set_variable).run).to eq({
277
277
  "From" => "sheldon@bigbangtheory.com",
278
278
  "Subject" => "Hello!",
279
279
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -285,7 +285,7 @@ describe Postmark::MailMessageConverter do
285
285
 
286
286
  context 'link tracking' do
287
287
  it 'converts html and text link tracking enabled messages correctly' do
288
- expect(subject.new(mail_message_with_link_tracking_all).run).to eq ({
288
+ expect(subject.new(mail_message_with_link_tracking_all).run).to eq({
289
289
  "From" => "sheldon@bigbangtheory.com",
290
290
  "Subject" => "Hello!",
291
291
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -294,7 +294,7 @@ describe Postmark::MailMessageConverter do
294
294
  end
295
295
 
296
296
  it 'converts html only link tracking enabled messages correctly' do
297
- expect(subject.new(mail_message_with_link_tracking_html).run).to eq ({
297
+ expect(subject.new(mail_message_with_link_tracking_html).run).to eq({
298
298
  "From" => "sheldon@bigbangtheory.com",
299
299
  "Subject" => "Hello!",
300
300
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -303,7 +303,7 @@ describe Postmark::MailMessageConverter do
303
303
  end
304
304
 
305
305
  it 'converts text only link tracking enabled messages correctly' do
306
- expect(subject.new(mail_message_with_link_tracking_text).run).to eq ({
306
+ expect(subject.new(mail_message_with_link_tracking_text).run).to eq({
307
307
  "From" => "sheldon@bigbangtheory.com",
308
308
  "Subject" => "Hello!",
309
309
  "HtmlBody" => "<b>Hello Sheldon!</b>",
@@ -374,4 +374,20 @@ describe Postmark::MailMessageConverter do
374
374
  expect(mail_message.to_postmark_hash.keys).not_to include('Cc')
375
375
  end
376
376
  end
377
+
378
+ describe 'passing message stream' do
379
+ context 'when not set' do
380
+ specify { expect(subject.new(mail_message).run).not_to include('MessageStream') }
381
+ end
382
+
383
+ context 'when set' do
384
+ before do
385
+ mail_message.message_stream = 'weekly-newsletter'
386
+ end
387
+
388
+ it 'passes message stream to the API call' do
389
+ expect(subject.new(mail_message).run).to include('MessageStream' => 'weekly-newsletter')
390
+ end
391
+ end
392
+ end
377
393
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.20.0
4
+ version: 1.21.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petyo Ivanov
8
8
  - Ilya Sabanin
9
9
  - Artem Chistyakov
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-03-12 00:00:00.000000000 Z
13
+ date: 2021-06-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -63,16 +63,17 @@ extra_rdoc_files:
63
63
  - LICENSE
64
64
  - README.md
65
65
  files:
66
+ - ".circleci/config.yml"
66
67
  - ".document"
67
68
  - ".gitignore"
68
69
  - ".rake_tasks"
69
70
  - ".rspec"
70
- - ".travis.yml"
71
71
  - CHANGELOG.rdoc
72
72
  - CONTRIBUTING.md
73
73
  - Gemfile
74
74
  - LICENSE
75
75
  - README.md
76
+ - RELEASE.md
76
77
  - Rakefile
77
78
  - VERSION
78
79
  - gemfiles/Gemfile.legacy
@@ -146,8 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  - !ruby/object:Gem::Version
147
148
  version: 1.3.7
148
149
  requirements: []
149
- rubygems_version: 3.0.6
150
- signing_key:
150
+ rubygems_version: 3.0.8
151
+ signing_key:
151
152
  specification_version: 4
152
153
  summary: Official Postmark API wrapper.
153
154
  test_files:
data/.travis.yml DELETED
@@ -1,31 +0,0 @@
1
- env:
2
- global:
3
- # POSTMARK_API_KEY=?
4
- - secure: "ee7WQAGh7zOcoLYYx1k+542cU2R9jovnypCgyKTaBWMtdes3He4NksJGgp3PSgiPOjpYiqncXYZitgo/gKL8cYjtgcP8o/TKbzmHMTHEbD2LRWfIJ6sr4DiGYT1sjKvTLhVhSIh+WVcIXK9X3V5e6VIUfo14RMj6owHD6qv8Bjc="
5
- # POSTMARK_ACCOUNT_API_KEY=?
6
- - secure: "lau1m+ws6T5LBiRXwd+Q0b20Wjh62W/nHnCmzOSZc2+V97XTldl3MCJdXNV7J6X7O9CzFabcAG8FSbGGwPRiyhY/qhxkYSc/9pWE8RUjyCjbw5q2RzZQelMKizyKU92eOjd6jQw/wDSZcww1OceW/pgdRjqEo21Pk6XH2yzLAd8="
7
- # POSTMARK_CI_RECIPIENT=?
8
- - secure: "YnccT2MM+hIfwxl1WtcTk48q+D9XY7p6FTHkeJbUoaT9PFXQqXyUCQpwk5wYAwzZbVWG/CgH4PitWyRbWBP6kAqYKlsnAkQip0FNjs0DbK0SH9YvcFFSDZsTAl9yfwSxlgnBZHGZ49LO3yISMPUOdNn1QmaF4Ndpl4hiycH7UA8="
9
- # POSTMARK_CI_SENDER=?
10
- - secure: "Cz/KfiXkd90GQr+47LunlZnal8clrRpKmZUd9K161RYd5bfkL+P6SnEmhMprwdzomUBqIcqleR9HjmECey2V/Zd9V8vtBaLVZ5CoeMTkz3Tu6SllfmpymkcuJKf7GGizs97gmhPMlJd9iMukL6eqW4/1C9HW0cLZFB/jlzqFHpE="
11
- language: ruby
12
- rvm:
13
- - 2.0.0
14
- - 2.1.9
15
- - 2.2.5
16
- - 2.3.1
17
- - 2.5.7
18
- - 2.6.5
19
- - 2.7.0
20
- matrix:
21
- include:
22
- - rvm: 1.8.7
23
- dist: precise
24
- gemfile: gemfiles/Gemfile.legacy
25
- - rvm: 1.9.3
26
- gemfile: gemfiles/Gemfile.legacy
27
- - rvm: jruby-19mode
28
- jdk: oraclejdk8
29
- dist: trusty
30
- gemfile: gemfiles/Gemfile.legacy
31
- script: bundle exec rake spec