postmark 1.21.3 → 1.21.7

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: fb0f51e437e4831ac7fe011e089ac51c00984a614f48f31e94cce6233331f3bd
4
- data.tar.gz: 599f2b99b5a8bca7a5761c560feddac36cd252a2232431008c3eabc1ef3375b0
3
+ metadata.gz: b2bd2c9a288c0f4baa7f2f076d91151a0835b8b168c76e6b1938d5aee972d118
4
+ data.tar.gz: 5f8ef5865ba91468d5d413f111af5f195adaf0c44983749605e7e015d9b79eb3
5
5
  SHA512:
6
- metadata.gz: 7f16405603d847f6e8b4124a7da3c478db38555196016d59cb743c4d63f154e512ffac6d9db74702340e19cfa2afdb04965fdcb3436ab92c62f031d2d2b7ba0b
7
- data.tar.gz: 6429f12e770e5a305f2bcb705cff501c48ebeb45be85dbd78f44e32cc4b5312abd0d6d9789c5c29e7cb3fca411a4e1a748a34fdc35e703862202e7c72851a0be
6
+ metadata.gz: ba8d2597f8502259ef996c647d08f5264e6c677aa4d3e0e697156442b35fe6a1503b914f156b83a627dadaf4cdb64e3e159049d2031e52c675ff721b960abc16
7
+ data.tar.gz: 538224ea9fa9c537f9671a5f9de5bfb1a7dc9078f531b6ef8fc8f1c02aa64fda4e82e8031ad5da37abcaeb793b65fd4b5b541e6329181e8e0e21af8d05d0fc93
@@ -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/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,21 @@
1
1
  = Changelog
2
2
 
3
+ == 1.21.7
4
+
5
+ * Improved parsing recipients with Postmark::InactiveRecipientError.parse_recipients method
6
+
7
+ == 1.21.6
8
+
9
+ * Improved error handling for email sending related to invalid email addresses
10
+
11
+ == 1.21.5
12
+
13
+ * Added support for archiving/unarchiving message streams
14
+
15
+ == 1.21.4
16
+
17
+ * Fixed Postmark::ApiClient#deliver_messages_with_templates (#104)
18
+
3
19
  == 1.21.3
4
20
 
5
21
  * Remove default SSL version setting and rely on Net::HTTP/OpenSSL default.
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 © 2020 Wildbit LLC.
66
+ Copyright © 2021 Wildbit LLC.
data/RELEASE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  New versions of the gem are cut by the Postmark team, this is a quick guide to ensuring a smooth release.
2
2
 
3
- 1. Verify all builds are passing on Travis for your branch.
3
+ 1. Verify all builds are passing on CircleCI for your branch.
4
4
  1. Merge in your branch to master.
5
5
  1. Update VERSION and lib/postmark/version.rb with the new version.
6
6
  1. Update CHANGELOG.rdoc with a brief description of the changes.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.21.3
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|
@@ -351,6 +352,14 @@ module Postmark
351
352
  format_response(http_client.patch("message-streams/#{id}", data))
352
353
  end
353
354
 
355
+ def archive_message_stream(id)
356
+ format_response http_client.post("message-streams/#{id}/archive")
357
+ end
358
+
359
+ def unarchive_message_stream(id)
360
+ format_response http_client.post("message-streams/#{id}/unarchive")
361
+ end
362
+
354
363
  def dump_suppressions(stream_id, options = {})
355
364
  _, batch = load_batch("message-streams/#{stream_id}/suppressions/dump", 'Suppressions', options)
356
365
  batch
@@ -30,9 +30,8 @@ module Postmark
30
30
  def initialize(status_code = 500, body = '', parsed_body = {})
31
31
  self.parsed_body = parsed_body
32
32
  self.status_code = status_code.to_i
33
- message = parsed_body.fetch(
34
- 'Message',
35
- "The Postmark API responded with HTTP status #{status_code}.")
33
+ self.body = body
34
+ message = parsed_body.fetch('Message', "The Postmark API responded with HTTP status #{status_code}.")
36
35
 
37
36
  super(message)
38
37
  end
@@ -44,6 +43,7 @@ module Postmark
44
43
 
45
44
  class ApiInputError < HttpServerError
46
45
  INACTIVE_RECIPIENT = 406
46
+ INVALID_EMAIL_ADDRESS = 300
47
47
 
48
48
  attr_accessor :error_code
49
49
 
