postmark 1.8.1 → 1.21.3
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 +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +8 -5
- data/CHANGELOG.rdoc +86 -0
- data/CONTRIBUTING.md +18 -0
- data/Gemfile +6 -5
- data/LICENSE +1 -1
- data/README.md +34 -607
- data/RELEASE.md +12 -0
- data/VERSION +1 -1
- data/gemfiles/Gemfile.legacy +5 -4
- data/lib/postmark.rb +1 -18
- data/lib/postmark/account_api_client.rb +55 -1
- data/lib/postmark/api_client.rb +145 -17
- data/lib/postmark/bounce.rb +0 -4
- data/lib/postmark/client.rb +12 -4
- data/lib/postmark/error.rb +127 -0
- data/lib/postmark/handlers/mail.rb +10 -4
- data/lib/postmark/helpers/message_helper.rb +4 -0
- data/lib/postmark/http_client.rb +20 -32
- data/lib/postmark/mail_message_converter.rb +18 -5
- data/lib/postmark/message_extensions/mail.rb +83 -8
- data/lib/postmark/version.rb +1 -1
- data/postmark.gemspec +1 -1
- data/postmark.png +0 -0
- data/spec/integration/account_api_client_spec.rb +42 -10
- data/spec/integration/api_client_hashes_spec.rb +32 -49
- data/spec/integration/api_client_messages_spec.rb +33 -52
- data/spec/integration/api_client_resources_spec.rb +12 -44
- data/spec/integration/mail_delivery_method_spec.rb +21 -23
- data/spec/spec_helper.rb +4 -7
- data/spec/support/custom_matchers.rb +44 -0
- data/spec/support/shared_examples.rb +16 -16
- data/spec/unit/postmark/account_api_client_spec.rb +239 -45
- data/spec/unit/postmark/api_client_spec.rb +792 -406
- data/spec/unit/postmark/bounce_spec.rb +40 -62
- data/spec/unit/postmark/client_spec.rb +0 -6
- data/spec/unit/postmark/error_spec.rb +231 -0
- data/spec/unit/postmark/handlers/mail_spec.rb +59 -27
- data/spec/unit/postmark/helpers/hash_helper_spec.rb +5 -6
- data/spec/unit/postmark/helpers/message_helper_spec.rb +60 -11
- data/spec/unit/postmark/http_client_spec.rb +76 -61
- data/spec/unit/postmark/inbound_spec.rb +34 -34
- data/spec/unit/postmark/inflector_spec.rb +11 -13
- data/spec/unit/postmark/json_spec.rb +2 -2
- data/spec/unit/postmark/mail_message_converter_spec.rb +250 -81
- data/spec/unit/postmark/message_extensions/mail_spec.rb +249 -38
- data/spec/unit/postmark_spec.rb +37 -37
- metadata +41 -11
@@ -17,11 +17,7 @@ describe "Sending Mail::Messages with delivery_method Mail::Postmark" do
|
|
17
17
|
end
|
18
18
|
}
|
19
19
|
|
20
|
-
let(:tagged_message) {
|
21
|
-
message.tap do |m|
|
22
|
-
m.tag "postmark-gem"
|
23
|
-
end
|
24
|
-
}
|
20
|
+
let(:tagged_message) { message.tap { |m| m.tag "postmark-gem" } }
|
25
21
|
|
26
22
|
let(:message_with_no_body) {
|
27
23
|
Mail.new do
|
@@ -53,35 +49,37 @@ describe "Sending Mail::Messages with delivery_method Mail::Postmark" do
|
|
53
49
|
expect { message.deliver }.to change{message.delivered?}.to(true)
|
54
50
|
end
|
55
51
|
|
56
|
-
it 'updates a message object with Message-
|
57
|
-
expect { message.deliver }.
|
58
|
-
to change{message['Message-ID'].to_s}.to(postmark_message_id_format)
|
52
|
+
it 'updates a message object with X-PM-Message-Id' do
|
53
|
+
expect { message.deliver }.to change{message['X-PM-Message-Id'].to_s}.to(postmark_message_id_format)
|
59
54
|
end
|
60
55
|
|
61
56
|
it 'updates a message object with full postmark response' do
|
62
|
-
expect { message.deliver }.
|
63
|
-
to change{message.postmark_response}.from(nil)
|
57
|
+
expect { message.deliver }.to change{message.postmark_response}.from(nil)
|
64
58
|
end
|
65
59
|
|
66
60
|
it 'delivers a tagged message' do
|
67
|
-
expect { tagged_message.deliver }.
|
68
|
-
to change{message.delivered?}.to(true)
|
61
|
+
expect { tagged_message.deliver }.to change{message.delivered?}.to(true)
|
69
62
|
end
|
70
63
|
|
71
64
|
it 'delivers a message with attachment' do
|
72
|
-
expect { message_with_attachment.deliver }.
|
73
|
-
to change{message_with_attachment.delivered?}.to(true)
|
65
|
+
expect { message_with_attachment.deliver }.to change{message_with_attachment.delivered?}.to(true)
|
74
66
|
end
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
68
|
+
context 'fails to deliver a message' do
|
69
|
+
it ' without body - raise error' do
|
70
|
+
expect { message_with_no_body.deliver! }.to raise_error(Postmark::InvalidMessageError)
|
71
|
+
end
|
81
72
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
73
|
+
it 'without body - do not deliver' do
|
74
|
+
expect(message_with_no_body).not_to be_delivered
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'with invalid To address - raise error' do
|
78
|
+
expect { message_with_invalid_to.deliver! }.to raise_error(Postmark::InvalidMessageError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'with invalid To address - do not deliver' do
|
82
|
+
expect(message_with_invalid_to).not_to be_delivered
|
83
|
+
end
|
86
84
|
end
|
87
85
|
end
|
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 = :expect }
|
28
|
+
|
26
29
|
config.filter_run_excluding :skip_for_platform => lambda { |platform|
|
27
30
|
RUBY_PLATFORM.to_s =~ /^#{platform.to_s}/
|
28
31
|
}
|
@@ -46,9 +49,3 @@ RSpec.configure do |config|
|
|
46
49
|
Postmark.response_parser_class = nil
|
47
50
|
end
|
48
51
|
end
|
49
|
-
|
50
|
-
RSpec::Matchers.define :be_serialized_to do |json|
|
51
|
-
match do |mail_message|
|
52
|
-
Postmark.convert_message_to_options_hash(mail_message).should == JSON.parse(json)
|
53
|
-
end
|
54
|
-
end
|
@@ -0,0 +1,44 @@
|
|
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
|
31
|
+
|
32
|
+
RSpec::Matchers.define :json_representation_of do |x|
|
33
|
+
match { |actual| Postmark::Json.decode(actual) == x }
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec::Matchers.define :match_json do |x|
|
37
|
+
match { |actual| Postmark::Json.encode(x) == actual }
|
38
|
+
end
|
39
|
+
|
40
|
+
RSpec::Matchers.define :be_serialized_to do |json|
|
41
|
+
match do |mail_message|
|
42
|
+
Postmark.convert_message_to_options_hash(mail_message) == JSON.parse(json)
|
43
|
+
end
|
44
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
1
|
shared_examples :mail do
|
2
|
-
it "
|
3
|
-
Postmark.send(:convert_message_to_options_hash, subject)['TextBody'].
|
2
|
+
it "set text body for plain message" do
|
3
|
+
expect(Postmark.send(:convert_message_to_options_hash, subject)['TextBody']).not_to be_nil
|
4
4
|
end
|
5
5
|
|
6
|
-
it "
|
6
|
+
it "encode from properly when name is used" do
|
7
7
|
subject.from = "Sheldon Lee Cooper <sheldon@bigbangtheory.com>"
|
8
|
-
subject.
|
8
|
+
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"Sheldon Lee Cooper <sheldon@bigbangtheory.com>", "To":"lenard@bigbangtheory.com", "TextBody":"Hello Sheldon!"}]
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "encode reply to" do
|
12
12
|
subject.reply_to = ['a@a.com', 'b@b.com']
|
13
|
-
subject.
|
13
|
+
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"sheldon@bigbangtheory.com", "ReplyTo":"a@a.com, b@b.com", "To":"lenard@bigbangtheory.com", "TextBody":"Hello Sheldon!"}]
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "encode tag" do
|
17
17
|
subject.tag = "invite"
|
18
|
-
subject.
|
18
|
+
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"sheldon@bigbangtheory.com", "Tag":"invite", "To":"lenard@bigbangtheory.com", "TextBody":"Hello Sheldon!"}]
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "encode multiple recepients (TO)" do
|
22
22
|
subject.to = ['a@a.com', 'b@b.com']
|
23
|
-
subject.
|
23
|
+
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"sheldon@bigbangtheory.com", "To":"a@a.com, b@b.com", "TextBody":"Hello Sheldon!"}]
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "encode multiple recepients (CC)" do
|
27
27
|
subject.cc = ['a@a.com', 'b@b.com']
|
28
|
-
subject.
|
28
|
+
expect(subject).to be_serialized_to %q[{"Cc":"a@a.com, b@b.com", "Subject":"Hello!", "From":"sheldon@bigbangtheory.com", "To":"lenard@bigbangtheory.com", "TextBody":"Hello Sheldon!"}]
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "encode multiple recepients (BCC)" do
|
32
32
|
subject.bcc = ['a@a.com', 'b@b.com']
|
33
|
-
subject.
|
33
|
+
expect(subject).to be_serialized_to %q[{"Bcc":"a@a.com, b@b.com", "Subject":"Hello!", "From":"sheldon@bigbangtheory.com", "To":"lenard@bigbangtheory.com", "TextBody":"Hello Sheldon!"}]
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "accept string as reply_to field" do
|
37
37
|
subject.reply_to = ['Anton Astashov <b@b.com>']
|
38
|
-
subject.
|
38
|
+
expect(subject).to be_serialized_to %q[{"From": "sheldon@bigbangtheory.com", "ReplyTo": "b@b.com", "To": "lenard@bigbangtheory.com", "Subject": "Hello!", "TextBody": "Hello Sheldon!"}]
|
39
39
|
end
|
40
40
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Postmark::AccountApiClient do
|
4
|
-
|
5
4
|
let(:api_token) { 'abcd-efgh' }
|
6
5
|
subject { Postmark::AccountApiClient}
|
7
6
|
|
@@ -14,7 +13,6 @@ describe Postmark::AccountApiClient do
|
|
14
13
|
end
|
15
14
|
|
16
15
|
context 'instance' do
|
17
|
-
|
18
16
|
subject { Postmark::AccountApiClient.new(api_token) }
|
19
17
|
|
20
18
|
it 'uses the auth header specific for Account API' do
|
@@ -23,7 +21,6 @@ describe Postmark::AccountApiClient do
|
|
23
21
|
end
|
24
22
|
|
25
23
|
describe '#senders' do
|
26
|
-
|
27
24
|
let(:response) {
|
28
25
|
{
|
29
26
|
'TotalCount' => 10, 'SenderSignatures' => [{}, {}]
|
@@ -44,11 +41,9 @@ describe Postmark::AccountApiClient do
|
|
44
41
|
with('senders', an_instance_of(Hash)).and_return(response)
|
45
42
|
subject.senders.take(1000)
|
46
43
|
end
|
47
|
-
|
48
44
|
end
|
49
45
|
|
50
46
|
describe '#get_senders' do
|
51
|
-
|
52
47
|
let(:response) {
|
53
48
|
{
|
54
49
|
"TotalCount" => 1,
|
@@ -77,7 +72,7 @@ describe Postmark::AccountApiClient do
|
|
77
72
|
it 'formats the keys of returned list of senders' do
|
78
73
|
allow(subject.http_client).to receive(:get).and_return(response)
|
79
74
|
keys = subject.get_senders.map { |s| s.keys }.flatten
|
80
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
75
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
81
76
|
end
|
82
77
|
|
83
78
|
it 'accepts offset and count options' do
|
@@ -86,11 +81,9 @@ describe Postmark::AccountApiClient do
|
|
86
81
|
and_return(response)
|
87
82
|
subject.get_senders(:offset => 10, :count => 42)
|
88
83
|
end
|
89
|
-
|
90
84
|
end
|
91
85
|
|
92
86
|
describe '#get_senders_count' do
|
93
|
-
|
94
87
|
let(:response) { {'TotalCount' => 42} }
|
95
88
|
|
96
89
|
it 'is aliased as #get_signatures_count' do
|
@@ -103,11 +96,9 @@ describe Postmark::AccountApiClient do
|
|
103
96
|
with('senders', an_instance_of(Hash)).and_return(response)
|
104
97
|
expect(subject.get_senders_count).to eq(42)
|
105
98
|
end
|
106
|
-
|
107
99
|
end
|
108
100
|
|
109
101
|
describe '#get_sender' do
|
110
|
-
|
111
102
|
let(:response) {
|
112
103
|
{
|
113
104
|
"Domain" => "example.com",
|
@@ -132,12 +123,11 @@ describe Postmark::AccountApiClient do
|
|
132
123
|
it 'formats the keys of returned response' do
|
133
124
|
allow(subject.http_client).to receive(:get).and_return(response)
|
134
125
|
keys = subject.get_sender(42).keys
|
135
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
126
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
136
127
|
end
|
137
128
|
end
|
138
129
|
|
139
130
|
describe '#create_sender' do
|
140
|
-
|
141
131
|
let(:response) {
|
142
132
|
{
|
143
133
|
"Domain" => "example.com",
|
@@ -168,12 +158,11 @@ describe Postmark::AccountApiClient do
|
|
168
158
|
it 'formats the keys of returned response' do
|
169
159
|
allow(subject.http_client).to receive(:post).and_return(response)
|
170
160
|
keys = subject.create_sender(:foo => 'bar').keys
|
171
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
161
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
172
162
|
end
|
173
163
|
end
|
174
164
|
|
175
165
|
describe '#update_sender' do
|
176
|
-
|
177
166
|
let(:response) {
|
178
167
|
{
|
179
168
|
"Domain" => "example.com",
|
@@ -205,13 +194,11 @@ describe Postmark::AccountApiClient do
|
|
205
194
|
it 'formats the keys of returned response' do
|
206
195
|
allow(subject.http_client).to receive(:put).and_return(response)
|
207
196
|
keys = subject.update_sender(42, :foo => 'bar').keys
|
208
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
197
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
209
198
|
end
|
210
|
-
|
211
199
|
end
|
212
200
|
|
213
201
|
describe '#resend_sender_confirmation' do
|
214
|
-
|
215
202
|
let(:response) {
|
216
203
|
{
|
217
204
|
"ErrorCode" => 0,
|
@@ -233,13 +220,11 @@ describe Postmark::AccountApiClient do
|
|
233
220
|
it 'formats the keys of returned response' do
|
234
221
|
allow(subject.http_client).to receive(:post).and_return(response)
|
235
222
|
keys = subject.resend_sender_confirmation(42).keys
|
236
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
223
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
237
224
|
end
|
238
|
-
|
239
225
|
end
|
240
226
|
|
241
227
|
describe '#verified_sender_spf?' do
|
242
|
-
|
243
228
|
let(:response) { {"SPFVerified" => true} }
|
244
229
|
let(:false_response) { {"SPFVerified" => false} }
|
245
230
|
|
@@ -255,18 +240,16 @@ describe Postmark::AccountApiClient do
|
|
255
240
|
|
256
241
|
it 'returns false when SPFVerified field of the response is false' do
|
257
242
|
allow(subject.http_client).to receive(:post).and_return(false_response)
|
258
|
-
expect(subject.verified_sender_spf?(42)).to
|
243
|
+
expect(subject.verified_sender_spf?(42)).to be false
|
259
244
|
end
|
260
245
|
|
261
246
|
it 'returns true when SPFVerified field of the response is true' do
|
262
247
|
allow(subject.http_client).to receive(:post).and_return(response)
|
263
|
-
expect(subject.verified_sender_spf?(42)).to
|
248
|
+
expect(subject.verified_sender_spf?(42)).to be true
|
264
249
|
end
|
265
|
-
|
266
250
|
end
|
267
251
|
|
268
252
|
describe '#request_new_sender_dkim' do
|
269
|
-
|
270
253
|
let(:response) {
|
271
254
|
{
|
272
255
|
"Domain" => "example.com",
|
@@ -292,13 +275,11 @@ describe Postmark::AccountApiClient do
|
|
292
275
|
it 'formats the keys of returned response' do
|
293
276
|
allow(subject.http_client).to receive(:post).and_return(response)
|
294
277
|
keys = subject.request_new_sender_dkim(42).keys
|
295
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
278
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
296
279
|
end
|
297
|
-
|
298
280
|
end
|
299
281
|
|
300
282
|
describe '#delete_sender' do
|
301
|
-
|
302
283
|
let(:response) {
|
303
284
|
{
|
304
285
|
"ErrorCode" => 0,
|
@@ -319,13 +300,209 @@ describe Postmark::AccountApiClient do
|
|
319
300
|
it 'formats the keys of returned response' do
|
320
301
|
allow(subject.http_client).to receive(:delete).and_return(response)
|
321
302
|
keys = subject.delete_sender(42).keys
|
322
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
303
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
describe '#domains' do
|
308
|
+
let(:response) {{'TotalCount' => 10, 'Domains' => [{}, {}]}}
|
309
|
+
|
310
|
+
it 'returns an enumerator' do
|
311
|
+
expect(subject.domains).to be_kind_of(Enumerable)
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'lazily loads domains' do
|
315
|
+
allow(subject.http_client).to receive(:get).
|
316
|
+
with('domains', an_instance_of(Hash)).and_return(response)
|
317
|
+
subject.domains.take(1000)
|
323
318
|
end
|
324
319
|
|
325
320
|
end
|
326
321
|
|
327
|
-
describe '#
|
322
|
+
describe '#get_domains' do
|
323
|
+
|
324
|
+
let(:response) {
|
325
|
+
{
|
326
|
+
"TotalCount" => 1,
|
327
|
+
"Domains" => [{
|
328
|
+
"Name" => "example.com",
|
329
|
+
"ID" => 8139
|
330
|
+
}]
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
it 'performs a GET request to /domains endpoint' do
|
335
|
+
allow(subject.http_client).to receive(:get).
|
336
|
+
with('domains', :offset => 0, :count => 30).
|
337
|
+
and_return(response)
|
338
|
+
subject.get_domains
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'formats the keys of returned list of domains' do
|
342
|
+
allow(subject.http_client).to receive(:get).and_return(response)
|
343
|
+
keys = subject.get_domains.map { |s| s.keys }.flatten
|
344
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
345
|
+
end
|
346
|
+
|
347
|
+
it 'accepts offset and count options' do
|
348
|
+
allow(subject.http_client).to receive(:get).
|
349
|
+
with('domains', :offset => 10, :count => 42).
|
350
|
+
and_return(response)
|
351
|
+
subject.get_domains(:offset => 10, :count => 42)
|
352
|
+
end
|
353
|
+
|
354
|
+
end
|
355
|
+
|
356
|
+
describe '#get_domains_count' do
|
357
|
+
let(:response) { {'TotalCount' => 42} }
|
358
|
+
|
359
|
+
it 'returns a total number of domains' do
|
360
|
+
allow(subject.http_client).to receive(:get).
|
361
|
+
with('domains', an_instance_of(Hash)).and_return(response)
|
362
|
+
expect(subject.get_domains_count).to eq(42)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
describe '#get_domain' do
|
367
|
+
let(:response) {
|
368
|
+
{
|
369
|
+
"Name" => "example.com",
|
370
|
+
"ID" => 8139
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
it 'performs a GET request to /domains/:id endpoint' do
|
375
|
+
allow(subject.http_client).to receive(:get).with("domains/42").
|
376
|
+
and_return(response)
|
377
|
+
subject.get_domain(42)
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'formats the keys of returned response' do
|
381
|
+
allow(subject.http_client).to receive(:get).and_return(response)
|
382
|
+
keys = subject.get_domain(42).keys
|
383
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
describe '#create_domain' do
|
388
|
+
let(:response) {
|
389
|
+
{
|
390
|
+
"Name" => "example.com",
|
391
|
+
"ID" => 8139
|
392
|
+
}
|
393
|
+
}
|
394
|
+
|
395
|
+
it 'performs a POST request to /domains endpoint' do
|
396
|
+
allow(subject.http_client).to receive(:post).
|
397
|
+
with("domains", an_instance_of(String)).and_return(response)
|
398
|
+
subject.create_domain(:name => 'example.com')
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'converts the domain attributes names to camel case' do
|
402
|
+
allow(subject.http_client).to receive(:post).
|
403
|
+
with("domains", {'FooBar' => 'bar'}.to_json).and_return(response)
|
404
|
+
subject.create_domain(:foo_bar => 'bar')
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'formats the keys of returned response' do
|
408
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
409
|
+
keys = subject.create_domain(:foo => 'bar').keys
|
410
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
411
|
+
end
|
412
|
+
end
|
328
413
|
|
414
|
+
describe '#update_domain' do
|
415
|
+
let(:response) {
|
416
|
+
{
|
417
|
+
"Name" => "example.com",
|
418
|
+
"ReturnPathDomain" => "return.example.com",
|
419
|
+
"ID" => 8139
|
420
|
+
}
|
421
|
+
}
|
422
|
+
|
423
|
+
it 'performs a PUT request to /domains/:id endpoint' do
|
424
|
+
allow(subject.http_client).to receive(:put).
|
425
|
+
with('domains/42', an_instance_of(String)).and_return(response)
|
426
|
+
subject.update_domain(42, :return_path_domain => 'updated-return.example.com')
|
427
|
+
end
|
428
|
+
|
429
|
+
it 'converts the domain attributes names to camel case' do
|
430
|
+
allow(subject.http_client).to receive(:put).
|
431
|
+
with('domains/42', {'FooBar' => 'bar'}.to_json).and_return(response)
|
432
|
+
subject.update_domain(42, :foo_bar => 'bar')
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'formats the keys of returned response' do
|
436
|
+
allow(subject.http_client).to receive(:put).and_return(response)
|
437
|
+
keys = subject.update_domain(42, :foo => 'bar').keys
|
438
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
describe '#verified_domain_spf?' do
|
443
|
+
let(:response) { {"SPFVerified" => true} }
|
444
|
+
let(:false_response) { {"SPFVerified" => false} }
|
445
|
+
|
446
|
+
it 'performs a POST request to /domains/:id/verifyspf endpoint' do
|
447
|
+
allow(subject.http_client).to receive(:post).
|
448
|
+
with('domains/42/verifyspf').and_return(response)
|
449
|
+
subject.verified_domain_spf?(42)
|
450
|
+
end
|
451
|
+
|
452
|
+
it 'returns false when SPFVerified field of the response is false' do
|
453
|
+
allow(subject.http_client).to receive(:post).and_return(false_response)
|
454
|
+
expect(subject.verified_domain_spf?(42)).to be false
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'returns true when SPFVerified field of the response is true' do
|
458
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
459
|
+
expect(subject.verified_domain_spf?(42)).to be true
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
describe '#rotate_domain_dkim' do
|
464
|
+
let(:response) {
|
465
|
+
{
|
466
|
+
"Name" => "example.com",
|
467
|
+
"ID" => 8139
|
468
|
+
}
|
469
|
+
}
|
470
|
+
|
471
|
+
it 'performs a POST request to /domains/:id/rotatedkim endpoint' do
|
472
|
+
allow(subject.http_client).to receive(:post).
|
473
|
+
with('domains/42/rotatedkim').and_return(response)
|
474
|
+
subject.rotate_domain_dkim(42)
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'formats the keys of returned response' do
|
478
|
+
allow(subject.http_client).to receive(:post).and_return(response)
|
479
|
+
keys = subject.rotate_domain_dkim(42).keys
|
480
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
describe '#delete_domain' do
|
485
|
+
let(:response) {
|
486
|
+
{
|
487
|
+
"ErrorCode" => 0,
|
488
|
+
"Message" => "Domain example.com removed."
|
489
|
+
}
|
490
|
+
}
|
491
|
+
|
492
|
+
it 'performs a DELETE request to /domains/:id endpoint' do
|
493
|
+
allow(subject.http_client).to receive(:delete).
|
494
|
+
with('domains/42').and_return(response)
|
495
|
+
subject.delete_domain(42)
|
496
|
+
end
|
497
|
+
|
498
|
+
it 'formats the keys of returned response' do
|
499
|
+
allow(subject.http_client).to receive(:delete).and_return(response)
|
500
|
+
keys = subject.delete_sender(42).keys
|
501
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
describe '#servers' do
|
329
506
|
let(:response) { {'TotalCount' => 10, 'Servers' => [{}, {}]} }
|
330
507
|
|
331
508
|
it 'returns an enumerator' do
|
@@ -337,11 +514,9 @@ describe Postmark::AccountApiClient do
|
|
337
514
|
with('servers', an_instance_of(Hash)).and_return(response)
|
338
515
|
subject.servers.take(100)
|
339
516
|
end
|
340
|
-
|
341
517
|
end
|
342
518
|
|
343
519
|
describe '#get_servers' do
|
344
|
-
|
345
520
|
let(:response) {
|
346
521
|
{
|
347
522
|
'TotalCount' => 1,
|
@@ -375,7 +550,7 @@ describe Postmark::AccountApiClient do
|
|
375
550
|
it 'formats the keys of returned list of servers' do
|
376
551
|
allow(subject.http_client).to receive(:get).and_return(response)
|
377
552
|
keys = subject.get_servers.map { |s| s.keys }.flatten
|
378
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
553
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
379
554
|
end
|
380
555
|
|
381
556
|
it 'accepts offset and count options' do
|
@@ -387,7 +562,6 @@ describe Postmark::AccountApiClient do
|
|
387
562
|
end
|
388
563
|
|
389
564
|
describe '#get_server' do
|
390
|
-
|
391
565
|
let(:response) {
|
392
566
|
{
|
393
567
|
"ID" => 7438,
|
@@ -416,13 +590,11 @@ describe Postmark::AccountApiClient do
|
|
416
590
|
it 'formats the keys of returned response' do
|
417
591
|
allow(subject.http_client).to receive(:get).and_return(response)
|
418
592
|
keys = subject.get_server(42).keys
|
419
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
593
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
420
594
|
end
|
421
|
-
|
422
595
|
end
|
423
596
|
|
424
597
|
describe '#get_servers_count' do
|
425
|
-
|
426
598
|
let(:response) { {'TotalCount' => 42} }
|
427
599
|
|
428
600
|
it 'returns a total number of servers' do
|
@@ -434,7 +606,6 @@ describe Postmark::AccountApiClient do
|
|
434
606
|
end
|
435
607
|
|
436
608
|
describe '#create_server' do
|
437
|
-
|
438
609
|
let(:response) {
|
439
610
|
{
|
440
611
|
"Name" => "Staging Testing",
|
@@ -463,9 +634,8 @@ describe Postmark::AccountApiClient do
|
|
463
634
|
it 'formats the keys of returned response' do
|
464
635
|
allow(subject.http_client).to receive(:post).and_return(response)
|
465
636
|
keys = subject.create_server(:foo => 'bar').keys
|
466
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
637
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
467
638
|
end
|
468
|
-
|
469
639
|
end
|
470
640
|
|
471
641
|
describe '#update_server' do
|
@@ -505,13 +675,11 @@ describe Postmark::AccountApiClient do
|
|
505
675
|
it 'formats the keys of returned response' do
|
506
676
|
allow(subject.http_client).to receive(:put).and_return(response)
|
507
677
|
keys = subject.update_server(42, :foo => 'bar').keys
|
508
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
678
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
509
679
|
end
|
510
|
-
|
511
680
|
end
|
512
681
|
|
513
682
|
describe '#delete_server' do
|
514
|
-
|
515
683
|
let(:response) {
|
516
684
|
{
|
517
685
|
"ErrorCode" => "0",
|
@@ -528,11 +696,37 @@ describe Postmark::AccountApiClient do
|
|
528
696
|
it 'formats the keys of returned response' do
|
529
697
|
allow(subject.http_client).to receive(:delete).and_return(response)
|
530
698
|
keys = subject.delete_server(42).keys
|
531
|
-
expect(keys.all? { |k| k.is_a?(Symbol) }).to
|
699
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
532
700
|
end
|
701
|
+
end
|
702
|
+
|
703
|
+
describe '#push_templates' do
|
704
|
+
let(:response) {
|
705
|
+
{"TotalCount"=>5,
|
706
|
+
"Templates"=>
|
707
|
+
[{"Action"=>"Create", "TemplateId"=>nil, "Alias"=>"alias1", "Name"=>"Comment notification"},
|
708
|
+
{"Action"=>"Create", "TemplateId"=>nil, "Alias"=>"alias2", "Name"=>"Password reset"}]}
|
709
|
+
}
|
533
710
|
|
711
|
+
let(:request_data) {{:source_server_id => 1, :destination_server_id => 2, :perform_changes => false}}
|
712
|
+
|
713
|
+
it 'gets templates info and converts it to ruby format' do
|
714
|
+
allow(subject.http_client).to receive(:put).and_return(response)
|
715
|
+
templates = subject.push_templates({:source_server_id => 1, :destination_server_id => 2, :perform_changes => false} )
|
716
|
+
|
717
|
+
expect(templates.size).to eq(2)
|
718
|
+
expect(templates.first[:action]).to eq('Create')
|
719
|
+
expect(templates.first[:alias]).to eq('alias1')
|
720
|
+
end
|
721
|
+
|
722
|
+
it 'formats the keys of returned response' do
|
723
|
+
allow(subject.http_client).to receive(:put).and_return(response)
|
724
|
+
templates = subject.push_templates({:source_server_id => 1, :destination_server_id => 2, :perform_changes => false} )
|
725
|
+
|
726
|
+
keys = templates.map { |template| template.keys }.flatten
|
727
|
+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
|
728
|
+
end
|
534
729
|
end
|
535
730
|
|
536
731
|
end
|
537
|
-
|
538
|
-
end
|
732
|
+
end
|