postmark 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +1 -1
- data/README.md +22 -3
- data/VERSION +1 -1
- data/lib/postmark/account_api_client.rb +96 -0
- data/lib/postmark/api_client.rb +25 -52
- data/lib/postmark/client.rb +82 -0
- data/lib/postmark/http_client.rb +7 -2
- data/lib/postmark/version.rb +1 -1
- data/lib/postmark.rb +2 -0
- data/spec/integration/account_api_client_spec.rb +78 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/postmark/account_api_client_spec.rb +538 -0
- data/spec/unit/postmark/api_client_spec.rb +84 -0
- data/spec/unit/postmark/bounce_spec.rb +1 -1
- data/spec/unit/postmark/client_spec.rb +52 -0
- data/spec/unit/postmark/message_extensions/mail_spec.rb +1 -1
- data/spec/unit/postmark_spec.rb +16 -16
- metadata +10 -2
@@ -0,0 +1,538 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Postmark::AccountApiClient do
|
4
|
+
|
5
|
+
let(:api_key) { 'abcd-efgh' }
|
6
|
+
subject { Postmark::AccountApiClient}
|
7
|
+
|
8
|
+
it 'can be created with an API key' do
|
9
|
+
expect { subject.new(api_key) }.not_to raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can be created with an API key and options hash' do
|
13
|
+
expect { subject.new(api_key, :http_read_timeout => 5) }.not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'instance' do
|
17
|
+
|
18
|
+
subject { Postmark::AccountApiClient.new(api_key) }
|
19
|
+
|
20
|
+
it 'uses the auth header specific for Account API' do
|
21
|
+
auth_header = subject.http_client.auth_header_name
|
22
|
+
expect(auth_header).to eq('X-Postmark-Account-Token')
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#senders' do
|
26
|
+
|
27
|
+
let(:response) {
|
28
|
+
{
|
29
|
+
'TotalCount' => 10, 'SenderSignatures' => [{}, {}]
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
it 'is aliased as #signatures' do
|
34
|
+
expect(subject).to respond_to(:signatures)
|
35
|
+
expect(subject).to respond_to(:signatures).with(1).argument
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns an enumerator' do
|
39
|
+
expect(subject.senders).to be_kind_of(Enumerable)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'lazily loads senders' do
|
43
|
+
allow(subject.http_client).to receive(:get).
|
44
|
+
with('senders', an_instance_of(Hash)).and_return(response)
|
45
|
+
subject.senders.take(1000)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#get_senders' do
|
51
|
+
|
52
|
+
let(:response) {
|
53
|
+
{
|
54
|
+
"TotalCount" => 1,
|
55
|
+
"SenderSignatures" => [{
|
56
|
+
"Domain" => "example.com",
|
57
|
+
"EmailAddress" => "someone@example.com",
|
58
|
+
"ReplyToEmailAddress" => "info@example.com",
|
59
|
+
"Name" => "Example User",
|
60
|
+
"Confirmed" => true,
|
61
|
+
"ID" => 8139
|
62
|
+
}]
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
it 'is aliased as #get_signatures' do
|
67
|
+
expect(subject).to respond_to(:get_signatures).with(1).argument
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'performs a GET request to /senders endpoint' do
|
71
|
+
allow(subject.http_client).to receive(:get).
|
72
|
+
with('senders', :offset => 0, :count => 30).
|
73
|
+
and_return(response)
|
74
|
+
subject.get_senders
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'formats the keys of returned list of senders' do
|
78
|
+
allow(subject.http_client).to receive(:get).and_return(response)
|
79
|
+
keys = subject.get_senders.map { |s| s.keys }.flatten
|
80
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'accepts offset and count options' do
|
84
|
+
allow(subject.http_client).to receive(:get).
|
85
|
+
with('senders', :offset => 10, :count => 42).
|
86
|
+
and_return(response)
|
87
|
+
subject.get_senders(:offset => 10, :count => 42)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#get_senders_count' do
|
93
|
+
|
94
|
+
let(:response) { {'TotalCount' => 42} }
|
95
|
+
|
96
|
+
it 'is aliased as #get_signatures_count' do
|
97
|
+
expect(subject).to respond_to(:get_signatures_count)
|
98
|
+
expect(subject).to respond_to(:get_signatures_count).with(1).argument
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'returns a total number of senders' do
|
102
|
+
allow(subject.http_client).to receive(:get).
|
103
|
+
with('senders', an_instance_of(Hash)).and_return(response)
|
104
|
+
expect(subject.get_senders_count).to eq(42)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#get_sender' do
|
110
|
+
|
111
|
+
let(:response) {
|
112
|
+
{
|
113
|
+
"Domain" => "example.com",
|
114
|
+
"EmailAddress" => "someone@example.com",
|
115
|
+
"ReplyToEmailAddress" => "info@example.com",
|
116
|
+
"Name" => "Example User",
|
117
|
+
"Confirmed" => true,
|
118
|
+
"ID" => 8139
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
it 'is aliased as #get_signature' do
|
123
|
+
expect(subject).to respond_to(:get_signature).with(1).argument
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'performs a GET request to /senders/:id endpoint' do
|
127
|
+
allow(subject.http_client).to receive(:get).with("senders/42").
|
128
|
+
and_return(response)
|
129
|
+
subject.get_sender(42)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'formats the keys of returned response' do
|
133
|
+
allow(subject.http_client).to receive(:get).and_return(response)
|
134
|
+
keys = subject.get_sender(42).keys
|
135
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#create_sender' do
|
140
|
+
|
141
|
+
let(:response) {
|
142
|
+
{
|
143
|
+
"Domain" => "example.com",
|
144
|
+
"EmailAddress" => "someone@example.com",
|
145
|
+
"ReplyToEmailAddress" => "info@example.com",
|
146
|
+
"Name" => "Example User",
|
147
|
+
"Confirmed" => true,
|
148
|
+
"ID" => 8139
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
it 'is aliased as #create_signature' do
|
153
|
+
expect(subject).to respond_to(:create_signature).with(1).argument
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'performs a POST request to /senders endpoint' do
|
157
|
+
allow(subject.http_client).to receive(:post).
|
158
|
+
with("senders", an_instance_of(String)).and_return(response)
|
159
|
+
subject.create_sender(:name => 'Chris Nagele')
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'converts the sender attributes names to camel case' do
|
163
|
+
allow(subject.http_client).to receive(:post).
|
164
|
+
with("senders", {'FooBar' => 'bar'}.to_json).and_return(response)
|
165
|
+
subject.create_sender(:foo_bar => 'bar')
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'formats the keys of returned response' do
|
169
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
170
|
+
keys = subject.create_sender(:foo => 'bar').keys
|
171
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe '#update_sender' do
|
176
|
+
|
177
|
+
let(:response) {
|
178
|
+
{
|
179
|
+
"Domain" => "example.com",
|
180
|
+
"EmailAddress" => "someone@example.com",
|
181
|
+
"ReplyToEmailAddress" => "info@example.com",
|
182
|
+
"Name" => "Example User",
|
183
|
+
"Confirmed" => true,
|
184
|
+
"ID" => 8139
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
it 'is aliased as #update_signature' do
|
189
|
+
expect(subject).to respond_to(:update_signature).with(1).argument
|
190
|
+
expect(subject).to respond_to(:update_signature).with(2).arguments
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'performs a PUT request to /senders/:id endpoint' do
|
194
|
+
allow(subject.http_client).to receive(:put).
|
195
|
+
with('senders/42', an_instance_of(String)).and_return(response)
|
196
|
+
subject.update_sender(42, :name => 'Chris Nagele')
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'converts the sender attributes names to camel case' do
|
200
|
+
allow(subject.http_client).to receive(:put).
|
201
|
+
with('senders/42', {'FooBar' => 'bar'}.to_json).and_return(response)
|
202
|
+
subject.update_sender(42, :foo_bar => 'bar')
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'formats the keys of returned response' do
|
206
|
+
allow(subject.http_client).to receive(:put).and_return(response)
|
207
|
+
keys = subject.update_sender(42, :foo => 'bar').keys
|
208
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#resend_sender_confirmation' do
|
214
|
+
|
215
|
+
let(:response) {
|
216
|
+
{
|
217
|
+
"ErrorCode" => 0,
|
218
|
+
"Message" => "Confirmation email for Sender Signature someone@example.com was re-sent."
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
it 'is aliased as #resend_signature_confirmation' do
|
223
|
+
expect(subject).to respond_to(:resend_signature_confirmation).
|
224
|
+
with(1).argument
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'performs a POST request to /senders/:id/resend endpoint' do
|
228
|
+
allow(subject.http_client).to receive(:post).
|
229
|
+
with('senders/42/resend').and_return(response)
|
230
|
+
subject.resend_sender_confirmation(42)
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'formats the keys of returned response' do
|
234
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
235
|
+
keys = subject.resend_sender_confirmation(42).keys
|
236
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
describe '#verified_sender_spf?' do
|
242
|
+
|
243
|
+
let(:response) { {"SPFVerified" => true} }
|
244
|
+
let(:false_response) { {"SPFVerified" => false} }
|
245
|
+
|
246
|
+
it 'is aliased as #verified_signature_spf?' do
|
247
|
+
expect(subject).to respond_to(:verified_signature_spf?).with(1).argument
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'performs a POST request to /senders/:id/verifyspf endpoint' do
|
251
|
+
allow(subject.http_client).to receive(:post).
|
252
|
+
with('senders/42/verifyspf').and_return(response)
|
253
|
+
subject.verified_sender_spf?(42)
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'returns false when SPFVerified field of the response is false' do
|
257
|
+
allow(subject.http_client).to receive(:post).and_return(false_response)
|
258
|
+
expect(subject.verified_sender_spf?(42)).to be_false
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'returns true when SPFVerified field of the response is true' do
|
262
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
263
|
+
expect(subject.verified_sender_spf?(42)).to be_true
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
describe '#request_new_sender_dkim' do
|
269
|
+
|
270
|
+
let(:response) {
|
271
|
+
{
|
272
|
+
"Domain" => "example.com",
|
273
|
+
"EmailAddress" => "someone@example.com",
|
274
|
+
"ReplyToEmailAddress" => "info@example.com",
|
275
|
+
"Name" => "Example User",
|
276
|
+
"Confirmed" => true,
|
277
|
+
"ID" => 8139
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
it 'is aliased as #request_new_signature_dkim' do
|
282
|
+
expect(subject).to respond_to(:request_new_signature_dkim).
|
283
|
+
with(1).argument
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'performs a POST request to /senders/:id/requestnewdkim endpoint' do
|
287
|
+
allow(subject.http_client).to receive(:post).
|
288
|
+
with('senders/42/requestnewdkim').and_return(response)
|
289
|
+
subject.request_new_sender_dkim(42)
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'formats the keys of returned response' do
|
293
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
294
|
+
keys = subject.request_new_sender_dkim(42).keys
|
295
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
describe '#delete_sender' do
|
301
|
+
|
302
|
+
let(:response) {
|
303
|
+
{
|
304
|
+
"ErrorCode" => 0,
|
305
|
+
"Message" => "Signature someone@example.com removed."
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
it 'is aliased as #delete_signature' do
|
310
|
+
expect(subject).to respond_to(:delete_signature).with(1).argument
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'performs a DELETE request to /senders/:id endpoint' do
|
314
|
+
allow(subject.http_client).to receive(:delete).
|
315
|
+
with('senders/42').and_return(response)
|
316
|
+
subject.delete_sender(42)
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'formats the keys of returned response' do
|
320
|
+
allow(subject.http_client).to receive(:delete).and_return(response)
|
321
|
+
keys = subject.delete_sender(42).keys
|
322
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
describe '#servers' do
|
328
|
+
|
329
|
+
let(:response) { {'TotalCount' => 10, 'Servers' => [{}, {}]} }
|
330
|
+
|
331
|
+
it 'returns an enumerator' do
|
332
|
+
expect(subject.servers).to be_kind_of(Enumerable)
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'lazily loads servers' do
|
336
|
+
allow(subject.http_client).to receive(:get).
|
337
|
+
with('servers', an_instance_of(Hash)).and_return(response)
|
338
|
+
subject.servers.take(100)
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
describe '#get_servers' do
|
344
|
+
|
345
|
+
let(:response) {
|
346
|
+
{
|
347
|
+
'TotalCount' => 1,
|
348
|
+
'Servers' => [
|
349
|
+
{
|
350
|
+
"ID" => 11635,
|
351
|
+
"Name" => "Production01",
|
352
|
+
"ApiTokens" => [
|
353
|
+
"fe6ec0cf-ff06-787a-b5e9-e77a41c61ce3"
|
354
|
+
],
|
355
|
+
"ServerLink" => "https://postmarkapp.com/servers/11635/overview",
|
356
|
+
"Color" => "red",
|
357
|
+
"SmtpApiActivated" => true,
|
358
|
+
"RawEmailEnabled" => false,
|
359
|
+
"InboundAddress" => "7373de3ebd66acea228fjkdkf88dd7d5@inbound.postmarkapp.com",
|
360
|
+
"InboundHookUrl" => "http://inboundhook.example.com/inbound",
|
361
|
+
"BounceHookUrl" => "http://bouncehook.example.com/bounce",
|
362
|
+
"InboundDomain" => "",
|
363
|
+
"InboundHash" => "7373de3ebd66acea228fjkdkf88dd7d5"
|
364
|
+
}
|
365
|
+
]
|
366
|
+
}
|
367
|
+
}
|
368
|
+
|
369
|
+
it 'performs a GET request to /servers endpoint' do
|
370
|
+
allow(subject.http_client).to receive(:get).
|
371
|
+
with('servers', an_instance_of(Hash)).and_return(response)
|
372
|
+
subject.get_servers
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'formats the keys of returned list of servers' do
|
376
|
+
allow(subject.http_client).to receive(:get).and_return(response)
|
377
|
+
keys = subject.get_servers.map { |s| s.keys }.flatten
|
378
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'accepts offset and count options' do
|
382
|
+
allow(subject.http_client).to receive(:get).
|
383
|
+
with('servers', :offset => 30, :count => 50).
|
384
|
+
and_return(response)
|
385
|
+
subject.get_servers(:offset => 30, :count => 50)
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
describe '#get_server' do
|
390
|
+
|
391
|
+
let(:response) {
|
392
|
+
{
|
393
|
+
"ID" => 7438,
|
394
|
+
"Name" => "Staging Testing",
|
395
|
+
"ApiTokens" => [
|
396
|
+
"fe6ec0cf-ff06-44aa-jf88-e77a41c61ce3"
|
397
|
+
],
|
398
|
+
"ServerLink" => "https://postmarkapp.com/servers/7438/overview",
|
399
|
+
"Color" => "red",
|
400
|
+
"SmtpApiActivated" => true,
|
401
|
+
"RawEmailEnabled" => false,
|
402
|
+
"InboundAddress" => "7373de3ebd66acea22812731fb1dd7d5@inbound.postmarkapp.com",
|
403
|
+
"InboundHookUrl" => "",
|
404
|
+
"BounceHookUrl" => "",
|
405
|
+
"InboundDomain" => "",
|
406
|
+
"InboundHash" => "7373de3ebd66acea22812731fb1dd7d5"
|
407
|
+
}
|
408
|
+
}
|
409
|
+
|
410
|
+
it 'performs a GET request to /servers/:id endpoint' do
|
411
|
+
allow(subject.http_client).to receive(:get).
|
412
|
+
with('servers/42').and_return(response)
|
413
|
+
subject.get_server(42)
|
414
|
+
end
|
415
|
+
|
416
|
+
it 'formats the keys of returned response' do
|
417
|
+
allow(subject.http_client).to receive(:get).and_return(response)
|
418
|
+
keys = subject.get_server(42).keys
|
419
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
420
|
+
end
|
421
|
+
|
422
|
+
end
|
423
|
+
|
424
|
+
describe '#get_servers_count' do
|
425
|
+
|
426
|
+
let(:response) { {'TotalCount' => 42} }
|
427
|
+
|
428
|
+
it 'returns a total number of servers' do
|
429
|
+
allow(subject.http_client).to receive(:get).
|
430
|
+
with('servers', an_instance_of(Hash)).and_return(response)
|
431
|
+
expect(subject.get_servers_count).to eq(42)
|
432
|
+
end
|
433
|
+
|
434
|
+
end
|
435
|
+
|
436
|
+
describe '#create_server' do
|
437
|
+
|
438
|
+
let(:response) {
|
439
|
+
{
|
440
|
+
"Name" => "Staging Testing",
|
441
|
+
"Color" => "red",
|
442
|
+
"SmtpApiActivated" => true,
|
443
|
+
"RawEmailEnabled" => false,
|
444
|
+
"InboundHookUrl" => "http://hooks.example.com/inbound",
|
445
|
+
"BounceHookUrl" => "http://hooks.example.com/bounce",
|
446
|
+
"InboundDomain" => ""
|
447
|
+
}
|
448
|
+
}
|
449
|
+
|
450
|
+
it 'performs a POST request to /servers endpoint' do
|
451
|
+
allow(subject.http_client).to receive(:post).
|
452
|
+
with('servers', an_instance_of(String)).and_return(response)
|
453
|
+
subject.create_server(:foo => 'bar')
|
454
|
+
end
|
455
|
+
|
456
|
+
it 'converts the server attribute names to camel case' do
|
457
|
+
allow(subject.http_client).to receive(:post).
|
458
|
+
with('servers', {'FooBar' => 'foo_bar'}.to_json).
|
459
|
+
and_return(response)
|
460
|
+
subject.create_server(:foo_bar => 'foo_bar')
|
461
|
+
end
|
462
|
+
|
463
|
+
it 'formats the keys of returned response' do
|
464
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
465
|
+
keys = subject.create_server(:foo => 'bar').keys
|
466
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
467
|
+
end
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
describe '#update_server' do
|
472
|
+
let(:response) {
|
473
|
+
{
|
474
|
+
"ID" => 7450,
|
475
|
+
"Name" => "Production Testing",
|
476
|
+
"ApiTokens" => [
|
477
|
+
"fe6ec0cf-ff06-44aa-jf88-e77a41c61ce3"
|
478
|
+
],
|
479
|
+
"ServerLink" => "https://postmarkapp.com/servers/7438/overview",
|
480
|
+
"Color" => "blue",
|
481
|
+
"SmtpApiActivated" => false,
|
482
|
+
"RawEmailEnabled" => false,
|
483
|
+
"InboundAddress" => "7373de3ebd66acea22812731fb1dd7d5@inbound.postmarkapp.com",
|
484
|
+
"InboundHookUrl" => "http://hooks.example.com/inbound",
|
485
|
+
"BounceHookUrl" => "http://hooks.example.com/bounce",
|
486
|
+
"InboundDomain" => "",
|
487
|
+
"InboundHash" => "7373de3ebd66acea22812731fb1dd7d5"
|
488
|
+
}
|
489
|
+
}
|
490
|
+
|
491
|
+
it 'converts the server attribute names to camel case' do
|
492
|
+
allow(subject.http_client).to receive(:put).
|
493
|
+
with(an_instance_of(String), {'FooBar' => 'foo_bar'}.to_json).
|
494
|
+
and_return(response)
|
495
|
+
subject.update_server(42, :foo_bar => 'foo_bar')
|
496
|
+
end
|
497
|
+
|
498
|
+
it 'performs a PUT request to /servers/:id endpoint' do
|
499
|
+
allow(subject.http_client).to receive(:put).
|
500
|
+
with('servers/42', an_instance_of(String)).
|
501
|
+
and_return(response)
|
502
|
+
subject.update_server(42, :foo => 'bar')
|
503
|
+
end
|
504
|
+
|
505
|
+
it 'formats the keys of returned response' do
|
506
|
+
allow(subject.http_client).to receive(:put).and_return(response)
|
507
|
+
keys = subject.update_server(42, :foo => 'bar').keys
|
508
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
509
|
+
end
|
510
|
+
|
511
|
+
end
|
512
|
+
|
513
|
+
describe '#delete_server' do
|
514
|
+
|
515
|
+
let(:response) {
|
516
|
+
{
|
517
|
+
"ErrorCode" => "0",
|
518
|
+
"Message" => "Server Production Testing removed."
|
519
|
+
}
|
520
|
+
}
|
521
|
+
|
522
|
+
it 'performs a DELETE request to /servers/:id endpoint' do
|
523
|
+
allow(subject.http_client).to receive(:delete).
|
524
|
+
with('servers/42').and_return(response)
|
525
|
+
subject.delete_server(42)
|
526
|
+
end
|
527
|
+
|
528
|
+
it 'formats the keys of returned response' do
|
529
|
+
allow(subject.http_client).to receive(:delete).and_return(response)
|
530
|
+
keys = subject.delete_server(42).keys
|
531
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be_true
|
532
|
+
end
|
533
|
+
|
534
|
+
end
|
535
|
+
|
536
|
+
end
|
537
|
+
|
538
|
+
end
|
@@ -170,6 +170,48 @@ describe Postmark::ApiClient do
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
+
describe '#messages' do
|
174
|
+
|
175
|
+
context 'given outbound' do
|
176
|
+
|
177
|
+
let(:response) {
|
178
|
+
{'TotalCount' => 5,
|
179
|
+
'Messages' => [{}].cycle(5).to_a}
|
180
|
+
}
|
181
|
+
|
182
|
+
it 'returns an enumerator' do
|
183
|
+
expect(subject.messages).to be_kind_of(Enumerable)
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'loads outbound messages' do
|
187
|
+
allow(subject.http_client).to receive(:get).
|
188
|
+
with('messages/outbound', an_instance_of(Hash)).and_return(response)
|
189
|
+
expect(subject.messages.count).to eq(5)
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'given inbound' do
|
195
|
+
|
196
|
+
let(:response) {
|
197
|
+
{'TotalCount' => 5,
|
198
|
+
'InboundMessages' => [{}].cycle(5).to_a}
|
199
|
+
}
|
200
|
+
|
201
|
+
it 'returns an enumerator' do
|
202
|
+
expect(subject.messages(:inbound => true)).to be_kind_of(Enumerable)
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'loads inbound messages' do
|
206
|
+
allow(subject.http_client).to receive(:get).
|
207
|
+
with('messages/inbound', an_instance_of(Hash)).and_return(response)
|
208
|
+
expect(subject.messages(:inbound => true).count).to eq(5)
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
173
215
|
describe '#get_messages' do
|
174
216
|
let(:http_client) { subject.http_client }
|
175
217
|
|
@@ -199,6 +241,33 @@ describe Postmark::ApiClient do
|
|
199
241
|
end
|
200
242
|
end
|
201
243
|
|
244
|
+
describe '#get_messages_count' do
|
245
|
+
|
246
|
+
let(:response) { {'TotalCount' => 42} }
|
247
|
+
|
248
|
+
context 'given outbound' do
|
249
|
+
|
250
|
+
it 'requests and returns outbound messages count' do
|
251
|
+
allow(subject.http_client).to receive(:get).
|
252
|
+
with('messages/outbound', an_instance_of(Hash)).and_return(response)
|
253
|
+
expect(subject.get_messages_count).to eq(42)
|
254
|
+
expect(subject.get_messages_count(:inbound => false)).to eq(42)
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'given inbound' do
|
260
|
+
|
261
|
+
it 'requests and returns inbound messages count' do
|
262
|
+
allow(subject.http_client).to receive(:get).
|
263
|
+
with('messages/inbound', an_instance_of(Hash)).and_return(response)
|
264
|
+
expect(subject.get_messages_count(:inbound => true)).to eq(42)
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
202
271
|
describe '#get_message' do
|
203
272
|
let(:id) { '8ad0e8b0-xxxx-xxxx-951d-223c581bb467' }
|
204
273
|
let(:http_client) { subject.http_client }
|
@@ -255,6 +324,21 @@ describe Postmark::ApiClient do
|
|
255
324
|
end
|
256
325
|
end
|
257
326
|
|
327
|
+
describe '#bounces' do
|
328
|
+
|
329
|
+
it 'returns an Enumerator' do
|
330
|
+
expect(subject.bounces).to be_kind_of(Enumerable)
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'requests data at /bounces' do
|
334
|
+
allow(subject.http_client).to receive(:get).
|
335
|
+
with('bounces', an_instance_of(Hash)).
|
336
|
+
and_return('TotalCount' => 1, 'Bounces' => [{}])
|
337
|
+
expect(subject.bounces.first(5).count).to eq(1)
|
338
|
+
end
|
339
|
+
|
340
|
+
end
|
341
|
+
|
258
342
|
describe "#get_bounces" do
|
259
343
|
let(:http_client) { subject.http_client }
|
260
344
|
let(:options) { {:foo => :bar} }
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Postmark::Client do
|
4
|
+
|
5
|
+
subject { Postmark::Client.new('abcd-efgh') }
|
6
|
+
|
7
|
+
describe 'instance' do
|
8
|
+
|
9
|
+
describe '#find_each' do
|
10
|
+
|
11
|
+
let(:path) { 'resources' }
|
12
|
+
let(:name) { 'Resources' }
|
13
|
+
let(:response) {
|
14
|
+
{
|
15
|
+
'TotalCount' => 10,
|
16
|
+
name => [{'Foo' => 'bar'}, {'Bar' => 'foo'}]
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
it 'returns an enumerator' do
|
21
|
+
expect(subject.find_each(path, name)).to be_kind_of(Enumerable)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'can be iterated' do
|
25
|
+
collection = [{:foo => 'bar'}, {:bar => 'foo'}].cycle(5)
|
26
|
+
allow(subject.http_client).
|
27
|
+
to receive(:get).with(path, an_instance_of(Hash)).
|
28
|
+
exactly(5).times.and_return(response)
|
29
|
+
expect { |b| subject.find_each(path, name, :count => 2).each(&b) }.
|
30
|
+
to yield_successive_args(*collection)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Only Ruby >= 2.0.0 supports Enumerator#size
|
34
|
+
it 'lazily calculates the collection size',
|
35
|
+
:skip_ruby_version => ['1.8.7', '1.9'] do
|
36
|
+
allow(subject.http_client).
|
37
|
+
to receive(:get).exactly(1).times.and_return(response)
|
38
|
+
collection = subject.find_each(path, name, :count => 2)
|
39
|
+
expect(collection.size).to eq(10)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'iterates over the collection to count it' do
|
43
|
+
allow(subject.http_client).
|
44
|
+
to receive(:get).exactly(5).times.and_return(response)
|
45
|
+
expect(subject.find_each(path, name, :count => 2).count).to eq(10)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|