postmark 1.21.8 → 1.22.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
  SHA256:
3
- metadata.gz: bd56ea1117c73ce9a8f60d4dc81dd29f3b409efe1f362a534cb6a9b16a67dc60
4
- data.tar.gz: 245374f9fb1752254c9c32aeff3ee0139b4b5bce4d252ce40c4f9d2627db42f7
3
+ metadata.gz: b214577bda32a36ea3de8910d8ef1bf7929e090e513a30d32ae891219134234b
4
+ data.tar.gz: 7379520e17f6e9afda7e7157e4e118ccd1b171298e211555e112e5963433880c
5
5
  SHA512:
6
- metadata.gz: 17ad62b39034c58dfa35b9aeb296d609b35d786ae1c752abe07df6be4bf7743ecac1a9d83675e1ed860f7e01354bdc9761ccf742fbfe60c5bdd4016fbb831d9b
7
- data.tar.gz: a3a0792f2525acc786627d7f16b0faa453b9608397a88d270a2bdcf61da3a00549a6bfb0eb92096f1015825fe4813fa5d62c1ba5b591bc675761c65fa2f38fac
6
+ metadata.gz: 9bf13b2db7d0818a8f69286b4ece4ad1675b8e546a9677f23f9827915c80795b5118a16a9a32860dfab3b35b5b694791ef3e48bc8d2eca13dd05228fe634f3a2
7
+ data.tar.gz: a4ce846c304fea9a62ffd3bcc4802675a435009b6536741ad3b32c9dd98780925f57d0e32fa1c40c1d45c0b8ca5096d626140c4fd78268a072231a7fc4dc4fdc
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = Changelog
2
2
 
3
+ == 1.22.0
4
+
5
+ * Disabled automatic retries of failed requests by default. You can enabled it by passing `max_retries` option to the client constructor.
6
+
3
7
  == 1.21.8
4
8
 
