postmark 1.21.5 → 1.22.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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.rdoc +16 -0
- data/RELEASE.md +1 -0
- data/VERSION +1 -1
- data/lib/postmark/api_client.rb +7 -7
- data/lib/postmark/client.rb +7 -4
- data/lib/postmark/error.rb +10 -6
- data/lib/postmark/helpers/hash_helper.rb +36 -11
- data/lib/postmark/version.rb +1 -1
- data/spec/unit/postmark/api_client_spec.rb +243 -209
- data/spec/unit/postmark/error_spec.rb +52 -0
- data/spec/unit/postmark/helpers/hash_helper_spec.rb +101 -14
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b214577bda32a36ea3de8910d8ef1bf7929e090e513a30d32ae891219134234b
|
4
|
+
data.tar.gz: 7379520e17f6e9afda7e7157e4e118ccd1b171298e211555e112e5963433880c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bf13b2db7d0818a8f69286b4ece4ad1675b8e546a9677f23f9827915c80795b5118a16a9a32860dfab3b35b5b694791ef3e48bc8d2eca13dd05228fe634f3a2
|
7
|
+
data.tar.gz: a4ce846c304fea9a62ffd3bcc4802675a435009b6536741ad3b32c9dd98780925f57d0e32fa1c40c1d45c0b8ca5096d626140c4fd78268a072231a7fc4dc4fdc
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
postmark-gem
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.6
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,21 @@
|
|
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
|
+
|
7
|
+
== 1.21.8
|
8
|
+
|
9
|
+
* Fixed passing and receiving SubscriptionManagementConfiguration when creating/updating message streams (#94).
|
10
|
+
|
11
|
+
== 1.21.7
|
12
|
+
|
13
|
+
* Improved parsing recipients with Postmark::InactiveRecipientError.parse_recipients method
|
14
|
+
|
15
|
+
== 1.21.6
|
16
|
+
|
17
|
+
* Improved error handling for email sending related to invalid email addresses
|
18
|
+
|
3
19
|
== 1.21.5
|
4
20
|
|
5
21
|
* Added support for archiving/unarchiving message streams
|
data/RELEASE.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
New versions of the gem are cut by the Postmark team, this is a quick guide to ensuring a smooth release.
|
2
2
|
|
3
|
+
1. Determine the next version of the gem by following the [SemVer](https://semver.org/) guidelines.
|
3
4
|
1. Verify all builds are passing on CircleCI for your branch.
|
4
5
|
1. Merge in your branch to master.
|
5
6
|
1. Update VERSION and lib/postmark/version.rb with the new version.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.22.0
|
data/lib/postmark/api_client.rb
CHANGED
@@ -38,7 +38,7 @@ module Postmark
|
|
38
38
|
response, error = take_response_of { http_client.post("email", data) }
|
39
39
|
update_message(message, response)
|
40
40
|
raise error if error
|
41
|
-
format_response(response, true)
|
41
|
+
format_response(response, :compatible => true)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -51,7 +51,7 @@ module Postmark
|
|
51
51
|
response, error = take_response_of { http_client.post("email/withTemplate", data) }
|
52
52
|
update_message(message, response)
|
53
53
|
raise error if error
|
54
|
-
format_response(response, true)
|
54
|
+
format_response(response, :compatible => true)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -95,7 +95,7 @@ module Postmark
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def delivery_stats
|
98
|
-
response = format_response(http_client.get("deliverystats"), true)
|
98
|
+
response = format_response(http_client.get("deliverystats"), :compatible => true)
|
99
99
|
|
100
100
|
if response[:bounces]
|
101
101
|
response[:bounces] = format_response(response[:bounces])
|
@@ -343,13 +343,13 @@ module Postmark
|
|
343
343
|
end
|
344
344
|
|
345
345
|
def create_message_stream(attributes = {})
|
346
|
-
data = serialize(HashHelper.to_postmark(attributes))
|
347
|
-
format_response(http_client.post('message-streams', data))
|
346
|
+
data = serialize(HashHelper.to_postmark(attributes, :deep => true))
|
347
|
+
format_response(http_client.post('message-streams', data), :deep => true)
|
348
348
|
end
|
349
349
|
|
350
350
|
def update_message_stream(id, attributes)
|
351
|
-
data = serialize(HashHelper.to_postmark(attributes))
|
352
|
-
format_response(http_client.patch("message-streams/#{id}", data))
|
351
|
+
data = serialize(HashHelper.to_postmark(attributes, :deep => true))
|
352
|
+
format_response(http_client.patch("message-streams/#{id}", data), :deep => true)
|
353
353
|
end
|
354
354
|
|
355
355
|
def archive_message_stream(id)
|
data/lib/postmark/client.rb
CHANGED
@@ -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) ||
|
9
|
+
@max_retries = options.delete(:max_retries) || 0
|
10
10
|
@http_client = HttpClient.new(api_token, options)
|
11
11
|
end
|
12
12
|
|
@@ -60,13 +60,16 @@ module Postmark
|
|
60
60
|
[e.full_response || {}, e]
|
61
61
|
end
|
62
62
|
|
63
|
-
def format_response(response,
|
63
|
+
def format_response(response, options = {})
|
64
64
|
return {} unless response
|
65
65
|
|
66
|
+
compatible = options.fetch(:compatible, false)
|
67
|
+
deep = options.fetch(:deep, false)
|
68
|
+
|
66
69
|
if response.kind_of? Array
|
67
|
-
response.map { |entry| Postmark::HashHelper.to_ruby(entry, compatible) }
|
70
|
+
response.map { |entry| Postmark::HashHelper.to_ruby(entry, :compatible => compatible, :deep => deep) }
|
68
71
|
else
|
69
|
-
Postmark::HashHelper.to_ruby(response, compatible)
|
72
|
+
Postmark::HashHelper.to_ruby(response, :compatible => compatible, :deep => deep)
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
data/lib/postmark/error.rb
CHANGED
@@ -30,9 +30,8 @@ module Postmark
|
|
30
30
|
def initialize(status_code = 500, body = '', parsed_body = {})
|
31
31
|
self.parsed_body = parsed_body
|
32
32
|
self.status_code = status_code.to_i
|
33
|
-
|
34
|
-
|
35
|
-
"The Postmark API responded with HTTP status #{status_code}.")
|
33
|
+
self.body = body
|
34
|
+
message = parsed_body.fetch('Message', "The Postmark API responded with HTTP status #{status_code}.")
|
36
35
|
|
37
36
|
super(message)
|
38
37
|
end
|
@@ -44,6 +43,7 @@ module Postmark
|
|
44
43
|
|
45
44
|
class ApiInputError < HttpServerError
|
46
45
|
INACTIVE_RECIPIENT = 406
|
46
|
+
INVALID_EMAIL_ADDRESS = 300
|
47
47
|
|
48
48
|
attr_accessor :error_code
|
49
49
|
|
@@ -52,7 +52,9 @@ module Postmark
|
|
52
52
|
|
53
53
|
case error_code
|
54
54
|
when INACTIVE_RECIPIENT
|
55
|
-
InactiveRecipientError.new(
|
55
|
+
InactiveRecipientError.new(error_code, body, parsed_body)
|
56
|
+
when INVALID_EMAIL_ADDRESS
|
57
|
+
InvalidEmailAddressError.new(error_code, body, parsed_body)
|
56
58
|
else
|
57
59
|
new(error_code, body, parsed_body)
|
58
60
|
end
|
@@ -68,12 +70,14 @@ module Postmark
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
73
|
+
class InvalidEmailAddressError < ApiInputError; end
|
74
|
+
|
71
75
|
class InactiveRecipientError < ApiInputError
|
72
76
|
attr_reader :recipients
|
73
77
|
|
74
78
|
PATTERNS = [/^Found inactive addresses: (.+?)\.$/.freeze,
|
75
|
-
|
76
|
-
/these inactive addresses: (.+?)
|
79
|
+
/these inactive addresses: (.+?)\. Inactive/.freeze,
|
80
|
+
/these inactive addresses: (.+?)\.?$/].freeze
|
77
81
|
|
78
82
|
def self.parse_recipients(message)
|
79
83
|
PATTERNS.each do |p|
|
@@ -3,22 +3,47 @@ module Postmark
|
|
3
3
|
|
4
4
|
extend self
|
5
5
|
|
6
|
-
def to_postmark(
|
7
|
-
|
6
|
+
def to_postmark(object, options = {})
|
7
|
+
deep = options.fetch(:deep, false)
|
8
|
+
|
9
|
+
case object
|
10
|
+
when Hash
|
11
|
+
object.reduce({}) do |m, (k, v)|
|
12
|
+
m.tap do |h|
|
13
|
+
h[Inflector.to_postmark(k)] = deep ? to_postmark(v, options) : v
|
14
|
+
end
|
15
|
+
end
|
16
|
+
when Array
|
17
|
+
deep ? object.map { |v| to_postmark(v, options) } : object
|
18
|
+
else
|
19
|
+
object
|
20
|
+
end
|
8
21
|
end
|
9
22
|
|
10
|
-
def to_ruby(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
23
|
+
def to_ruby(object, options = {})
|
24
|
+
compatible = options.fetch(:compatible, false)
|
25
|
+
deep = options.fetch(:deep, false)
|
26
|
+
|
27
|
+
case object
|
28
|
+
when Hash
|
29
|
+
object.reduce({}) do |m, (k, v)|
|
30
|
+
m.tap do |h|
|
31
|
+
h[Inflector.to_ruby(k)] = deep ? to_ruby(v, options) : v
|
32
|
+
end
|
33
|
+
end.tap do |result|
|
34
|
+
if compatible
|
35
|
+
result.merge!(object)
|
36
|
+
enhance_with_compatibility_warning(result)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
when Array
|
40
|
+
deep ? object.map { |v| to_ruby(v, options) } : object
|
41
|
+
else
|
42
|
+
object
|
16
43
|
end
|
17
|
-
|
18
|
-
formatted
|
19
44
|
end
|
20
45
|
|
21
|
-
|
46
|
+
private
|
22
47
|
|
23
48
|
def enhance_with_compatibility_warning(hash)
|
24
49
|
def hash.[](key)
|
data/lib/postmark/version.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
26
|
-
it { expect(
|
27
|
-
it { expect(
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
53
|
-
expect(
|
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
|
-
|
58
|
-
expect(
|
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
|
68
|
-
|
69
|
-
subject
|
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
|
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
|
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
|
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
|
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
|
-
|
107
|
-
|
108
|
-
to raise_error(ArgumentError, /Please use Postmark::ApiClient\#deliver_message_with_template/)
|
109
|
-
end
|
150
|
+
context 'when given a templated message' do
|
151
|
+
let(:message) {templated_message}
|
110
152
|
|
111
|
-
|
112
|
-
|
113
|
-
subject.deliver_message(message)
|
114
|
-
end
|
115
|
-
|
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
|
125
|
-
expect(http_client).to receive(:post).
|
126
|
-
|
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
|
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
|
-
|
141
|
-
|
142
|
-
to raise_error(ArgumentError, 'Templated delivery requested, but the template is missing.')
|
143
|
-
end
|
177
|
+
context 'when given a non-templated message' do
|
178
|
+
let(:templated_message) {message}
|
144
179
|
|
145
|
-
|
146
|
-
|
147
|
-
subject.deliver_message_with_template(templated_message)
|
148
|
-
end
|
149
|
-
|
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
|
159
|
-
expect(http_client).to receive(:post).
|
160
|
-
|
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
|
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(:
|
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
|
-
|
177
|
-
|
178
|
-
|
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
|
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
|
-
|
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(:
|
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
|
-
|
209
|
-
|
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
|
-
|
219
|
-
|
220
|
-
|
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
|
227
|
-
expect(http_client).to receive(:post).
|
228
|
-
|
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(
|
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(
|
261
|
+
expect(api_client.messages).to be_kind_of(Enumerable)
|
248
262
|
end
|
249
263
|
|
250
264
|
it 'loads outbound messages' do
|
251
|
-
allow(
|
265
|
+
allow(api_client.http_client).to receive(:get).
|
252
266
|
with('messages/outbound', an_instance_of(Hash)).and_return(response)
|
253
|
-
expect(
|
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(
|
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(
|
266
|
-
expect(
|
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
|
-
|
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(
|
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(
|
313
|
+
allow(api_client.http_client).to receive(:get).
|
300
314
|
with('messages/outbound', an_instance_of(Hash)).and_return(response)
|
301
|
-
expect(
|
302
|
-
expect(
|
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(
|
323
|
+
allow(api_client.http_client).to receive(:get).
|
310
324
|
with('messages/inbound', an_instance_of(Hash)).and_return(response)
|
311
|
-
expect(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
385
|
-
expect(
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
450
|
-
expect(
|
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(
|
461
|
-
expect(
|
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(
|
473
|
-
expect(
|
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(
|
485
|
-
expect(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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
|
-
|
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(
|
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
|
-
|
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(
|
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
|
-
|
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(
|
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
|
-
|
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(
|
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(
|
590
|
-
expect(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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 =
|
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(
|
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(
|
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(
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
802
|
-
|
803
|
-
|
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 =
|
849
|
-
|
850
|
-
|
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
|
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
|
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 {
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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
|
|
@@ -1073,7 +1083,10 @@ describe Postmark::ApiClient do
|
|
1073
1083
|
{
|
1074
1084
|
:name => 'My Stream',
|
1075
1085
|
:id => 'my-stream',
|
1076
|
-
:message_stream_type => 'Broadcasts'
|
1086
|
+
:message_stream_type => 'Broadcasts',
|
1087
|
+
:subscription_management_configuration => {
|
1088
|
+
:unsubscribe_handling_type => 'Custom'
|
1089
|
+
}
|
1077
1090
|
}
|
1078
1091
|
end
|
1079
1092
|
|
@@ -1083,7 +1096,10 @@ describe Postmark::ApiClient do
|
|
1083
1096
|
'Id' => 'my-stream',
|
1084
1097
|
'MessageStreamType' => 'Broadcasts',
|
1085
1098
|
'ServerId' => 222,
|
1086
|
-
'CreatedAt' => '2020-04-01T03:33:33.333-03:00'
|
1099
|
+
'CreatedAt' => '2020-04-01T03:33:33.333-03:00',
|
1100
|
+
'SubscriptionManagementConfiguration' => {
|
1101
|
+
'UnsubscribeHandlingType' => 'Custom'
|
1102
|
+
}
|
1087
1103
|
}
|
1088
1104
|
end
|
1089
1105
|
|
@@ -1097,7 +1113,10 @@ describe Postmark::ApiClient do
|
|
1097
1113
|
json_representation_of({
|
1098
1114
|
'Name' => 'My Stream',
|
1099
1115
|
'Id' => 'my-stream',
|
1100
|
-
'MessageStreamType' => 'Broadcasts'
|
1116
|
+
'MessageStreamType' => 'Broadcasts',
|
1117
|
+
'SubscriptionManagementConfiguration' => {
|
1118
|
+
'UnsubscribeHandlingType' => 'Custom'
|
1119
|
+
}
|
1101
1120
|
}))
|
1102
1121
|
subject
|
1103
1122
|
end
|
@@ -1108,7 +1127,10 @@ describe Postmark::ApiClient do
|
|
1108
1127
|
:name => 'My Stream',
|
1109
1128
|
:server_id => 222,
|
1110
1129
|
:message_stream_type => 'Broadcasts',
|
1111
|
-
:created_at => '2020-04-01T03:33:33.333-03:00'
|
1130
|
+
:created_at => '2020-04-01T03:33:33.333-03:00',
|
1131
|
+
:subscription_management_configuration => {
|
1132
|
+
:unsubscribe_handling_type => 'Custom'
|
1133
|
+
}
|
1112
1134
|
)
|
1113
1135
|
}
|
1114
1136
|
end
|
@@ -1118,7 +1140,10 @@ describe Postmark::ApiClient do
|
|
1118
1140
|
|
1119
1141
|
let(:attrs) do
|
1120
1142
|
{
|
1121
|
-
:name => 'My Stream XXX'
|
1143
|
+
:name => 'My Stream XXX',
|
1144
|
+
:subscription_management_configuration => {
|
1145
|
+
:unsubscribe_handling_type => 'Custom'
|
1146
|
+
}
|
1122
1147
|
}
|
1123
1148
|
end
|
1124
1149
|
|
@@ -1128,7 +1153,10 @@ describe Postmark::ApiClient do
|
|
1128
1153
|
'Id' => 'xxx',
|
1129
1154
|
'MessageStreamType' => 'Broadcasts',
|
1130
1155
|
'ServerId' => 222,
|
1131
|
-
'CreatedAt' => '2020-04-01T03:33:33.333-03:00'
|
1156
|
+
'CreatedAt' => '2020-04-01T03:33:33.333-03:00',
|
1157
|
+
'SubscriptionManagementConfiguration' => {
|
1158
|
+
'UnsubscribeHandlingType' => 'Custom'
|
1159
|
+
}
|
1132
1160
|
}
|
1133
1161
|
end
|
1134
1162
|
|
@@ -1140,7 +1168,10 @@ describe Postmark::ApiClient do
|
|
1140
1168
|
expect(http_client).to receive(:patch).
|
1141
1169
|
with('message-streams/xxx',
|
1142
1170
|
match_json({
|
1143
|
-
|
1171
|
+
'Name' => 'My Stream XXX',
|
1172
|
+
'SubscriptionManagementConfiguration' => {
|
1173
|
+
'UnsubscribeHandlingType' => 'Custom'
|
1174
|
+
}
|
1144
1175
|
}))
|
1145
1176
|
subject
|
1146
1177
|
end
|
@@ -1151,7 +1182,10 @@ describe Postmark::ApiClient do
|
|
1151
1182
|
:name => 'My Stream XXX',
|
1152
1183
|
:server_id => 222,
|
1153
1184
|
:message_stream_type => 'Broadcasts',
|
1154
|
-
:created_at => '2020-04-01T03:33:33.333-03:00'
|
1185
|
+
:created_at => '2020-04-01T03:33:33.333-03:00',
|
1186
|
+
:subscription_management_configuration => {
|
1187
|
+
:unsubscribe_handling_type => 'Custom'
|
1188
|
+
}
|
1155
1189
|
)
|
1156
1190
|
}
|
1157
1191
|
end
|
@@ -1185,7 +1219,7 @@ describe Postmark::ApiClient do
|
|
1185
1219
|
let(:stream_id) { 'my-stream'}
|
1186
1220
|
let(:server_id) { 123 }
|
1187
1221
|
let(:api_endpoint) { "message-streams/#{stream_id}/unarchive" }
|
1188
|
-
let(:api_response) {
|
1222
|
+
let(:api_response) {
|
1189
1223
|
{ 'ID' => stream_id, 'ServerID' => server_id, 'Name' => 'My Stream',
|
1190
1224
|
'Description' => 'My test stream.', 'MessageStreamType' => 'Transactional',
|
1191
1225
|
'CreatedAt' => '2030-08-30T12:30:00.00-04:00', 'UpdatedAt' => '2030-09-30T12:30:00.00-04:00',
|