@@ -52,7 +52,9 @@ module Postmark
52
52
 
53
53
  case error_code
54
54
  when INACTIVE_RECIPIENT
55
- InactiveRecipientError.new(INACTIVE_RECIPIENT, body, parsed_body)
55
+ InactiveRecipientError.new(error_code, body, parsed_body)
56
+ when INVALID_EMAIL_ADDRESS
57
+ InvalidEmailAddressError.new(error_code, body, parsed_body)
56
58
  else
57
59
  new(error_code, body, parsed_body)
58
60
  end
@@ -68,12 +70,14 @@ module Postmark
68
70
  end
69
71
  end
70
72
 
73
+ class InvalidEmailAddressError < ApiInputError; end
74
+
71
75
  class InactiveRecipientError < ApiInputError
72
76
  attr_reader :recipients
73
77
 
74
78
  PATTERNS = [/^Found inactive addresses: (.+?)\.$/.freeze,
75
- /^Found inactive addresses: (.+?)\.$/.freeze,
76
- /these inactive addresses: (.+?)\. Inactive/.freeze].freeze
79
+ /these inactive addresses: (.+?)\. Inactive/.freeze,
80
+ /these inactive addresses: (.+?)\.?$/].freeze
77
81
 
78
82
  def self.parse_recipients(message)
79
83
  PATTERNS.each do |p|
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.21.3'
2
+ VERSION = '1.21.7'
3
3
  end
data/postmark.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.license = 'MIT'
11
11
 
12
- s.authors = ["Petyo Ivanov", "Ilya Sabanin", "Artem Chistyakov"]
13
- s.email = "ilya@wildbit.com"
12
+ s.authors = ["Tomek Maszkowski", "Igor Balos", "Artem Chistyakov", "Nick Hammond", "Petyo Ivanov", "Ilya Sabanin"]
13
+ s.email = "tomek@wildbit.com"
14
14
  s.extra_rdoc_files = ["LICENSE", "README.md"]
15
15
  s.rdoc_options = ["--charset=UTF-8"]
16
16
 
@@ -201,7 +201,7 @@ describe Postmark::ApiClient do
201
201
  describe "#deliver_messages_with_templates" do
202
202
  let(:email) {templated_message.to_postmark_hash}
203
203
  let(:emails) {[email, email, email]}
204
- let(:emails_json) {Postmark::Json.encode(emails)}
204
+ let(:emails_json) {Postmark::Json.encode(:Messages => emails)}
205
205
  let(:response) {[{}, {}, {}]}
206
206
  let(:messages) { Array.new(3) { templated_message } }
207
207
 
@@ -606,10 +606,14 @@ describe Postmark::ApiClient do
606
606
  end
607
607
 
608
608
  describe "#server_info" do
609
- let(:response) {{"Name" => "Testing",
610
- "Color" => "blue",
611
- "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
612
- "SmtpApiActivated" => true}}
609
+ let(:response) {
610
+ {
611
+ "Name" => "Testing",
612
+ "Color" => "blue",
613
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
614
+ "SmtpApiActivated" => true
615
+ }
616
+ }
613
617
 
614
618
  it 'requests server info from Postmark and converts it to ruby format' do
615
619
  expect(http_client).to receive(:get).with('server') {response}
@@ -618,10 +622,14 @@ describe Postmark::ApiClient do
618
622
  end
619
623
 
620
624
  describe "#update_server_info" do
621
- let(:response) {{"Name" => "Testing",
622
- "Color" => "blue",
623
- "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
624
- "SmtpApiActivated" => false}}
625
+ let(:response) {
626
+ {
627
+ "Name" => "Testing",
628
+ "Color" => "blue",
629
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
630
+ "SmtpApiActivated" => false
631
+ }
632
+ }
625
633
  let(:update) {{:smtp_api_activated => false}}
626
634
 
627
635
  it 'updates server info in Postmark and converts it to ruby format' do
@@ -1148,6 +1156,62 @@ describe Postmark::ApiClient do
1148
1156
  }
1149
1157
  end
1150
1158
 