5
9
  * Fixed passing and receiving SubscriptionManagementConfiguration when creating/updating message streams (#94).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.21.8
1
+ 1.22.0
@@ -6,7 +6,7 @@ module Postmark
6
6
 
7
7
  def initialize(api_token, options = {})
8
8
  options = options.dup
9
- @max_retries = options.delete(:max_retries) || 3
9
+ @max_retries = options.delete(:max_retries) || 0
10
10
  @http_client = HttpClient.new(api_token, options)
11
11
  end
12
12
 
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.21.8'
2
+ VERSION = '1.22.0'
3
3
  end
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Postmark::ApiClient do
4
+ let(:api_client) {Postmark::ApiClient.new(api_token)}
4
5
  let(:api_token) {"provided-api-token"}
5
- let(:max_retries) {42}
6
6
  let(:message_hash) {{:from => "support@postmarkapp.com"}}
7
- let(:message) {
7
+ let(:message) do
8
8
  Mail.new do
9
9
  from "support@postmarkapp.com"
10
10
  delivery_method Mail::Postmark
11
11
  end
12
- }
12
+ end
13
13
  let(:templated_message) do
14
14
  Mail.new do
15
15
  from "sheldon@bigbangtheory.com"
@@ -20,28 +20,68 @@ describe Postmark::ApiClient do
20
20
  end
21
21
  let(:http_client) {api_client.http_client}
22
22
 
23
- subject(:api_client) {Postmark::ApiClient.new(api_token)}
23
+ shared_examples "retryable" do |response|
24
+ let(:api_client) do
25
+ Postmark::ApiClient.new(
26
+ api_token,
27
+ max_retries.nil? ? {} : {:max_retries => max_retries}
28
+ )
29
+ end
30
+ let(:max_retries) {nil}
31
+
32
+ context 'with no retries' do
33
+ let(:max_retries) {nil}
34
+
35
+ it "doesn't retry failed requests" do
36
+ expect(http_client).to receive(:post).once.and_raise(Postmark::InternalServerError)
37
+ expect {subject}.to raise_error(Postmark::InternalServerError)
38
+ end
39
+ end
40
+
41
+ context 'with 3 retries' do
42
+ let(:max_retries) {3}
43
+
44
+ it 'retries 3 times' do
45
+ expect(http_client).to receive(:post).twice.and_raise(Postmark::InternalServerError)
46
+ expect(http_client).to receive(:post).and_return(response)
47
+ expect {subject}.not_to raise_error
48
+ end
49
+
50
+ it 'gives up after 3 retries' do
51
+ expect(http_client).to receive(:post).thrice.and_raise(Postmark::InternalServerError)
52
+ expect {subject}.to raise_error(Postmark::InternalServerError)
53
+ end
54
+
55
+ it "retries on timeout" do
56
+ expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
57
+ expect(http_client).to receive(:post).and_return(response)
58
+ expect {subject}.not_to raise_error
59
+ end
60
+ end
61
+ end
24
62
 
25
- context "attr readers" do
26
- it { expect(subject).to respond_to(:http_client) }
27
- it { expect(subject).to respond_to(:max_retries) }
63
+ describe "attr readers" do
64
+ it { expect(api_client).to respond_to(:http_client) }
65
+ it { expect(api_client).to respond_to(:max_retries) }
28
66
  end
29
67
 
30
68
  context "when it's created without options" do
31
- it "max retries" do
32
- expect(subject.max_retries).to eq 3
33
- end
69
+ let(:api_client) {Postmark::ApiClient.new(api_token)}
70
+
71
+ specify { expect(api_client.max_retries).to eq 0 }
34
72
  end
35
73
 
36
74
  context "when it's created with user options" do
37
- subject {Postmark::ApiClient.new(api_token, :max_retries => max_retries, :foo => :bar)}
38
- it "max_retries" do
39
- expect(subject.max_retries).to eq max_retries
75
+ let(:api_client) {Postmark::ApiClient.new(api_token, options)}
76
+ let(:options) { {:max_retries => 42, :foo => :bar} }
77
+
78
+ it "sets max_retries" do
79
+ expect(api_client.max_retries).to eq 42
40
80
  end
41
81
 
42
82
  it 'passes other options to HttpClient instance' do
43
- allow(Postmark::HttpClient).to receive(:new).with(api_token, :foo => :bar)
44
- expect(subject).to be
83
+ expect(Postmark::HttpClient).to receive(:new).with(api_token, :foo => :bar)
84
+ api_client
45
85
  end
46
86
  end
47
87
 
@@ -49,185 +89,159 @@ describe Postmark::ApiClient do
49
89
  let(:api_token) {"new-api-token-value"}
50
90
 
51
91
  it 'assigns the api token to the http client instance' do
52
- subject.api_token = api_token
53
- expect(subject.http_client.api_token).to eq api_token
92
+ api_client.api_token = api_token
93
+ expect(api_client.http_client.api_token).to eq api_token
54
94
  end
55
95
 
56
96
  it 'is aliased as api_key=' do
57
- subject.api_key = api_token
58
- expect(subject.http_client.api_token).to eq api_token
97
+ api_client.api_key = api_token
98
+ expect(api_client.http_client.api_token).to eq api_token
59
99
  end
60
100
  end
61
101
 
62
102
  describe "#deliver" do
103
+ subject {api_client.deliver(message_hash)}
104
+
63
105
  let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
64
106
  let(:email_json) {Postmark::Json.encode(email)}
65
107
  let(:response) {{"MessageID" => 42}}
66
108
 
67
- it 'converts message hash to Postmark format and posts it to /email' do
68
- allow(http_client).to receive(:post).with('email', email_json) {response}
69
- subject.deliver(message_hash)
70
- end
71
-
72
- it 'retries 3 times' do
73
- expect(http_client).to receive(:post).twice.and_raise(Postmark::InternalServerError)
74
- expect(http_client).to receive(:post) {response}
75
- expect {subject.deliver(message_hash)}.not_to raise_error
109
+ it 'converts message hash to Postmark format and posts it to expected enpoint' do
110
+ expect(http_client).to receive(:post).with('email', email_json) {response}
111
+ subject
76
112
  end
77
113
 
78
114
  it 'converts response to ruby format' do
79
115
  expect(http_client).to receive(:post).with('email', email_json) {response}
80
- expect(subject.deliver(message_hash)).to have_key(:message_id)
116
+ expect(subject).to have_key(:message_id)
81
117
  end
118
+
119
+ it_should_behave_like "retryable"
82
120
  end
83
121
 
84
122
  describe "#deliver_in_batches" do
123
+ subject {api_client.deliver_in_batches([message_hash, message_hash, message_hash])}
124
+
85
125
  let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
86
126
  let(:emails) {[email, email, email]}
87
127
  let(:emails_json) {Postmark::Json.encode(emails)}
88
128
  let(:response) {[{'ErrorCode' => 0}, {'ErrorCode' => 0}, {'ErrorCode' => 0}]}
89
129
 
90
- it 'turns array of messages into a JSON document and posts it to /email/batch' do
130
+ it 'turns array of messages into a JSON document and posts it to expected endpoint' do
91
131
  expect(http_client).to receive(:post).with('email/batch', emails_json) {response}
92
- subject.deliver_in_batches([message_hash, message_hash, message_hash])
132
+ subject
93
133
  end
94
134
 
95
135
  it 'converts response to ruby format' do
96
136
  expect(http_client).to receive(:post).with('email/batch', emails_json) {response}
97
- response = subject.deliver_in_batches([message_hash, message_hash, message_hash])
137
+ response = subject
98
138
  expect(response.first).to have_key(:error_code)
99
139
  end
140
+
141
+ it_should_behave_like "retryable"
100
142
  end
101
143
 
102
144
  describe "#deliver_message" do
145
+ subject {api_client.deliver_message(message)}
146
+
103
147
  let(:email) {message.to_postmark_hash}
104
148
  let(:email_json) {Postmark::Json.encode(email)}
105
149
 
106
- it 'raises an error when given a templated message' do
107
- expect { subject.deliver_message(templated_message) }.
108
- to raise_error(ArgumentError, /Please use Postmark::ApiClient\#deliver_message_with_template/)
109
- end
110
-
111
- it 'turns message into a JSON document and posts it to /email' do
112
- expect(http_client).to receive(:post).with('email', email_json)
113
- subject.deliver_message(message)
114
- end
150
+ context 'when given a templated message' do
151
+ let(:message) {templated_message}
115
152
 
116
- it "retries 3 times" do
117
- 2.times do
118
- expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
153
+ specify do
154
+ expect { subject }.to raise_error(ArgumentError, /Please use Postmark::ApiClient\#deliver_message_with_template/)
119
155
  end
120
- expect(http_client).to receive(:post)
121
- expect {subject.deliver_message(message)}.not_to raise_error
122
156
  end
123
157
 
124
- it "retries on timeout" do
125
- expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
126
- expect(http_client).to receive(:post)
127
- expect {subject.deliver_message(message)}.not_to raise_error
158
+ it 'turns message into a JSON document and posts it to /email' do
159
+ expect(http_client).to receive(:post).with('email', email_json)
160
+ subject
128
161
  end
129
162
 
130
163
  it "proxies errors" do
131
164
  allow(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
132
- expect {subject.deliver_message(message)}.to raise_error(Postmark::TimeoutError)
165
+ expect {subject}.to raise_error(Postmark::TimeoutError)
133
166
  end
167
+
168
+ it_should_behave_like "retryable"
134
169
  end
135
170
 
136
171
  describe "#deliver_message_with_template" do
172
+ subject {api_client.deliver_message_with_template(templated_message)}
173
+
137
174
  let(:email) {templated_message.to_postmark_hash}
138
175
  let(:email_json) {Postmark::Json.encode(email)}
139
176
 
140
- it 'raises an error when given a non-templated message' do
141
- expect { subject.deliver_message_with_template(message) }.
142
- to raise_error(ArgumentError, 'Templated delivery requested, but the template is missing.')
143
- end
144
-
145
- it 'turns message into a JSON document and posts it to /email' do
146
- expect(http_client).to receive(:post).with('email/withTemplate', email_json)
147
- subject.deliver_message_with_template(templated_message)
148
- end
177
+ context 'when given a non-templated message' do
178
+ let(:templated_message) {message}
149
179
 
150
- it "retries 3 times" do
151
- 2.times do
152
- expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
180
+ specify do
181
+ expect { subject }.to raise_error(ArgumentError, 'Templated delivery requested, but the template is missing.')
153
182
  end
154
- expect(http_client).to receive(:post)
155
- expect {subject.deliver_message_with_template(templated_message)}.not_to raise_error
156
183
  end
157
184
 
158
- it "retries on timeout" do
159
- expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
160
- expect(http_client).to receive(:post)
161
- expect {subject.deliver_message_with_template(templated_message)}.not_to raise_error
185
+ it 'turns message into a JSON document and posts it to expected endpoint' do
186
+ expect(http_client).to receive(:post).with('email/withTemplate', email_json)
187
+ subject
162
188
  end
163
189
 
164
190
  it "proxies errors" do
165
191
  allow(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
166
- expect {subject.deliver_message_with_template(templated_message)}.to raise_error(Postmark::TimeoutError)
192
+ expect {subject}.to raise_error(Postmark::TimeoutError)
167
193
  end
194
+
195
+ it_should_behave_like "retryable"
168
196
  end
169
197
 
170
198
  describe "#deliver_messages" do
199
+ subject {api_client.deliver_messages(messages)}
200
+
201
+ let(:messages) {[message, message, message]}
171
202
  let(:email) {message.to_postmark_hash}
172
- let(:emails) {[email, email, email]}
173
- let(:emails_json) {Postmark::Json.encode(emails)}
203
+ let(:emails_json) {Postmark::Json.encode(Array.new(3) { email })}
174
204
  let(:response) {[{}, {}, {}]}
175
205
 
176
- it 'raises an error when given a templated message' do
177
- expect { subject.deliver_messages([templated_message]) }.
178
- to raise_error(ArgumentError, /Please use Postmark::ApiClient\#deliver_messages_with_templates/)
206
+ context 'when given templated messages' do
207
+ let(:messages) {[templated_message]}
208
+
209
+ specify do
210
+ expect { subject }.to raise_error(ArgumentError, /Please use Postmark::ApiClient\#deliver_messages_with_templates/)
211
+ end
179
212
  end
180
213
 
181
214
  it 'turns array of messages into a JSON document and posts it to /email/batch' do
182
215
  expect(http_client).to receive(:post).with('email/batch', emails_json) {response}
183
- subject.deliver_messages([message, message, message])
184
- end
185
-
186
- it "retry 3 times" do
187
- 2.times do
188
- expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
189
- end
190
- expect(http_client).to receive(:post) {response}
191
- expect {subject.deliver_messages([message, message, message])}.not_to raise_error
216
+ subject
192
217
  end
193
218
 
194
- it "retry on timeout" do
195
- expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
196
- expect(http_client).to receive(:post) {response}
197
- expect {subject.deliver_messages([message, message, message])}.not_to raise_error
198
- end
219
+ it_should_behave_like 'retryable', []
199
220
  end
200
221
 
201
222
  describe "#deliver_messages_with_templates" do
223
+ subject {api_client.deliver_messages_with_templates(messages)}
224
+
202
225
  let(:email) {templated_message.to_postmark_hash}
203
- let(:emails) {[email, email, email]}
204
- let(:emails_json) {Postmark::Json.encode(:Messages => emails)}
226
+ let(:emails_json) {Postmark::Json.encode(:Messages => Array.new(3) { email })}
205
227
  let(:response) {[{}, {}, {}]}
206
228
  let(:messages) { Array.new(3) { templated_message } }
207
229
 
208
- it 'raises an error when given a templated message' do
209
- expect { subject.deliver_messages_with_templates([message]) }.
210
- to raise_error(ArgumentError, 'Templated delivery requested, but one or more messages lack templates.')
211
- end
212
-
213
- it 'turns array of messages into a JSON document and posts it to /email/batch' do
214
- expect(http_client).to receive(:post).with('email/batchWithTemplates', emails_json) {response}
215
- subject.deliver_messages_with_templates(messages)
216
- end
230
+ context 'when given a non-templated message' do
231
+ let(:messages) {[message]}
217
232
 
218
- it "retry 3 times" do
219
- 2.times do
220
- expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
233
+ it 'raises an error ' do
234
+ expect { subject }.
235
+ to raise_error(ArgumentError, 'Templated delivery requested, but one or more messages lack templates.')
221
236
  end
222
- expect(http_client).to receive(:post) {response}
223
- expect {subject.deliver_messages_with_templates(messages)}.not_to raise_error
224
237
  end
225
238
 
226
- it "retry on timeout" do
227
- expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
228
- expect(http_client).to receive(:post) {response}
229
- expect {subject.deliver_messages_with_templates(messages)}.not_to raise_error
239
+ it 'turns array of messages into a JSON document and posts it to expected endpoint' do
240
+ expect(http_client).to receive(:post).with('email/batchWithTemplates', emails_json) {response}
241
+ subject
230
242
  end
243
+
244
+ it_should_behave_like 'retryable', []
231
245
  end
232
246
 
233
247
  describe "#delivery_stats" do
@@ -235,7 +249,7 @@ describe Postmark::ApiClient do
235
249
 
236
250
  it 'requests data at /deliverystats' do
237
251
  expect(http_client).to receive(:get).with("deliverystats") {response}
238
- expect(subject.delivery_stats).to have_key(:bounces)
252
+ expect(api_client.delivery_stats).to have_key(:bounces)
239
253
  end
240
254
  end
241
255
 
@@ -244,13 +258,13 @@ describe Postmark::ApiClient do
244
258
  let(:response) {{'TotalCount' => 5, 'Messages' => [{}].cycle(5).to_a}}
245
259
 
246
260
  it 'returns an enumerator' do
247
- expect(subject.messages).to be_kind_of(Enumerable)
261
+ expect(api_client.messages).to be_kind_of(Enumerable)
248
262
  end
249
263
 
250
264
  it 'loads outbound messages' do
251
- allow(subject.http_client).to receive(:get).
265
+ allow(api_client.http_client).to receive(:get).
252
266
  with('messages/outbound', an_instance_of(Hash)).and_return(response)
253
- expect(subject.messages.count).to eq(5)
267
+ expect(api_client.messages.count).to eq(5)
254
268
  end
255
269
  end
256
270
 
@@ -258,12 +272,12 @@ describe Postmark::ApiClient do
258
272
  let(:response) {{'TotalCount' => 5, 'InboundMessages' => [{}].cycle(5).to_a}}
259
273
 
260
274
  it 'returns an enumerator' do
261
- expect(subject.messages(:inbound => true)).to be_kind_of(Enumerable)
275
+ expect(api_client.messages(:inbound => true)).to be_kind_of(Enumerable)
262
276
  end
263
277
 
264
278
  it 'loads inbound messages' do
265
- allow(subject.http_client).to receive(:get).with('messages/inbound', an_instance_of(Hash)).and_return(response)
266
- expect(subject.messages(:inbound => true).count).to eq(5)
279
+ allow(api_client.http_client).to receive(:get).with('messages/inbound', an_instance_of(Hash)).and_return(response)
280
+ expect(api_client.messages(:inbound => true).count).to eq(5)
267
281
  end
268
282
  end
269
283
  end
@@ -276,7 +290,7 @@ describe Postmark::ApiClient do
276
290
  expect(http_client).to receive(:get).
277
291
  with('messages/outbound', :offset => 50, :count => 50).
278
292
  and_return(response)
279
- subject.get_messages(:offset => 50, :count => 50)
293
+ api_client.get_messages(:offset => 50, :count => 50)
280
294
  end
281
295
  end
282
296
 
@@ -285,7 +299,7 @@ describe Postmark::ApiClient do
285
299
 
286
300
  it 'requests data at /messages/inbound' do
287
301
  expect(http_client).to receive(:get).with('messages/inbound', :offset => 50, :count => 50).and_return(response)
288
- expect(subject.get_messages(:inbound => true, :offset => 50, :count => 50)).to be_an(Array)
302
+ expect(api_client.get_messages(:inbound => true, :offset => 50, :count => 50)).to be_an(Array)
289
303
  end
290
304
  end
291
305
  end
@@ -296,19 +310,19 @@ describe Postmark::ApiClient do
296
310
  context 'given outbound' do
297
311
 
298
312
  it 'requests and returns outbound messages count' do
299
- allow(subject.http_client).to receive(:get).
313
+ allow(api_client.http_client).to receive(:get).
300
314
  with('messages/outbound', an_instance_of(Hash)).and_return(response)
301
- expect(subject.get_messages_count).to eq(42)
302
- expect(subject.get_messages_count(:inbound => false)).to eq(42)
315
+ expect(api_client.get_messages_count).to eq(42)
316
+ expect(api_client.get_messages_count(:inbound => false)).to eq(42)
303
317
  end
304
318
 
305
319
  end
306
320
 
307
321
  context 'given inbound' do
308
322
  it 'requests and returns inbound messages count' do
309
- allow(subject.http_client).to receive(:get).
323
+ allow(api_client.http_client).to receive(:get).
310
324
  with('messages/inbound', an_instance_of(Hash)).and_return(response)
311
- expect(subject.get_messages_count(:inbound => true)).to eq(42)
325
+ expect(api_client.get_messages_count(:inbound => true)).to eq(42)
312
326
  end
313
327
  end
314
328
 
@@ -323,7 +337,7 @@ describe Postmark::ApiClient do
323
337
  expect(http_client).to receive(:get).
324
338
  with("messages/outbound/#{id}/details", {}).
325
339
  and_return(response)
326
- expect(subject.get_message(id)).to have_key(:to)
340
+ expect(api_client.get_message(id)).to have_key(:to)
327
341
  end
328
342
  end
329
343
 
@@ -332,7 +346,7 @@ describe Postmark::ApiClient do
332
346
  expect(http_client).to receive(:get).
333
347
  with("messages/inbound/#{id}/details", {}).
334
348
  and_return(response)
335
- expect(subject.get_message(id, :inbound => true)).to have_key(:to)
349
+ expect(api_client.get_message(id, :inbound => true)).to have_key(:to)
336
350
  end
337
351
  end
338
352
  end
@@ -347,7 +361,7 @@ describe Postmark::ApiClient do
347
361
  expect(http_client).to receive(:get).
348
362
  with("messages/outbound/#{id}/dump", {}).
349
363
  and_return(response)
350
- expect(subject.dump_message(id)).to have_key(:body)
364
+ expect(api_client.dump_message(id)).to have_key(:body)
351
365
  end
352
366
 
353
367
  end
@@ -357,21 +371,21 @@ describe Postmark::ApiClient do
357
371
  expect(http_client).to receive(:get).
358
372
  with("messages/inbound/#{id}/dump", {}).
359
373
  and_return(response)
360
- expect(subject.dump_message(id, :inbound => true)).to have_key(:body)
374
+ expect(api_client.dump_message(id, :inbound => true)).to have_key(:body)
361
375
  end
362
376
  end
363
377
  end
364
378
 
365
379
  describe '#bounces' do
366
380
  it 'returns an Enumerator' do
367
- expect(subject.bounces).to be_kind_of(Enumerable)
381
+ expect(api_client.bounces).to be_kind_of(Enumerable)
368
382
  end
369
383
 
370
384
  it 'requests data at /bounces' do
371
- allow(subject.http_client).to receive(:get).
385
+ allow(api_client.http_client).to receive(:get).
372
386
  with('bounces', an_instance_of(Hash)).
373
387
  and_return('TotalCount' => 1, 'Bounces' => [{}])
374
- expect(subject.bounces.first(5).count).to eq(1)
388
+ expect(api_client.bounces.first(5).count).to eq(1)
375
389
  end
376
390
  end
377
391
 
@@ -381,8 +395,8 @@ describe Postmark::ApiClient do
381
395
 
382
396
  it 'requests data at /bounces' do
383
397
  allow(http_client).to receive(:get).with("bounces", options) {response}
384
- expect(subject.get_bounces(options)).to be_an(Array)
385
- expect(subject.get_bounces(options).count).to be_zero
398
+ expect(api_client.get_bounces(options)).to be_an(Array)
399
+ expect(api_client.get_bounces(options).count).to be_zero
386
400
  end
387
401
  end
388
402
 
@@ -391,7 +405,7 @@ describe Postmark::ApiClient do
391
405
 
392
406
  it 'requests a single bounce by ID at /bounces/:id' do
393
407
  expect(http_client).to receive(:get).with("bounces/#{id}")
394
- subject.get_bounce(id)
408
+ api_client.get_bounce(id)
395
409
  end
396
410
  end
397
411
 
@@ -400,7 +414,7 @@ describe Postmark::ApiClient do
400
414
 
401
415
  it 'requests a specific bounce data at /bounces/:id/dump' do
402
416
  expect(http_client).to receive(:get).with("bounces/#{id}/dump")
403
- subject.dump_bounce(id)
417
+ api_client.dump_bounce(id)
404
418
  end
405
419
  end
406
420
 
@@ -410,33 +424,33 @@ describe Postmark::ApiClient do
410
424
 
411
425
  it 'activates a specific bounce by sending a PUT request to /bounces/:id/activate' do
412
426
  expect(http_client).to receive(:put).with("bounces/#{id}/activate") {response}
413
- subject.activate_bounce(id)
427
+ api_client.activate_bounce(id)
414
428
  end
415
429
  end
416
430
 
417
431
  describe '#opens' do
418
432
  it 'returns an Enumerator' do
419
- expect(subject.opens).to be_kind_of(Enumerable)
433
+ expect(api_client.opens).to be_kind_of(Enumerable)
420
434
  end
421
435
 
422
436
  it 'performs a GET request to /opens/tags' do
423
- allow(subject.http_client).to receive(:get).
437
+ allow(api_client.http_client).to receive(:get).
424
438
  with('messages/outbound/opens', an_instance_of(Hash)).
425
439
  and_return('TotalCount' => 1, 'Opens' => [{}])
426
- expect(subject.opens.first(5).count).to eq(1)
440
+ expect(api_client.opens.first(5).count).to eq(1)
427
441
  end
428
442
  end
429
443
 
430
444
  describe '#clicks' do
431
445
  it 'returns an Enumerator' do
432
- expect(subject.clicks).to be_kind_of(Enumerable)
446
+ expect(api_client.clicks).to be_kind_of(Enumerable)
433
447
  end
434
448
 
435
449
  it 'performs a GET request to /clicks/tags' do
436
- allow(subject.http_client).to receive(:get).
450
+ allow(api_client.http_client).to receive(:get).
437
451
  with('messages/outbound/clicks', an_instance_of(Hash)).
438
452
  and_return('TotalCount' => 1, 'Clicks' => [{}])
439
- expect(subject.clicks.first(5).count).to eq(1)
453
+ expect(api_client.clicks.first(5).count).to eq(1)
440
454
  end
441
455
  end
442
456
 
@@ -446,8 +460,8 @@ describe Postmark::ApiClient do
446
460
 
447
461
  it 'performs a GET request to /messages/outbound/opens' do
448
462
  allow(http_client).to receive(:get).with('messages/outbound/opens', options) {response}
449
- expect(subject.get_opens(options)).to be_an(Array)
450
- expect(subject.get_opens(options).count).to be_zero
463
+ expect(api_client.get_opens(options)).to be_an(Array)
464
+ expect(api_client.get_opens(options).count).to be_zero
451
465
  end
452
466
  end
453
467
 
@@ -457,8 +471,8 @@ describe Postmark::ApiClient do
457
471
 
458
472
  it 'performs a GET request to /messages/outbound/clicks' do
459
473
  allow(http_client).to receive(:get).with('messages/outbound/clicks', options) {response}
460
- expect(subject.get_clicks(options)).to be_an(Array)
461
- expect(subject.get_clicks(options).count).to be_zero
474
+ expect(api_client.get_clicks(options)).to be_an(Array)
475
+ expect(api_client.get_clicks(options).count).to be_zero
462
476
  end
463
477
  end
464
478
 
@@ -469,8 +483,8 @@ describe Postmark::ApiClient do
469
483
 
470
484
  it 'performs a GET request to /messages/outbound/opens' do
471
485
  allow(http_client).to receive(:get).with("messages/outbound/opens/#{message_id}", options).and_return(response)
472
- expect(subject.get_opens_by_message_id(message_id, options)).to be_an(Array)
473
- expect(subject.get_opens_by_message_id(message_id, options).count).to be_zero
486
+ expect(api_client.get_opens_by_message_id(message_id, options)).to be_an(Array)
487
+ expect(api_client.get_opens_by_message_id(message_id, options).count).to be_zero
474
488
  end
475
489
  end
476
490
 
@@ -481,8 +495,8 @@ describe Postmark::ApiClient do
481
495
 
482
496
  it 'performs a GET request to /messages/outbound/clicks' do
483
497
  allow(http_client).to receive(:get).with("messages/outbound/clicks/#{message_id}", options).and_return(response)
484
- expect(subject.get_clicks_by_message_id(message_id, options)).to be_an(Array)
485
- expect(subject.get_clicks_by_message_id(message_id, options).count).to be_zero
498
+ expect(api_client.get_clicks_by_message_id(message_id, options)).to be_an(Array)
499
+ expect(api_client.get_clicks_by_message_id(message_id, options).count).to be_zero
486
500
  end
487
501
  end
488
502
 
@@ -490,14 +504,14 @@ describe Postmark::ApiClient do
490
504
  let(:message_id) {42}
491
505
 
492
506
  it 'returns an Enumerator' do
493
- expect(subject.opens_by_message_id(message_id)).to be_kind_of(Enumerable)
507
+ expect(api_client.opens_by_message_id(message_id)).to be_kind_of(Enumerable)
494
508
  end
495
509
 
496
510
  it 'performs a GET request to /opens/tags' do
497
- allow(subject.http_client).to receive(:get).
511
+ allow(api_client.http_client).to receive(:get).
498
512
  with("messages/outbound/opens/#{message_id}", an_instance_of(Hash)).
499
513
  and_return('TotalCount' => 1, 'Opens' => [{}])
500
- expect(subject.opens_by_message_id(message_id).first(5).count).to eq(1)
514
+ expect(api_client.opens_by_message_id(message_id).first(5).count).to eq(1)
501
515
  end
502
516
  end
503
517
 
@@ -505,14 +519,14 @@ describe Postmark::ApiClient do
505
519
  let(:message_id) {42}
506
520
 
507
521
  it 'returns an Enumerator' do
508
- expect(subject.clicks_by_message_id(message_id)).to be_kind_of(Enumerable)
522
+ expect(api_client.clicks_by_message_id(message_id)).to be_kind_of(Enumerable)
509
523
  end
510
524
 
511
525
  it 'performs a GET request to /clicks/tags' do
512
- allow(subject.http_client).to receive(:get).
526
+ allow(api_client.http_client).to receive(:get).
513
527
  with("messages/outbound/clicks/#{message_id}", an_instance_of(Hash)).
514
528
  and_return('TotalCount' => 1, 'Clicks' => [{}])
515
- expect(subject.clicks_by_message_id(message_id).first(5).count).to eq(1)
529
+ expect(api_client.clicks_by_message_id(message_id).first(5).count).to eq(1)
516
530
  end
517
531
  end
518
532
 
@@ -524,12 +538,12 @@ describe Postmark::ApiClient do
524
538
  it 'performs a POST request to /triggers/inboundrules with given options' do
525
539
  allow(http_client).to receive(:post).with('triggers/inboundrules',
526
540
  {'Rule' => 'example.com'}.to_json)
527
- subject.create_trigger(:inbound_rules, options)
541
+ api_client.create_trigger(:inbound_rules, options)
528
542
  end
529
543
 
530
544
  it 'symbolizes response keys' do
531
545
  allow(http_client).to receive(:post).and_return(response)
532
- expect(subject.create_trigger(:inbound_rules, options)).to eq(:rule => 'example.com')
546
+ expect(api_client.create_trigger(:inbound_rules, options)).to eq(:rule => 'example.com')
533
547
  end
534
548
  end
535
549
  end
@@ -539,12 +553,12 @@ describe Postmark::ApiClient do
539
553
 
540
554
  it 'performs a GET request to /triggers/tags/:id' do
541
555
  allow(http_client).to receive(:get).with("triggers/tags/#{id}")
542
- subject.get_trigger(:tags, id)
556
+ api_client.get_trigger(:tags, id)
543
557
  end
544
558
 
545
559
  it 'symbolizes response keys' do
546
560
  allow(http_client).to receive(:get).and_return('Foo' => 'Bar')
547
- expect(subject.get_trigger(:tags, id)).to eq(:foo => 'Bar')
561
+ expect(api_client.get_trigger(:tags, id)).to eq(:foo => 'Bar')
548
562
  end
549
563
  end
550
564
 
@@ -554,12 +568,12 @@ describe Postmark::ApiClient do
554
568
 
555
569
  it 'performs a DELETE request to /triggers/tags/:id' do
556
570
  allow(http_client).to receive(:delete).with("triggers/tags/#{id}")
557
- subject.delete_trigger(:tags, id)
571
+ api_client.delete_trigger(:tags, id)
558
572
  end
559
573
 
560
574
  it 'symbolizes response keys' do
561
575
  allow(http_client).to receive(:delete).and_return('Foo' => 'Bar')
562
- expect(subject.delete_trigger(:tags, id)).to eq(:foo => 'Bar')
576
+ expect(api_client.delete_trigger(:tags, id)).to eq(:foo => 'Bar')
563
577
  end
564
578
  end
565
579
 
@@ -568,12 +582,12 @@ describe Postmark::ApiClient do
568
582
 
569
583
  it 'performs a DELETE request to /triggers/inboundrules/:id' do
570
584
  allow(http_client).to receive(:delete).with("triggers/inboundrules/#{id}")
571
- subject.delete_trigger(:inbound_rules, id)
585
+ api_client.delete_trigger(:inbound_rules, id)
572
586
  end
573
587
 
574
588
  it 'symbolizes response keys' do
575
589
  allow(http_client).to receive(:delete).and_return('Rule' => 'example.com')
576
- expect(subject.delete_trigger(:tags, id)).to eq(:rule => 'example.com')
590
+ expect(api_client.delete_trigger(:tags, id)).to eq(:rule => 'example.com')
577
591
  end
578
592
  end
579
593
  end
@@ -586,22 +600,22 @@ describe Postmark::ApiClient do
586
600
 
587
601
  it 'performs a GET request to /triggers/inboundrules' do
588
602
  allow(http_client).to receive(:get).with('triggers/inboundrules', options) {response}
589
- expect(subject.get_triggers(:inbound_rules, options)).to be_an(Array)
590
- expect(subject.get_triggers(:inbound_rules, options).count).to be_zero
603
+ expect(api_client.get_triggers(:inbound_rules, options)).to be_an(Array)
604
+ expect(api_client.get_triggers(:inbound_rules, options).count).to be_zero
591
605
  end
592
606
  end
593
607
  end
594
608
 
595
609
  describe '#triggers' do
596
610
  it 'returns an Enumerator' do
597
- expect(subject.triggers(:tags)).to be_kind_of(Enumerable)
611
+ expect(api_client.triggers(:tags)).to be_kind_of(Enumerable)
598
612
  end
599
613
 
600
614
  it 'performs a GET request to /triggers/tags' do
601
- allow(subject.http_client).to receive(:get).
615
+ allow(api_client.http_client).to receive(:get).
602
616
  with('triggers/tags', an_instance_of(Hash)).
603
617
  and_return('TotalCount' => 1, 'Tags' => [{}])
604
- expect(subject.triggers(:tags).first(5).count).to eq(1)
618
+ expect(api_client.triggers(:tags).first(5).count).to eq(1)
605
619
  end
606
620
  end
607
621
 
@@ -617,7 +631,7 @@ describe Postmark::ApiClient do
617
631
 
618
632
  it 'requests server info from Postmark and converts it to ruby format' do
619
633
  expect(http_client).to receive(:get).with('server') {response}
620
- expect(subject.server_info).to have_key(:inbound_hash)
634
+ expect(api_client.server_info).to have_key(:inbound_hash)
621
635
  end
622
636
  end
623
637
 
@@ -634,7 +648,7 @@ describe Postmark::ApiClient do
634
648
 
635
649
  it 'updates server info in Postmark and converts it to ruby format' do
636
650
  expect(http_client).to receive(:put).with('server', anything) {response}
637
- expect(subject.update_server_info(update)[:smtp_api_activated]).to be false
651
+ expect(api_client.update_server_info(update)[:smtp_api_activated]).to be false
638
652
  end
639
653
  end
640
654
 
@@ -660,7 +674,7 @@ describe Postmark::ApiClient do
660
674
  it 'gets templates info and converts it to ruby format' do
661
675
  expect(http_client).to receive(:get).with('templates', :offset => 0, :count => 2).and_return(response)
662
676
 
663
- count, templates = subject.get_templates(:count => 2)
677
+ count, templates = api_client.get_templates(:count => 2)
664
678
 
665
679
  expect(count).to eq(31)
666
680
  expect(templates.first[:template_id]).to eq(123)
@@ -670,14 +684,14 @@ describe Postmark::ApiClient do
670
684
 
671
685
  describe '#templates' do
672
686
  it 'returns an Enumerator' do
673
- expect(subject.templates).to be_kind_of(Enumerable)
687
+ expect(api_client.templates).to be_kind_of(Enumerable)
674
688
  end
675
689
 
676
690
  it 'requests data at /templates' do
677
- allow(subject.http_client).to receive(:get).
691
+ allow(api_client.http_client).to receive(:get).
678
692
  with('templates', an_instance_of(Hash)).
679
693
  and_return('TotalCount' => 1, 'Templates' => [{}])
680
- expect(subject.templates.first(5).count).to eq(1)
694
+ expect(api_client.templates.first(5).count).to eq(1)
681
695
  end
682
696
  end
683
697
 
@@ -697,7 +711,7 @@ describe Postmark::ApiClient do
697
711
  it 'gets single template and converts it to ruby format' do
698
712
  expect(http_client).to receive(:get).with('templates/123').and_return(response)
699
713
 
700
- template = subject.get_template('123')
714
+ template = api_client.get_template('123')
701
715
 
702
716
  expect(template[:name]).to eq('Template Name')
703
717
  expect(template[:template_id]).to eq(123)
@@ -719,7 +733,7 @@ describe Postmark::ApiClient do
719
733
  with('templates', json_representation_of('Name' => 'template name')).
720
734
  and_return(response)
721
735
 
722
- template = subject.create_template(:name => 'template name')
736
+ template = api_client.create_template(:name => 'template name')
723
737
 
724
738
  expect(template[:name]).to eq('template name')
725
739
  expect(template[:template_id]).to eq(123)
@@ -740,7 +754,7 @@ describe Postmark::ApiClient do
740
754
  with('templates/123', json_representation_of('Name' => 'template name')).
741
755
  and_return(response)
742
756
 
743
- template = subject.update_template(123, :name => 'template name')
757
+ template = api_client.update_template(123, :name => 'template name')
744
758
 
745
759
  expect(template[:name]).to eq('template name')
746
760
  expect(template[:template_id]).to eq(123)
@@ -758,7 +772,7 @@ describe Postmark::ApiClient do
758
772
  it 'performs a DELETE request to /templates/:id' do
759
773
  expect(http_client).to receive(:delete).with('templates/123').and_return(response)
760
774
 
761
- resp = subject.delete_template(123)
775
+ resp = api_client.delete_template(123)
762
776
 
763
777
  expect(resp[:error_code]).to eq(0)
764
778
  end
@@ -798,9 +812,9 @@ describe Postmark::ApiClient do
798
812
  'Subject' => '{{MyName}}')).
799
813
  and_return(response)
800
814
 
801
- resp = subject.validate_template(:html_body => '{{MyName}}',
802
- :text_body => '{{MyName}}',
803
- :subject => '{{MyName}}')
815
+ resp = api_client.validate_template(:html_body => '{{MyName}}',
816
+ :text_body => '{{MyName}}',
817
+ :subject => '{{MyName}}')
804
818
 
805
819
  expect(resp[:all_content_is_valid]).to be true
806
820
  expect(resp[:html_body][:content_is_valid]).to be true
@@ -845,9 +859,9 @@ describe Postmark::ApiClient do
845
859
  'TextBody' => '{{MyName}}',
846
860
  'Subject' => '{{MyName}}')).and_return(response)
847
861
 
848
- resp = subject.validate_template(:html_body => '{{#each}}',
849
- :text_body => '{{MyName}}',
850
- :subject => '{{MyName}}')
862
+ resp = api_client.validate_template(:html_body => '{{#each}}',
863
+ :text_body => '{{MyName}}',
864
+ :subject => '{{MyName}}')
851
865
 
852
866
  expect(resp[:all_content_is_valid]).to be false
853
867
  expect(resp[:text_body][:content_is_valid]).to be true
@@ -859,26 +873,22 @@ describe Postmark::ApiClient do
859
873
  end
860
874
 
861
875
  describe "#deliver_with_template" do
876
+ subject {api_client.deliver_with_template(message_hash)}
877
+
862
878
  let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
863
879
  let(:response) {{"MessageID" => 42}}
864
880
 
865
881
  it 'converts message hash to Postmark format and posts it to /email/withTemplate' do
866
882
  expect(http_client).to receive(:post).with('email/withTemplate', json_representation_of(email)) {response}
867
- subject.deliver_with_template(message_hash)
868
- end
869
-
870
- it 'retries 3 times' do
871
- 2.times do
872
- expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError, 500)
873
- end
874
- expect(http_client).to receive(:post) {response}
875
- expect {subject.deliver_with_template(message_hash)}.not_to raise_error
883
+ subject
876
884
  end
877
885
 
878
886
  it 'converts response to ruby format' do
879
887
  expect(http_client).to receive(:post).with('email/withTemplate', json_representation_of(email)) {response}
880
- expect(subject.deliver_with_template(message_hash)).to have_key(:message_id)
888
+ expect(subject).to have_key(:message_id)
881
889
  end
890
+
891
+ it_should_behave_like "retryable"
882
892
  end
883
893
 
884
894
  describe '#deliver_in_batches_with_templates' do
@@ -905,7 +915,7 @@ describe Postmark::ApiClient do
905
915
  end
906
916
  end
907
917
 
908
- before {subject.max_batch_size = max_batch_size}
918
+ before {api_client.max_batch_size = max_batch_size}
909
919
 
910
920
  it 'performs a total of (bath_size / max_batch_size) requests' do
911
921
  expect(http_client).
@@ -923,7 +933,7 @@ describe Postmark::ApiClient do
923
933
  response
924
934
  end
925
935
 
926
- response = subject.deliver_in_batches_with_templates(message_hashes)
936
+ response = api_client.deliver_in_batches_with_templates(message_hashes)
927
937
  expect(response).to be_an Array
928
938
  expect(response.size).to eq message_hashes.size
929
939
 
@@ -946,7 +956,7 @@ describe Postmark::ApiClient do
946
956
 
947
957
  it 'converts response to ruby format' do
948
958
  expect(http_client).to receive(:get).with('stats/outbound', {:tag => 'foo'}) {response}
949
- response = subject.get_stats_totals(:tag => 'foo')
959
+ response = api_client.get_stats_totals(:tag => 'foo')
950
960
  expect(response).to have_key(:sent)
951
961
  expect(response).to have_key(:bounce_rate)
952
962
  end
@@ -979,7 +989,7 @@ describe Postmark::ApiClient do
979
989
 
980
990
  it 'converts response to ruby format' do
981
991
  expect(http_client).to receive(:get).with('stats/outbound/sends', {:tag => 'foo'}) {response}
982
- response = subject.get_stats_counts(:sends, :tag => 'foo')
992
+ response = api_client.get_stats_counts(:sends, :tag => 'foo')
983
993
  expect(response).to have_key(:days)
984
994
  expect(response).to have_key(:sent)
985
995
 
@@ -990,7 +1000,7 @@ describe Postmark::ApiClient do
990
1000
 
991
1001
  it 'uses fromdate that is passed in' do
992
1002
  expect(http_client).to receive(:get).with('stats/outbound/sends', {:tag => 'foo', :fromdate => '2015-01-01'}) {response}
993
- response = subject.get_stats_counts(:sends, :tag => 'foo', :fromdate => '2015-01-01')
1003
+ response = api_client.get_stats_counts(:sends, :tag => 'foo', :fromdate => '2015-01-01')
994
1004
  expect(response).to have_key(:days)
995
1005
  expect(response).to have_key(:sent)
996
1006
 
@@ -1001,7 +1011,7 @@ describe Postmark::ApiClient do
1001
1011
 
1002
1012
  it 'uses stats type that is passed in' do
1003
1013
  expect(http_client).to receive(:get).with('stats/outbound/opens/readtimes', {:tag => 'foo', :type => :readtimes}) {response}
1004
- response = subject.get_stats_counts(:opens, :type => :readtimes, :tag => 'foo')
1014
+ response = api_client.get_stats_counts(:opens, :type => :readtimes, :tag => 'foo')
1005
1015
  expect(response).to have_key(:days)
1006
1016
  expect(response).to have_key(:sent)
1007
1017
 
@@ -1209,7 +1219,7 @@ describe Postmark::ApiClient do
1209
1219
  let(:stream_id) { 'my-stream'}
1210
1220
  let(:server_id) { 123 }
1211
1221
  let(:api_endpoint) { "message-streams/#{stream_id}/unarchive" }
1212
- let(:api_response) {
1222
+ let(:api_response) {
1213
1223
  { 'ID' => stream_id, 'ServerID' => server_id, 'Name' => 'My Stream',
1214
1224
  'Description' => 'My test stream.', 'MessageStreamType' => 'Transactional',
1215
1225
  'CreatedAt' => '2030-08-30T12:30:00.00-04:00', 'UpdatedAt' => '2030-09-30T12:30:00.00-04:00',
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.21.8
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomek Maszkowski
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2021-07-29 00:00:00.000000000 Z
16
+ date: 2021-08-25 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: json