postmark 1.10.0 → 1.11.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/CHANGELOG.rdoc +7 -0
- data/CONTRIBUTING.md +18 -0
- data/Gemfile +6 -5
- data/LICENSE +1 -1
- data/README.md +62 -9
- data/VERSION +1 -1
- data/gemfiles/Gemfile.legacy +4 -3
- data/lib/postmark.rb +1 -18
- data/lib/postmark/api_client.rb +32 -1
- data/lib/postmark/client.rb +8 -4
- data/lib/postmark/error.rb +117 -0
- data/lib/postmark/http_client.rb +7 -25
- data/lib/postmark/mail_message_converter.rb +1 -1
- data/lib/postmark/version.rb +1 -1
- data/spec/integration/account_api_client_spec.rb +2 -2
- data/spec/integration/api_client_messages_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -1
- data/spec/support/custom_matchers.rb +30 -0
- data/spec/unit/postmark/account_api_client_spec.rb +22 -22
- data/spec/unit/postmark/api_client_spec.rb +164 -54
- data/spec/unit/postmark/bounce_spec.rb +10 -10
- data/spec/unit/postmark/error_spec.rb +218 -0
- data/spec/unit/postmark/handlers/mail_spec.rb +5 -5
- data/spec/unit/postmark/http_client_spec.rb +4 -5
- data/spec/unit/postmark/mail_message_converter_spec.rb +6 -0
- data/spec/unit/postmark/message_extensions/mail_spec.rb +6 -6
- data/spec/unit/postmark_spec.rb +5 -5
- metadata +33 -4
@@ -31,7 +31,7 @@ module Postmark
|
|
31
31
|
'Headers' => @message.export_headers,
|
32
32
|
'Tag' => @message.tag.to_s,
|
33
33
|
'TrackOpens' => (cast_to_bool(@message.track_opens) unless @message.track_opens.empty?),
|
34
|
-
'TrackLinks' => (@message.track_links unless @message.track_links.empty?)
|
34
|
+
'TrackLinks' => (::Postmark::Inflector.to_postmark(@message.track_links) unless @message.track_links.empty?)
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
data/lib/postmark/version.rb
CHANGED
@@ -33,7 +33,7 @@ describe 'Account API client usage' do
|
|
33
33
|
|
34
34
|
|
35
35
|
# spf
|
36
|
-
expect(subject.verified_sender_spf?(new_sender[:id])).to
|
36
|
+
expect(subject.verified_sender_spf?(new_sender[:id])).to be true
|
37
37
|
|
38
38
|
# resend
|
39
39
|
expect { subject.resend_sender_confirmation(new_sender[:id]) }.not_to raise_error
|
@@ -74,7 +74,7 @@ describe 'Account API client usage' do
|
|
74
74
|
expect(updated_domain[:id]).to eq(new_domain[:id])
|
75
75
|
|
76
76
|
# spf
|
77
|
-
expect(subject.verified_domain_spf?(new_domain[:id])).to
|
77
|
+
expect(subject.verified_domain_spf?(new_domain[:id])).to be true
|
78
78
|
|
79
79
|
# dkim
|
80
80
|
expect { subject.rotate_domain_dkim(new_domain[:id]) }.
|
@@ -91,14 +91,14 @@ describe "Sending Mail::Messages with Postmark::ApiClient" do
|
|
91
91
|
api_client.deliver_messages(valid_messages)
|
92
92
|
|
93
93
|
expect(valid_messages.all? { |m| m.message_id =~ postmark_message_id_format }).
|
94
|
-
to
|
94
|
+
to be true
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'updates delivered messages with related Postmark responses' do
|
98
98
|
api_client.deliver_messages(valid_messages)
|
99
99
|
|
100
100
|
expect(valid_messages.all? { |m| m.postmark_response["To"] == m.to[0] }).
|
101
|
-
to
|
101
|
+
to be true
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'returns as many responses as many messages were sent' do
|
@@ -114,7 +114,7 @@ describe "Sending Mail::Messages with Postmark::ApiClient" do
|
|
114
114
|
api_client.deliver_messages(valid_messages)
|
115
115
|
|
116
116
|
expect(valid_messages.all? { |m| m.postmark_response["To"] == m.to[0] }).
|
117
|
-
to
|
117
|
+
to be true
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'returns as many responses as many messages were sent' do
|
data/spec/spec_helper.rb
CHANGED
@@ -10,8 +10,9 @@ require 'json'
|
|
10
10
|
require 'fakeweb'
|
11
11
|
require 'fakeweb_matcher'
|
12
12
|
require 'rspec'
|
13
|
-
require 'rspec/
|
13
|
+
require 'rspec/its'
|
14
14
|
require File.join(File.expand_path(File.dirname(__FILE__)), 'support', 'shared_examples.rb')
|
15
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'support', 'custom_matchers.rb')
|
15
16
|
require File.join(File.expand_path(File.dirname(__FILE__)), 'support', 'helpers.rb')
|
16
17
|
|
17
18
|
if ENV['JSONGEM']
|
@@ -23,6 +24,8 @@ end
|
|
23
24
|
RSpec.configure do |config|
|
24
25
|
include Postmark::RSpecHelpers
|
25
26
|
|
27
|
+
config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
|
28
|
+
|
26
29
|
config.filter_run_excluding :skip_for_platform => lambda { |platform|
|
27
30
|
RUBY_PLATFORM.to_s =~ /^#{platform.to_s}/
|
28
31
|
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
RSpec::Matchers.define :a_postmark_json do |string|
|
2
|
+
def postmark_key?(key)
|
3
|
+
key == ::Postmark::Inflector.to_postmark(key)
|
4
|
+
end
|
5
|
+
|
6
|
+
def postmark_object?(obj)
|
7
|
+
case obj
|
8
|
+
when Hash
|
9
|
+
return false unless obj.keys.all? { |k| postmark_key?(k) }
|
10
|
+
return false unless obj.values.all? { |v| postmark_object?(v) }
|
11
|
+
when Array
|
12
|
+
return false unless obj.all? { |v| postmark_object?(v) }
|
13
|
+
end
|
14
|
+
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def postmark_json?(str)
|
19
|
+
return false unless str.is_a?(String)
|
20
|
+
|
21
|
+
json = Postmark::Json.decode(str)
|
22
|
+
postmark_object?(json)
|
23
|
+
rescue
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
match do |actual|
|
28
|
+
postmark_json?(actual)
|
29
|
+
end
|
30
|
+
end
|
@@ -77,7 +77,7 @@ describe Postmark::AccountApiClient do
|
|
77
77
|
it 'formats the keys of returned list of senders' do
|
78
78
|
allow(subject.http_client).to receive(:get).and_return(response)
|
79
79
|
keys = subject.get_senders.map { |s| s.keys }.flatten
|
80
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
80
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'accepts offset and count options' do
|
@@ -132,7 +132,7 @@ describe Postmark::AccountApiClient do
|
|
132
132
|
it 'formats the keys of returned response' do
|
133
133
|
allow(subject.http_client).to receive(:get).and_return(response)
|
134
134
|
keys = subject.get_sender(42).keys
|
135
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
135
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -168,7 +168,7 @@ describe Postmark::AccountApiClient do
|
|
168
168
|
it 'formats the keys of returned response' do
|
169
169
|
allow(subject.http_client).to receive(:post).and_return(response)
|
170
170
|
keys = subject.create_sender(:foo => 'bar').keys
|
171
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
171
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -205,7 +205,7 @@ describe Postmark::AccountApiClient do
|
|
205
205
|
it 'formats the keys of returned response' do
|
206
206
|
allow(subject.http_client).to receive(:put).and_return(response)
|
207
207
|
keys = subject.update_sender(42, :foo => 'bar').keys
|
208
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
208
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
209
209
|
end
|
210
210
|
|
211
211
|
end
|
@@ -233,7 +233,7 @@ describe Postmark::AccountApiClient do
|
|
233
233
|
it 'formats the keys of returned response' do
|
234
234
|
allow(subject.http_client).to receive(:post).and_return(response)
|
235
235
|
keys = subject.resend_sender_confirmation(42).keys
|
236
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
236
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
237
237
|
end
|
238
238
|
|
239
239
|
end
|
@@ -255,12 +255,12 @@ describe Postmark::AccountApiClient do
|
|
255
255
|
|
256
256
|
it 'returns false when SPFVerified field of the response is false' do
|
257
257
|
allow(subject.http_client).to receive(:post).and_return(false_response)
|
258
|
-
expect(subject.verified_sender_spf?(42)).to
|
258
|
+
expect(subject.verified_sender_spf?(42)).to be false
|
259
259
|
end
|
260
260
|
|
261
261
|
it 'returns true when SPFVerified field of the response is true' do
|
262
262
|
allow(subject.http_client).to receive(:post).and_return(response)
|
263
|
-
expect(subject.verified_sender_spf?(42)).to
|
263
|
+
expect(subject.verified_sender_spf?(42)).to be true
|
264
264
|
end
|
265
265
|
|
266
266
|
end
|
@@ -292,7 +292,7 @@ describe Postmark::AccountApiClient do
|
|
292
292
|
it 'formats the keys of returned response' do
|
293
293
|
allow(subject.http_client).to receive(:post).and_return(response)
|
294
294
|
keys = subject.request_new_sender_dkim(42).keys
|
295
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
295
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
296
296
|
end
|
297
297
|
|
298
298
|
end
|
@@ -319,7 +319,7 @@ describe Postmark::AccountApiClient do
|
|
319
319
|
it 'formats the keys of returned response' do
|
320
320
|
allow(subject.http_client).to receive(:delete).and_return(response)
|
321
321
|
keys = subject.delete_sender(42).keys
|
322
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
322
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
323
323
|
end
|
324
324
|
|
325
325
|
end
|
@@ -366,7 +366,7 @@ describe Postmark::AccountApiClient do
|
|
366
366
|
it 'formats the keys of returned list of domains' do
|
367
367
|
allow(subject.http_client).to receive(:get).and_return(response)
|
368
368
|
keys = subject.get_domains.map { |s| s.keys }.flatten
|
369
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
369
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
370
370
|
end
|
371
371
|
|
372
372
|
it 'accepts offset and count options' do
|
@@ -408,7 +408,7 @@ describe Postmark::AccountApiClient do
|
|
408
408
|
it 'formats the keys of returned response' do
|
409
409
|
allow(subject.http_client).to receive(:get).and_return(response)
|
410
410
|
keys = subject.get_domain(42).keys
|
411
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
411
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
@@ -436,7 +436,7 @@ describe Postmark::AccountApiClient do
|
|
436
436
|
it 'formats the keys of returned response' do
|
437
437
|
allow(subject.http_client).to receive(:post).and_return(response)
|
438
438
|
keys = subject.create_domain(:foo => 'bar').keys
|
439
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
439
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
440
440
|
end
|
441
441
|
end
|
442
442
|
|
@@ -465,7 +465,7 @@ describe Postmark::AccountApiClient do
|
|
465
465
|
it 'formats the keys of returned response' do
|
466
466
|
allow(subject.http_client).to receive(:put).and_return(response)
|
467
467
|
keys = subject.update_domain(42, :foo => 'bar').keys
|
468
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
468
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
469
469
|
end
|
470
470
|
|
471
471
|
end
|
@@ -483,12 +483,12 @@ describe Postmark::AccountApiClient do
|
|
483
483
|
|
484
484
|
it 'returns false when SPFVerified field of the response is false' do
|
485
485
|
allow(subject.http_client).to receive(:post).and_return(false_response)
|
486
|
-
expect(subject.verified_domain_spf?(42)).to
|
486
|
+
expect(subject.verified_domain_spf?(42)).to be false
|
487
487
|
end
|
488
488
|
|
489
489
|
it 'returns true when SPFVerified field of the response is true' do
|
490
490
|
allow(subject.http_client).to receive(:post).and_return(response)
|
491
|
-
expect(subject.verified_domain_spf?(42)).to
|
491
|
+
expect(subject.verified_domain_spf?(42)).to be true
|
492
492
|
end
|
493
493
|
|
494
494
|
end
|
@@ -511,7 +511,7 @@ describe Postmark::AccountApiClient do
|
|
511
511
|
it 'formats the keys of returned response' do
|
512
512
|
allow(subject.http_client).to receive(:post).and_return(response)
|
513
513
|
keys = subject.rotate_domain_dkim(42).keys
|
514
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
514
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
515
515
|
end
|
516
516
|
|
517
517
|
end
|
@@ -534,7 +534,7 @@ describe Postmark::AccountApiClient do
|
|
534
534
|
it 'formats the keys of returned response' do
|
535
535
|
allow(subject.http_client).to receive(:delete).and_return(response)
|
536
536
|
keys = subject.delete_sender(42).keys
|
537
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
537
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
538
538
|
end
|
539
539
|
|
540
540
|
end
|
@@ -590,7 +590,7 @@ describe Postmark::AccountApiClient do
|
|
590
590
|
it 'formats the keys of returned list of servers' do
|
591
591
|
allow(subject.http_client).to receive(:get).and_return(response)
|
592
592
|
keys = subject.get_servers.map { |s| s.keys }.flatten
|
593
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
593
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
594
594
|
end
|
595
595
|
|
596
596
|
it 'accepts offset and count options' do
|
@@ -631,7 +631,7 @@ describe Postmark::AccountApiClient do
|
|
631
631
|
it 'formats the keys of returned response' do
|
632
632
|
allow(subject.http_client).to receive(:get).and_return(response)
|
633
633
|
keys = subject.get_server(42).keys
|
634
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
634
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
635
635
|
end
|
636
636
|
|
637
637
|
end
|
@@ -678,7 +678,7 @@ describe Postmark::AccountApiClient do
|
|
678
678
|
it 'formats the keys of returned response' do
|
679
679
|
allow(subject.http_client).to receive(:post).and_return(response)
|
680
680
|
keys = subject.create_server(:foo => 'bar').keys
|
681
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
681
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
682
682
|
end
|
683
683
|
|
684
684
|
end
|
@@ -720,7 +720,7 @@ describe Postmark::AccountApiClient do
|
|
720
720
|
it 'formats the keys of returned response' do
|
721
721
|
allow(subject.http_client).to receive(:put).and_return(response)
|
722
722
|
keys = subject.update_server(42, :foo => 'bar').keys
|
723
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
723
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
724
724
|
end
|
725
725
|
|
726
726
|
end
|
@@ -743,7 +743,7 @@ describe Postmark::AccountApiClient do
|
|
743
743
|
it 'formats the keys of returned response' do
|
744
744
|
allow(subject.http_client).to receive(:delete).and_return(response)
|
745
745
|
keys = subject.delete_server(42).keys
|
746
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
746
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
747
747
|
end
|
748
748
|
|
749
749
|
end
|
@@ -38,7 +38,7 @@ describe Postmark::ApiClient do
|
|
38
38
|
its(:max_retries) { should eq max_retries }
|
39
39
|
|
40
40
|
it 'passes other options to HttpClient instance' do
|
41
|
-
Postmark::HttpClient.
|
41
|
+
allow(Postmark::HttpClient).to receive(:new).with(api_token, :foo => :bar)
|
42
42
|
subject.should be
|
43
43
|
end
|
44
44
|
|
@@ -67,20 +67,18 @@ describe Postmark::ApiClient do
|
|
67
67
|
let(:response) { {"MessageID" => 42} }
|
68
68
|
|
69
69
|
it 'converts message hash to Postmark format and posts it to /email' do
|
70
|
-
http_client.
|
70
|
+
allow(http_client).to receive(:post).with('email', email_json) { response }
|
71
71
|
subject.deliver(message_hash)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'retries 3 times' do
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
http_client.should_receive(:post) { response }
|
75
|
+
expect(http_client).to receive(:post).twice.and_raise(Postmark::InternalServerError)
|
76
|
+
expect(http_client).to receive(:post) { response }
|
79
77
|
expect { subject.deliver(message_hash) }.not_to raise_error
|
80
78
|
end
|
81
79
|
|
82
80
|
it 'converts response to ruby format' do
|
83
|
-
http_client.
|
81
|
+
expect(http_client).to receive(:post).with('email', email_json) { response }
|
84
82
|
r = subject.deliver(message_hash)
|
85
83
|
r.should have_key(:message_id)
|
86
84
|
end
|
@@ -94,12 +92,12 @@ describe Postmark::ApiClient do
|
|
94
92
|
let(:response) { [{'ErrorCode' => 0}, {'ErrorCode' => 0}, {'ErrorCode' => 0}] }
|
95
93
|
|
96
94
|
it 'turns array of messages into a JSON document and posts it to /email/batch' do
|
97
|
-
http_client.
|
95
|
+
expect(http_client).to receive(:post).with('email/batch', emails_json) { response }
|
98
96
|
subject.deliver_in_batches([message_hash, message_hash, message_hash])
|
99
97
|
end
|
100
98
|
|
101
99
|
it 'converts response to ruby format' do
|
102
|
-
http_client.
|
100
|
+
expect(http_client).to receive(:post).with('email/batch', emails_json) { response }
|
103
101
|
response = subject.deliver_in_batches([message_hash, message_hash, message_hash])
|
104
102
|
response.first.should have_key(:error_code)
|
105
103
|
end
|
@@ -111,26 +109,26 @@ describe Postmark::ApiClient do
|
|
111
109
|
let(:http_client) { subject.http_client }
|
112
110
|
|
113
111
|
it 'turns message into a JSON document and posts it to /email' do
|
114
|
-
http_client.
|
112
|
+
expect(http_client).to receive(:post).with('email', email_json)
|
115
113
|
subject.deliver_message(message)
|
116
114
|
end
|
117
115
|
|
118
116
|
it "retries 3 times" do
|
119
117
|
2.times do
|
120
|
-
http_client.
|
118
|
+
expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
|
121
119
|
end
|
122
|
-
http_client.
|
120
|
+
expect(http_client).to receive(:post)
|
123
121
|
expect { subject.deliver_message(message) }.not_to raise_error
|
124
122
|
end
|
125
123
|
|
126
124
|
it "retries on timeout" do
|
127
|
-
http_client.
|
128
|
-
http_client.
|
125
|
+
expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
|
126
|
+
expect(http_client).to receive(:post)
|
129
127
|
expect { subject.deliver_message(message) }.not_to raise_error
|
130
128
|
end
|
131
129
|
|
132
130
|
it "proxies errors" do
|
133
|
-
http_client.
|
131
|
+
allow(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
|
134
132
|
expect { subject.deliver_message(message) }.to raise_error(Postmark::TimeoutError)
|
135
133
|
end
|
136
134
|
|
@@ -145,21 +143,21 @@ describe Postmark::ApiClient do
|
|
145
143
|
let(:response) { [{}, {}, {}] }
|
146
144
|
|
147
145
|
it 'turns array of messages into a JSON document and posts it to /email/batch' do
|
148
|
-
http_client.
|
146
|
+
expect(http_client).to receive(:post).with('email/batch', emails_json) { response }
|
149
147
|
subject.deliver_messages([message, message, message])
|
150
148
|
end
|
151
149
|
|
152
150
|
it "should retry 3 times" do
|
153
151
|
2.times do
|
154
|
-
http_client.
|
152
|
+
expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
|
155
153
|
end
|
156
|
-
http_client.
|
154
|
+
expect(http_client).to receive(:post) { response }
|
157
155
|
expect { subject.deliver_messages([message, message, message]) }.not_to raise_error
|
158
156
|
end
|
159
157
|
|
160
158
|
it "should retry on timeout" do
|
161
|
-
http_client.
|
162
|
-
http_client.
|
159
|
+
expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
|
160
|
+
expect(http_client).to receive(:post) { response }
|
163
161
|
expect { subject.deliver_messages([message, message, message]) }.not_to raise_error
|
164
162
|
end
|
165
163
|
|
@@ -170,7 +168,7 @@ describe Postmark::ApiClient do
|
|
170
168
|
let(:response) { {"Bounces" => [{"Foo" => "Bar"}]} }
|
171
169
|
|
172
170
|
it 'requests data at /deliverystats' do
|
173
|
-
http_client.
|
171
|
+
expect(http_client).to receive(:get).with("deliverystats") { response }
|
174
172
|
subject.delivery_stats.should have_key(:bounces)
|
175
173
|
end
|
176
174
|
end
|
@@ -224,7 +222,7 @@ describe Postmark::ApiClient do
|
|
224
222
|
let(:response) { {"TotalCount" => 1, "Messages" => [{}]} }
|
225
223
|
|
226
224
|
it 'requests data at /messages/outbound' do
|
227
|
-
http_client.
|
225
|
+
expect(http_client).to receive(:get).
|
228
226
|
with('messages/outbound', :offset => 50, :count => 50).
|
229
227
|
and_return(response)
|
230
228
|
subject.get_messages(:offset => 50, :count => 50)
|
@@ -236,7 +234,7 @@ describe Postmark::ApiClient do
|
|
236
234
|
let(:response) { {"TotalCount" => 1, "InboundMessages" => [{}]} }
|
237
235
|
|
238
236
|
it 'requests data at /messages/inbound' do
|
239
|
-
http_client.
|
237
|
+
expect(http_client).to receive(:get).
|
240
238
|
with('messages/inbound', :offset => 50, :count => 50).
|
241
239
|
and_return(response)
|
242
240
|
subject.get_messages(:inbound => true, :offset => 50, :count => 50).
|
@@ -281,7 +279,7 @@ describe Postmark::ApiClient do
|
|
281
279
|
context 'given outbound' do
|
282
280
|
|
283
281
|
it 'requests a single message by id at /messages/outbound/:id/details' do
|
284
|
-
http_client.
|
282
|
+
expect(http_client).to receive(:get).
|
285
283
|
with("messages/outbound/#{id}/details", {}).
|
286
284
|
and_return(response)
|
287
285
|
subject.get_message(id).should have_key(:to)
|
@@ -292,7 +290,7 @@ describe Postmark::ApiClient do
|
|
292
290
|
context 'given inbound' do
|
293
291
|
|
294
292
|
it 'requests a single message by id at /messages/inbound/:id/details' do
|
295
|
-
http_client.
|
293
|
+
expect(http_client).to receive(:get).
|
296
294
|
with("messages/inbound/#{id}/details", {}).
|
297
295
|
and_return(response)
|
298
296
|
subject.get_message(id, :inbound => true).should have_key(:to)
|
@@ -309,7 +307,7 @@ describe Postmark::ApiClient do
|
|
309
307
|
context 'given outbound' do
|
310
308
|
|
311
309
|
it 'requests a single message by id at /messages/outbound/:id/dump' do
|
312
|
-
http_client.
|
310
|
+
expect(http_client).to receive(:get).
|
313
311
|
with("messages/outbound/#{id}/dump", {}).
|
314
312
|
and_return(response)
|
315
313
|
subject.dump_message(id).should have_key(:body)
|
@@ -320,7 +318,7 @@ describe Postmark::ApiClient do
|
|
320
318
|
context 'given inbound' do
|
321
319
|
|
322
320
|
it 'requests a single message by id at /messages/inbound/:id/dump' do
|
323
|
-
http_client.
|
321
|
+
expect(http_client).to receive(:get).
|
324
322
|
with("messages/inbound/#{id}/dump", {}).
|
325
323
|
and_return(response)
|
326
324
|
subject.dump_message(id, :inbound => true).should have_key(:body)
|
@@ -360,7 +358,7 @@ describe Postmark::ApiClient do
|
|
360
358
|
let(:http_client) { subject.http_client }
|
361
359
|
|
362
360
|
it 'requests data at /bounces/tags' do
|
363
|
-
http_client.
|
361
|
+
expect(http_client).to receive(:get).with("bounces/tags")
|
364
362
|
subject.get_bounced_tags
|
365
363
|
end
|
366
364
|
end
|
@@ -370,7 +368,7 @@ describe Postmark::ApiClient do
|
|
370
368
|
let(:id) { 42 }
|
371
369
|
|
372
370
|
it 'requests a single bounce by ID at /bounces/:id' do
|
373
|
-
http_client.
|
371
|
+
expect(http_client).to receive(:get).with("bounces/#{id}")
|
374
372
|
subject.get_bounce(id)
|
375
373
|
end
|
376
374
|
end
|
@@ -380,7 +378,7 @@ describe Postmark::ApiClient do
|
|
380
378
|
let(:id) { 42 }
|
381
379
|
|
382
380
|
it 'requests a specific bounce data at /bounces/:id/dump' do
|
383
|
-
http_client.
|
381
|
+
expect(http_client).to receive(:get).with("bounces/#{id}/dump")
|
384
382
|
subject.dump_bounce(id)
|
385
383
|
end
|
386
384
|
end
|
@@ -391,7 +389,7 @@ describe Postmark::ApiClient do
|
|
391
389
|
let(:response) { {"Bounce" => {}} }
|
392
390
|
|
393
391
|
it 'activates a specific bounce by sending a PUT request to /bounces/:id/activate' do
|
394
|
-
http_client.
|
392
|
+
expect(http_client).to receive(:put).with("bounces/#{id}/activate") { response }
|
395
393
|
subject.activate_bounce(id)
|
396
394
|
end
|
397
395
|
end
|
@@ -411,6 +409,19 @@ describe Postmark::ApiClient do
|
|
411
409
|
|
412
410
|
end
|
413
411
|
|
412
|
+
describe '#clicks' do
|
413
|
+
it 'returns an Enumerator' do
|
414
|
+
expect(subject.clicks).to be_kind_of(Enumerable)
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'performs a GET request to /clicks/tags' do
|
418
|
+
allow(subject.http_client).to receive(:get).
|
419
|
+
with('messages/outbound/clicks', an_instance_of(Hash)).
|
420
|
+
and_return('TotalCount' => 1, 'Clicks' => [{}])
|
421
|
+
expect(subject.clicks.first(5).count).to eq(1)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
414
425
|
describe '#get_opens' do
|
415
426
|
let(:http_client) { subject.http_client }
|
416
427
|
let(:options) { {:offset => 5} }
|
@@ -423,6 +434,18 @@ describe Postmark::ApiClient do
|
|
423
434
|
end
|
424
435
|
end
|
425
436
|
|
437
|
+
describe '#get_clicks' do
|
438
|
+
let(:http_client) { subject.http_client }
|
439
|
+
let(:options) { {:offset => 5} }
|
440
|
+
let(:response) { {'Clicks' => [], 'TotalCount' => 0} }
|
441
|
+
|
442
|
+
it 'performs a GET request to /messages/outbound/clicks' do
|
443
|
+
allow(http_client).to receive(:get).with('messages/outbound/clicks', options) { response }
|
444
|
+
expect(subject.get_clicks(options)).to be_an(Array)
|
445
|
+
expect(subject.get_clicks(options).count).to be_zero
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
426
449
|
describe '#get_opens_by_message_id' do
|
427
450
|
let(:http_client) { subject.http_client }
|
428
451
|
let(:message_id) { 42 }
|
@@ -439,6 +462,22 @@ describe Postmark::ApiClient do
|
|
439
462
|
end
|
440
463
|
end
|
441
464
|
|
465
|
+
describe '#get_clicks_by_message_id' do
|
466
|
+
let(:http_client) { subject.http_client }
|
467
|
+
let(:message_id) { 42 }
|
468
|
+
let(:options) { {:offset => 5} }
|
469
|
+
let(:response) { {'Clicks' => [], 'TotalCount' => 0} }
|
470
|
+
|
471
|
+
it 'performs a GET request to /messages/outbound/clicks' do
|
472
|
+
allow(http_client).
|
473
|
+
to receive(:get).with("messages/outbound/clicks/#{message_id}",
|
474
|
+
options).
|
475
|
+
and_return(response)
|
476
|
+
expect(subject.get_clicks_by_message_id(message_id, options)).to be_an(Array)
|
477
|
+
expect(subject.get_clicks_by_message_id(message_id, options).count).to be_zero
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
442
481
|
describe '#opens_by_message_id' do
|
443
482
|
let(:message_id) { 42 }
|
444
483
|
|
@@ -454,6 +493,21 @@ describe Postmark::ApiClient do
|
|
454
493
|
end
|
455
494
|
end
|
456
495
|
|
496
|
+
describe '#clicks_by_message_id' do
|
497
|
+
let(:message_id) { 42 }
|
498
|
+
|
499
|
+
it 'returns an Enumerator' do
|
500
|
+
expect(subject.clicks_by_message_id(message_id)).to be_kind_of(Enumerable)
|
501
|
+
end
|
502
|
+
|
503
|
+
it 'performs a GET request to /clicks/tags' do
|
504
|
+
allow(subject.http_client).to receive(:get).
|
505
|
+
with("messages/outbound/clicks/#{message_id}", an_instance_of(Hash)).
|
506
|
+
and_return('TotalCount' => 1, 'Clicks' => [{}])
|
507
|
+
expect(subject.clicks_by_message_id(message_id).first(5).count).to eq(1)
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
457
511
|
describe '#create_trigger' do
|
458
512
|
let(:http_client) { subject.http_client }
|
459
513
|
let(:options) { {:foo => 'bar'} }
|
@@ -553,7 +607,7 @@ describe Postmark::ApiClient do
|
|
553
607
|
"SmtpApiActivated" => true} }
|
554
608
|
|
555
609
|
it 'requests server info from Postmark and converts it to ruby format' do
|
556
|
-
http_client.
|
610
|
+
expect(http_client).to receive(:get).with('server') { response }
|
557
611
|
subject.server_info.should have_key(:inbound_hash)
|
558
612
|
end
|
559
613
|
end
|
@@ -567,8 +621,8 @@ describe Postmark::ApiClient do
|
|
567
621
|
let(:update) { {:smtp_api_activated => false} }
|
568
622
|
|
569
623
|
it 'updates server info in Postmark and converts it to ruby format' do
|
570
|
-
http_client.
|
571
|
-
subject.update_server_info(update)[:smtp_api_activated].should
|
624
|
+
expect(http_client).to receive(:put).with('server', anything) { response }
|
625
|
+
subject.update_server_info(update)[:smtp_api_activated].should be false
|
572
626
|
end
|
573
627
|
end
|
574
628
|
|
@@ -593,7 +647,7 @@ describe Postmark::ApiClient do
|
|
593
647
|
end
|
594
648
|
|
595
649
|
it 'gets templates info and converts it to ruby format' do
|
596
|
-
http_client.
|
650
|
+
expect(http_client).to receive(:get).with('templates', :offset => 0, :count => 2).and_return(response)
|
597
651
|
|
598
652
|
count, templates = subject.get_templates(:count => 2)
|
599
653
|
|
@@ -631,7 +685,7 @@ describe Postmark::ApiClient do
|
|
631
685
|
end
|
632
686
|
|
633
687
|
it 'gets single template and converts it to ruby format' do
|
634
|
-
http_client.
|
688
|
+
expect(http_client).to receive(:get).with('templates/123').and_return(response)
|
635
689
|
|
636
690
|
template = subject.get_template('123')
|
637
691
|
|
@@ -654,7 +708,7 @@ describe Postmark::ApiClient do
|
|
654
708
|
it 'performs a POST request to /templates with the given attributes' do
|
655
709
|
expected_json = { 'Name' => 'template name' }.to_json
|
656
710
|
|
657
|
-
http_client.
|
711
|
+
expect(http_client).to receive(:post).with('templates', expected_json).and_return(response)
|
658
712
|
|
659
713
|
template = subject.create_template(:name => 'template name')
|
660
714
|
|
@@ -676,7 +730,7 @@ describe Postmark::ApiClient do
|
|
676
730
|
it 'performs a PUT request to /templates with the given attributes' do
|
677
731
|
expected_json = { 'Name' => 'template name' }.to_json
|
678
732
|
|
679
|
-
http_client.
|
733
|
+
expect(http_client).to receive(:put).with('templates/123', expected_json).and_return(response)
|
680
734
|
|
681
735
|
template = subject.update_template(123, :name => 'template name')
|
682
736
|
|
@@ -695,7 +749,7 @@ describe Postmark::ApiClient do
|
|
695
749
|
end
|
696
750
|
|
697
751
|
it 'performs a DELETE request to /templates/:id' do
|
698
|
-
http_client.
|
752
|
+
expect(http_client).to receive(:delete).with('templates/123').and_return(response)
|
699
753
|
|
700
754
|
resp = subject.delete_template(123)
|
701
755
|
|
@@ -738,14 +792,14 @@ describe Postmark::ApiClient do
|
|
738
792
|
'Subject' => '{{MyName}}'
|
739
793
|
}.to_json
|
740
794
|
|
741
|
-
http_client.
|
795
|
+
expect(http_client).to receive(:post).with('templates/validate', expected_template_json).and_return(response)
|
742
796
|
|
743
797
|
resp = subject.validate_template(:html_body => '{{MyName}}',
|
744
798
|
:text_body => '{{MyName}}',
|
745
799
|
:subject => '{{MyName}}')
|
746
800
|
|
747
|
-
expect(resp[:all_content_is_valid]).to
|
748
|
-
expect(resp[:html_body][:content_is_valid]).to
|
801
|
+
expect(resp[:all_content_is_valid]).to be true
|
802
|
+
expect(resp[:html_body][:content_is_valid]).to be true
|
749
803
|
expect(resp[:html_body][:validation_errors]).to be_empty
|
750
804
|
expect(resp[:suggested_template_model]['MyName']).to eq('MyName_Value')
|
751
805
|
end
|
@@ -787,15 +841,15 @@ describe Postmark::ApiClient do
|
|
787
841
|
'Subject' => '{{MyName}}'
|
788
842
|
}.to_json
|
789
843
|
|
790
|
-
http_client.
|
844
|
+
expect(http_client).to receive(:post).with('templates/validate', expected_template_json).and_return(response)
|
791
845
|
|
792
846
|
resp = subject.validate_template(:html_body => '{{#each}}',
|
793
847
|
:text_body => '{{MyName}}',
|
794
848
|
:subject => '{{MyName}}')
|
795
849
|
|
796
|
-
expect(resp[:all_content_is_valid]).to
|
797
|
-
expect(resp[:text_body][:content_is_valid]).to
|
798
|
-
expect(resp[:html_body][:content_is_valid]).to
|
850
|
+
expect(resp[:all_content_is_valid]).to be false
|
851
|
+
expect(resp[:text_body][:content_is_valid]).to be true
|
852
|
+
expect(resp[:html_body][:content_is_valid]).to be false
|
799
853
|
expect(resp[:html_body][:validation_errors].first[:character_position]).to eq(1)
|
800
854
|
expect(resp[:html_body][:validation_errors].first[:message]).to eq('The \'each\' block being opened requires a model path to be specified in the form \'{#each <name>}\'.')
|
801
855
|
end
|
@@ -809,25 +863,81 @@ describe Postmark::ApiClient do
|
|
809
863
|
let(:response) { {"MessageID" => 42} }
|
810
864
|
|
811
865
|
it 'converts message hash to Postmark format and posts it to /email/withTemplate' do
|
812
|
-
http_client.
|
866
|
+
expect(http_client).to receive(:post).with('email/withTemplate', email_json) { response }
|
813
867
|
subject.deliver_with_template(message_hash)
|
814
868
|
end
|
815
869
|
|
816
870
|
it 'retries 3 times' do
|
817
871
|
2.times do
|
818
|
-
http_client.
|
872
|
+
expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError, 500)
|
819
873
|
end
|
820
|
-
http_client.
|
874
|
+
expect(http_client).to receive(:post) { response }
|
821
875
|
expect { subject.deliver_with_template(message_hash) }.not_to raise_error
|
822
876
|
end
|
823
877
|
|
824
878
|
it 'converts response to ruby format' do
|
825
|
-
http_client.
|
879
|
+
expect(http_client).to receive(:post).with('email/withTemplate', email_json) { response }
|
826
880
|
r = subject.deliver_with_template(message_hash)
|
827
881
|
r.should have_key(:message_id)
|
828
882
|
end
|
829
883
|
end
|
830
884
|
|
885
|
+
describe '#deliver_in_batches_with_templates' do
|
886
|
+
let(:max_batch_size) { 50 }
|
887
|
+
let(:factor) { 3.5 }
|
888
|
+
let(:http_client) { subject.http_client }
|
889
|
+
let(:postmark_response) do
|
890
|
+
{
|
891
|
+
'ErrorCode' => 0,
|
892
|
+
'Message' => 'OK',
|
893
|
+
'SubmittedAt' => '2018-03-14T09:56:50.4288265-04:00',
|
894
|
+
'To' => 'recipient@example.org'
|
895
|
+
}
|
896
|
+
end
|
897
|
+
|
898
|
+
let(:message_hashes) do
|
899
|
+
Array.new((factor * max_batch_size).to_i) do
|
900
|
+
{
|
901
|
+
:template_id => 42,
|
902
|
+
:alias => 'alias',
|
903
|
+
:template_model => { :Foo => 'attr_value' },
|
904
|
+
:from => 'sender@example.org',
|
905
|
+
:to => 'recipient@example.org'
|
906
|
+
}
|
907
|
+
end
|
908
|
+
end
|
909
|
+
|
910
|
+
before { subject.max_batch_size = max_batch_size }
|
911
|
+
|
912
|
+
it 'performs a total of (bath_size / max_batch_size) requests' do
|
913
|
+
expect(http_client).
|
914
|
+
to receive(:post).with('email/batchWithTemplates', a_postmark_json).
|
915
|
+
at_most(factor.to_i).times do
|
916
|
+
Array.new(max_batch_size) { postmark_response }
|
917
|
+
end
|
918
|
+
|
919
|
+
expect(http_client).
|
920
|
+
to receive(:post).with('email/batchWithTemplates', a_postmark_json).
|
921
|
+
exactly((factor - factor.to_i).ceil).times do
|
922
|
+
response = Array.new(((factor - factor.to_i) * max_batch_size).to_i) do
|
923
|
+
postmark_response
|
924
|
+
end
|
925
|
+
response
|
926
|
+
end
|
927
|
+
|
928
|
+
response = subject.deliver_in_batches_with_templates(message_hashes)
|
929
|
+
expect(response).to be_an Array
|
930
|
+
expect(response.size).to eq message_hashes.size
|
931
|
+
|
932
|
+
response.each do |message_status|
|
933
|
+
expect(message_status).to have_key(:error_code)
|
934
|
+
expect(message_status).to have_key(:message)
|
935
|
+
expect(message_status).to have_key(:to)
|
936
|
+
expect(message_status).to have_key(:submitted_at)
|
937
|
+
end
|
938
|
+
end
|
939
|
+
end
|
940
|
+
|
831
941
|
describe '#get_stats_totals' do
|
832
942
|
let(:response) do
|
833
943
|
{
|
@@ -838,7 +948,7 @@ describe Postmark::ApiClient do
|
|
838
948
|
let(:http_client) { subject.http_client }
|
839
949
|
|
840
950
|
it 'converts response to ruby format' do
|
841
|
-
http_client.
|
951
|
+
expect(http_client).to receive(:get).with('stats/outbound', { :tag => 'foo' }) { response }
|
842
952
|
r = subject.get_stats_totals(:tag => 'foo')
|
843
953
|
r.should have_key(:sent)
|
844
954
|
r.should have_key(:bounce_rate)
|
@@ -872,7 +982,7 @@ describe Postmark::ApiClient do
|
|
872
982
|
let(:http_client) { subject.http_client }
|
873
983
|
|
874
984
|
it 'converts response to ruby format' do
|
875
|
-
http_client.
|
985
|
+
expect(http_client).to receive(:get).with('stats/outbound/sends', { :tag => 'foo' }) { response }
|
876
986
|
r = subject.get_stats_counts(:sends, :tag => 'foo')
|
877
987
|
r.should have_key(:days)
|
878
988
|
r.should have_key(:sent)
|
@@ -884,7 +994,7 @@ describe Postmark::ApiClient do
|
|
884
994
|
end
|
885
995
|
|
886
996
|
it 'uses fromdate that is passed in' do
|
887
|
-
http_client.
|
997
|
+
expect(http_client).to receive(:get).with('stats/outbound/sends', { :tag => 'foo', :fromdate => '2015-01-01' }) { response }
|
888
998
|
r = subject.get_stats_counts(:sends, :tag => 'foo', :fromdate => '2015-01-01')
|
889
999
|
r.should have_key(:days)
|
890
1000
|
r.should have_key(:sent)
|
@@ -896,7 +1006,7 @@ describe Postmark::ApiClient do
|
|
896
1006
|
end
|
897
1007
|
|
898
1008
|
it 'uses stats type that is passed in' do
|
899
|
-
http_client.
|
1009
|
+
expect(http_client).to receive(:get).with('stats/outbound/opens/readtimes', { :tag => 'foo', :type => :readtimes }) { response }
|
900
1010
|
r = subject.get_stats_counts(:opens, :type => :readtimes, :tag => 'foo')
|
901
1011
|
r.should have_key(:days)
|
902
1012
|
r.should have_key(:sent)
|