1159
+ describe '#archive_message_stream' do
1160
+ subject { api_client.archive_message_stream(stream_id) }
1161
+
1162
+ let(:stream_id) { 'my-stream'}
1163
+ let(:server_id) { 123 }
1164
+ let(:purge_date) { '2030-08-30T12:30:00.00-04:00' }
1165
+ let(:api_endpoint) { "message-streams/#{stream_id}/archive" }
1166
+ let(:api_response) {{ 'ID' => stream_id, 'ServerID' => server_id, 'ExpectedPurgeDate' => purge_date }}
1167
+
1168
+ before do
1169
+ allow(http_client).to receive(:post).with(api_endpoint) { api_response }
1170
+ end
1171
+
1172
+ it 'calls the API endpoint' do
1173
+ expect(http_client).to receive(:post).with(api_endpoint)
1174
+ subject
1175
+ end
1176
+
1177
+ it 'transforms the API response' do
1178
+ expect(subject).to eq({ :id => stream_id, :server_id => server_id, :expected_purge_date => purge_date })
1179
+ end
1180
+ end
1181
+
1182
+ describe '#unarchive_message_stream' do
1183
+ subject { api_client.unarchive_message_stream(stream_id) }
1184
+
1185
+ let(:stream_id) { 'my-stream'}
1186
+ let(:server_id) { 123 }
1187
+ let(:api_endpoint) { "message-streams/#{stream_id}/unarchive" }
1188
+ let(:api_response) {
1189
+ { 'ID' => stream_id, 'ServerID' => server_id, 'Name' => 'My Stream',
1190
+ 'Description' => 'My test stream.', 'MessageStreamType' => 'Transactional',
1191
+ 'CreatedAt' => '2030-08-30T12:30:00.00-04:00', 'UpdatedAt' => '2030-09-30T12:30:00.00-04:00',
1192
+ 'ArchivedAt'=> nil, 'ExpectedPurgeDate' => nil,
1193
+ 'SubscriptionManagementConfiguration' => { 'UnsubscribeHandlingType' => 'None' } }
1194
+ }
1195
+
1196
+ before do
1197
+ allow(http_client).to receive(:post).with(api_endpoint) { api_response }
1198
+ end
1199
+
1200
+ it 'calls the API endpoint' do
1201
+ expect(http_client).to receive(:post).with(api_endpoint)
1202
+ subject
1203
+ end
1204
+
1205
+ it 'transforms the API response' do
1206
+ expect(subject).to eq({ :id => stream_id, :server_id => server_id, :name => 'My Stream',
1207
+ :description => 'My test stream.', :message_stream_type => 'Transactional',
1208
+ :created_at => '2030-08-30T12:30:00.00-04:00',
1209
+ :updated_at => '2030-09-30T12:30:00.00-04:00',
1210
+ :archived_at => nil , :expected_purge_date => nil ,
1211
+ :subscription_management_configuration => { 'UnsubscribeHandlingType' => 'None' }})
1212
+ end
1213
+ end
1214
+
1151
1215
  describe '#create_suppressions' do
1152
1216
  let(:email_addresses) { nil }
1153
1217
  let(:message_stream_id) { 'outbound' }
@@ -97,6 +97,13 @@ describe(Postmark::ApiInputError) do
97
97
  it_behaves_like 'api input error'
98
98
  end
99
99
 
100
+ context '300' do
101
+ let(:code) {Postmark::ApiInputError::INVALID_EMAIL_ADDRESS}
102
+
103
+ it {is_expected.to be_a(Postmark::InvalidEmailAddressError)}
104
+ it_behaves_like 'api input error'
105
+ end
106
+
100
107
  context 'others' do
101
108
  let(:code) {'9999'}
102
109
 
@@ -142,6 +149,33 @@ describe(Postmark::MailAdapterError) do
142
149
  it {is_expected.to be_a(Postmark::Error)}
143
150
  end
144
151
 
152
+ describe(Postmark::InvalidEmailAddressError) do
153
+ describe '.new' do
154
+ let(:response) {{'Message' => message}}
155
+
156
+ subject do
157
+ Postmark::InvalidEmailAddressError.new(
158
+ Postmark::ApiInputError::INVALID_EMAIL_ADDRESS, Postmark::Json.encode(response), response)
159
+ end
160
+
161
+ let(:message) do
162
+ "Error parsing 'To': Illegal email address 'johne.xample.com'. It must contain the '@' symbol."
163
+ end
164
+
165
+ it 'body is set' do
166
+ expect(subject.body).to eq(Postmark::Json.encode(response))
167
+ end
168
+
169
+ it 'parsed body is set' do
170
+ expect(subject.parsed_body).to eq(response)
171
+ end
172
+
173
+ it 'error code is set' do
174
+ expect(subject.error_code).to eq(Postmark::ApiInputError::INVALID_EMAIL_ADDRESS)
175
+ end
176
+ end
177
+ end
178
+
145
179
  describe(Postmark::InactiveRecipientError) do
146
180
  describe '.parse_recipients' do
147
181
  let(:recipients) do
@@ -161,6 +195,12 @@ describe(Postmark::InactiveRecipientError) do
161
195
  it {is_expected.to eq(recipients.take(1))}
162
196
  end
163
197
 
198
+ context 'i/n inactive, n > 1, i < n - new message format' do
199
+ let(:message) { "Message OK, but will not deliver to these inactive addresses: #{recipients[0...2].join(', ')}" }
200
+
201
+ it {is_expected.to eq(recipients.take(2))}
202
+ end
203
+
164
204
  context 'i/n inactive, n > 1, i < n' do
165
205
  let(:message) do
166
206
  'Message OK, but will not deliver to these inactive addresses: ' \
@@ -209,6 +249,18 @@ describe(Postmark::InactiveRecipientError) do
209
249
  it 'parses recipients from json payload' do
210
250
  expect(subject.recipients).to eq([address])
211
251
  end
252
+
253
+ it 'body is set' do
254
+ expect(subject.body).to eq(Postmark::Json.encode(response))
255
+ end
256
+
257
+ it 'parsed body is set' do
258
+ expect(subject.parsed_body).to eq(response)
259
+ end
260
+
261
+ it 'error code is set' do
262
+ expect(subject.error_code).to eq(Postmark::ApiInputError::INACTIVE_RECIPIENT)
263
+ end
212
264
  end
213
265
  end
214
266
 
metadata CHANGED
@@ -1,16 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.3
4
+ version: 1.21.7
5
5
  platform: ruby
6
6
  authors:
7
+ - Tomek Maszkowski
8
+ - Igor Balos
9
+ - Artem Chistyakov
10
+ - Nick Hammond
7
11
  - Petyo Ivanov
8
12
  - Ilya Sabanin
9
- - Artem Chistyakov
10
13
  autorequire:
11
14
  bindir: bin
12
15
  cert_chain: []
13
- date: 2020-12-03 00:00:00.000000000 Z
16
+ date: 2021-07-22 00:00:00.000000000 Z
14
17
  dependencies:
15
18
  - !ruby/object:Gem::Dependency
16
19
  name: json
@@ -56,18 +59,18 @@ dependencies:
56
59
  version: '0'
57
60
  description: Use this gem to send emails through Postmark HTTP API and retrieve info
58
61
  about bounces.
59
- email: ilya@wildbit.com
62
+ email: tomek@wildbit.com
60
63
  executables: []
61
64
  extensions: []
62
65
  extra_rdoc_files:
63
66
  - LICENSE
64
67
  - README.md
65
68
  files:
69
+ - ".circleci/config.yml"
66
70
  - ".document"
67
71
  - ".gitignore"
68
72
  - ".rake_tasks"
69
73
  - ".rspec"
70
- - ".travis.yml"
71
74
  - CHANGELOG.rdoc
72
75
  - CONTRIBUTING.md
73
76
  - Gemfile
@@ -147,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
150
  - !ruby/object:Gem::Version
148
151
  version: 1.3.7
149
152
  requirements: []
150
- rubygems_version: 3.1.4
153
+ rubygems_version: 3.2.3
151
154
  signing_key:
152
155
  specification_version: 4
153
156
  summary: Official Postmark API wrapper.
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: "XJkpUbAC1N6vcL/bUvqX2Mx8OKXpr/3zwqhjGiWhrSGKmQJUNnK4TEGFjnb1TBncZvW5cBRD0oX1Tt7gAu4o8C6sldVf35hB5FQsEyQrgSN4s95uLHuTW9EQisiQS6kzPLbkUmsMIQhIlfNGKQ5tRzRQstip81E8a0Emth3Y9EQ="
9
- # POSTMARK_CI_SENDER=?
10
- - secure: "bOoU3WEFur/SqwTY0m0aGqy8v8AZfZtFFHNYsU/BtAppZXj378CiktvJGj+cz/KMqFEWyJKNzchFOfZa45Q9Xor/QbTqkBriTOz3Ff7gQpmuPfLSvWRQSLRmbRFgr0Dk8QCTTtfnNtnajxMUyGfxwCiMo+l3EEAqjtLpN+Gja20="
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