postmark 1.13.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3eb03641468ddcbee6aab9cdc449257f5bb309c
4
- data.tar.gz: 19f4463b421ead1daae9e1121a1a24e5a4485c98
3
+ metadata.gz: 512806d8502e950b2372e80998206636f5e4ef57
4
+ data.tar.gz: a39bfc31b589a7356f6f5f719468016fed438406
5
5
  SHA512:
6
- metadata.gz: ad68cc4ef04239f9a222d0a9426e9d0c8b8bdd696741990ff06076e34c8d4e1a9ff1ebaec7f0f2539ddd3b8147fba3c311286988f519b8121aa5ea71e9687a42
7
- data.tar.gz: 356a337ee74c68a196f11110537a2ab525ec4d446e597c32c8df0fb69166e03ef67aa0d317a3904cfe5c00cec39729c78be5c21c654919efa40ef972b395c8ea
6
+ metadata.gz: 2572c526c7de534b5806458c35ff81541641388878e4ac1f8b6d7ce9122f5d05f2f8e08d81de5cedb2a3bfa0e094215a91df3d6b22deac81ef02f6fa4f913be2
7
+ data.tar.gz: fc533f59049c454a5ca0ff4e199c3f7374b964bb24ed1211f7657fc32f4d14d6c4817da4bf9645259da5e5c1e40805492a018f7ce9b41fa04d581baba3be2393
@@ -1,5 +1,11 @@
1
1
  = Changelog
2
2
 
3
+ == 1.14.0
4
+
5
+ * Added support for verifying DKIM/Return-Path.
6
+ * Added support for searching inbound rules.
7
+ * Updated README.
8
+
3
9
  == 1.13.0
4
10
 
5
11
  * Changed default value returned by Mail::Message#metadata to a mutable hash (makes things easier for postmark-rails).
@@ -28,7 +34,7 @@
28
34
 
29
35
  == 1.9.0
30
36
 
31
- * Added methods to access domains API endoints
37
+ * Added methods to access domains API endoints.
32
38
 
33
39
  == 1.8.1
34
40
 
data/README.md CHANGED
@@ -194,7 +194,8 @@ client.deliver(from: 'sheldon@bigbangtheory.com',
194
194
 
195
195
  ## Sending a templated email
196
196
 
197
- If you have a [template created](https://github.com/wildbit/postmark-gem/wiki/The-Templates-API-support) in Postmark you can send an email using that template.
197
+ If you have a [template created](https://github.com/wildbit/postmark-gem/wiki/The-Templates-API-support) in Postmark you can send an email using that template.
198
+ For the purpose of sending emails, you can reference a template by its alias or ID.
198
199
 
199
200
  ``` ruby
200
201
  client.deliver_with_template(from: 'sheldon@bigbangtheory.com',
@@ -208,6 +209,38 @@ client.deliver_with_template(from: 'sheldon@bigbangtheory.com',
208
209
  # => {:to=>"Penny <penny@bigbangtheory.com>", :submitted_at=>"2013-05-09T03:00:55.4454938-04:00", :message_id=>"34aed4b3-3a95-xxxx-bd1d-88064909cc93", :error_code=>0, :message=>"OK"}
209
210
  ```
210
211
 
212
+ Following example shows how to send email using template alias:
213
+
214
+ ``` ruby
215
+ client.deliver_with_template(from: 'sheldon@bigbangtheory.com',
216
+ to: 'Penny <penny@bigbangtheory.com>',
217
+ template_alias: 'bigbangtheory',
218
+ template_model: {
219
+ name: 'Penny',
220
+ message: 'Bazinga!'
221
+ })
222
+
223
+ # => {:to=>"Penny <penny@bigbangtheory.com>", :submitted_at=>"2013-05-09T03:00:55.4454938-04:00", :message_id=>"34aed4b3-3a95-xxxx-bd1d-88064909cc93", :error_code=>0, :message=>"OK"}
224
+ ```
225
+
226
+ ## Sending a templated email in batches
227
+
228
+ ``` ruby
229
+ client.deliver_with_template([{from: 'sheldon@bigbangtheory.com',
230
+ to: 'Penny <penny@bigbangtheory.com>',
231
+ template_alias: 'bigbangtheory',
232
+ template_model: {
233
+ name: 'Penny',
234
+ message: 'Bazinga!'
235
+ }
236
+ },
237
+ {from: 'tom@bigbangtheory.com',
238
+ to: '<sheldon@bigbangtheory.com>',
239
+ template_id: 53,
240
+ template_model: {}
241
+ }])
242
+ ```
243
+
211
244
  ## Sending in batches
212
245
 
213
246
  While Postmark is focused on transactional email, we understand that developers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.13.0
1
+ 1.14.0
@@ -89,6 +89,14 @@ module Postmark
89
89
  format_response http_client.put("domains/#{id.to_i}", data)
90
90
  end
91
91
 
92
+ def verify_domain_dkim(id)
93
+ format_response http_client.put("domains/#{id.to_i}/verifydkim")
94
+ end
95
+
96
+ def verify_domain_return_path(id)
97
+ format_response http_client.put("domains/#{id.to_i}/verifyreturnpath")
98
+ end
99
+
92
100
  def verified_domain_spf?(id)
93
101
  !!http_client.post("domains/#{id.to_i}/verifyspf")['SPFVerified']
94
102
  end
@@ -150,6 +150,7 @@ module Postmark
150
150
  end
151
151
 
152
152
  def create_trigger(type, options)
153
+ type = Postmark::Inflector.to_postmark(type).downcase
153
154
  data = serialize(HashHelper.to_postmark(options))
154
155
  format_response http_client.post("triggers/#{type}", data)
155
156
  end
@@ -164,16 +165,19 @@ module Postmark
164
165
  end
165
166
 
166
167
  def delete_trigger(type, id)
168
+ type = Postmark::Inflector.to_postmark(type).downcase
167
169
  format_response http_client.delete("triggers/#{type}/#{id}")
168
170
  end
169
171
 
170
172
  def get_triggers(type, options = {})
171
- _, batch = load_batch("triggers/#{type}", 'Tags', options)
173
+ type = Postmark::Inflector.to_postmark(type)
174
+ _, batch = load_batch("triggers/#{type.downcase}", type, options)
172
175
  batch
173
176
  end
174
177
 
175
178
  def triggers(type, options = {})
176
- find_each("triggers/#{type}", 'Tags', options)
179
+ type = Postmark::Inflector.to_postmark(type)
180
+ find_each("triggers/#{type.downcase}", type, options)
177
181
  end
178
182
 
179
183
  def server_info
@@ -258,13 +262,10 @@ module Postmark
258
262
 
259
263
  def get_stats_counts(stat, options = {})
260
264
  url = "stats/outbound/#{stat}"
261
-
262
265
  url << "/#{options[:type]}" if options.has_key?(:type)
263
266
 
264
267
  response = format_response(http_client.get(url, options))
265
-
266
268
  response[:days].map! { |d| HashHelper.to_ruby(d) }
267
-
268
269
  response
269
270
  end
270
271
 
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.13.0'
2
+ VERSION = '1.14.0'
3
3
  end
@@ -1,14 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Postmark::ApiClient do
4
-
5
- let(:api_token) { "provided-api-token" }
6
- let(:max_retries) { 42 }
7
- let(:message_hash) {
8
- {
9
- :from => "support@postmarkapp.com"
10
- }
11
- }
4
+ let(:api_token) {"provided-api-token"}
5
+ let(:max_retries) {42}
6
+ let(:message_hash) {{:from => "support@postmarkapp.com"}}
12
7
  let(:message) {
13
8
  Mail.new do
14
9
  from "support@postmarkapp.com"
@@ -16,37 +11,30 @@ describe Postmark::ApiClient do
16
11
  end
17
12
  }
18
13
 
19
- let(:api_client) { Postmark::ApiClient.new(api_token) }
20
- subject { api_client }
14
+ let(:api_client) {Postmark::ApiClient.new(api_token)}
15
+ subject {api_client}
21
16
 
22
17
  context "attr readers" do
23
- it { should respond_to(:http_client) }
24
- it { should respond_to(:max_retries) }
18
+ it {should respond_to(:http_client)}
19
+ it {should respond_to(:max_retries)}
25
20
  end
26
21
 
27
22
  context "when it's created without options" do
28
-
29
- its(:max_retries) { should eq 3 }
30
-
23
+ its(:max_retries) {should eq 3}
31
24
  end
32
25
 
33
26
  context "when it's created with user options" do
34
-
35
- subject { Postmark::ApiClient.new(api_token, :max_retries => max_retries,
36
- :foo => :bar)}
37
-
38
- its(:max_retries) { should eq max_retries }
27
+ subject {Postmark::ApiClient.new(api_token, :max_retries => max_retries, :foo => :bar)}
28
+ its(:max_retries) {should eq max_retries}
39
29
 
40
30
  it 'passes other options to HttpClient instance' do
41
31
  allow(Postmark::HttpClient).to receive(:new).with(api_token, :foo => :bar)
42
32
  subject.should be
43
33
  end
44
-
45
34
  end
46
35
 
47
36
  describe "#api_token=" do
48
-
49
- let(:api_token) { "new-api-token-value" }
37
+ let(:api_token) {"new-api-token-value"}
50
38
 
51
39
  it 'assigns the api token to the http client instance' do
52
40
  subject.api_token = api_token
@@ -57,56 +45,55 @@ describe Postmark::ApiClient do
57
45
  subject.api_key = api_token
58
46
  subject.http_client.api_token.should == api_token
59
47
  end
60
-
61
48
  end
62
49
 
63
50
  describe "#deliver" do
64
- let(:email) { Postmark::MessageHelper.to_postmark(message_hash) }
65
- let(:email_json) { Postmark::Json.encode(email) }
66
- let(:http_client) { subject.http_client }
67
- let(:response) { {"MessageID" => 42} }
51
+ let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
52
+ let(:email_json) {Postmark::Json.encode(email)}
53
+ let(:http_client) {subject.http_client}
54
+ let(:response) {{"MessageID" => 42}}
68
55
 
69
56
  it 'converts message hash to Postmark format and posts it to /email' do
70
- allow(http_client).to receive(:post).with('email', email_json) { response }
57
+ allow(http_client).to receive(:post).with('email', email_json) {response}
71
58
  subject.deliver(message_hash)
72
59
  end
73
60
 
74
61
  it 'retries 3 times' do
75
62
  expect(http_client).to receive(:post).twice.and_raise(Postmark::InternalServerError)
76
- expect(http_client).to receive(:post) { response }
77
- expect { subject.deliver(message_hash) }.not_to raise_error
63
+ expect(http_client).to receive(:post) {response}
64
+ expect {subject.deliver(message_hash)}.not_to raise_error
78
65
  end
79
66
 
80
67
  it 'converts response to ruby format' do
81
- expect(http_client).to receive(:post).with('email', email_json) { response }
68
+ expect(http_client).to receive(:post).with('email', email_json) {response}
82
69
  r = subject.deliver(message_hash)
83
70
  r.should have_key(:message_id)
84
71
  end
85
72
  end
86
73
 
87
74
  describe "#deliver_in_batches" do
88
- let(:email) { Postmark::MessageHelper.to_postmark(message_hash) }
89
- let(:emails) { [email, email, email] }
90
- let(:emails_json) { Postmark::Json.encode(emails) }
91
- let(:http_client) { subject.http_client }
92
- let(:response) { [{'ErrorCode' => 0}, {'ErrorCode' => 0}, {'ErrorCode' => 0}] }
75
+ let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
76
+ let(:emails) {[email, email, email]}
77
+ let(:emails_json) {Postmark::Json.encode(emails)}
78
+ let(:http_client) {subject.http_client}
79
+ let(:response) {[{'ErrorCode' => 0}, {'ErrorCode' => 0}, {'ErrorCode' => 0}]}
93
80
 
94
81
  it 'turns array of messages into a JSON document and posts it to /email/batch' do
95
- expect(http_client).to receive(:post).with('email/batch', emails_json) { response }
82
+ expect(http_client).to receive(:post).with('email/batch', emails_json) {response}
96
83
  subject.deliver_in_batches([message_hash, message_hash, message_hash])
97
84
  end
98
85
 
99
86
  it 'converts response to ruby format' do
100
- expect(http_client).to receive(:post).with('email/batch', emails_json) { response }
87
+ expect(http_client).to receive(:post).with('email/batch', emails_json) {response}
101
88
  response = subject.deliver_in_batches([message_hash, message_hash, message_hash])
102
89
  response.first.should have_key(:error_code)
103
90
  end
104
91
  end
105
92
 
106
93
  describe "#deliver_message" do
107
- let(:email) { message.to_postmark_hash }
108
- let(:email_json) { Postmark::Json.encode(email) }
109
- let(:http_client) { subject.http_client }
94
+ let(:email) {message.to_postmark_hash}
95
+ let(:email_json) {Postmark::Json.encode(email)}
96
+ let(:http_client) {subject.http_client}
110
97
 
111
98
  it 'turns message into a JSON document and posts it to /email' do
112
99
  expect(http_client).to receive(:post).with('email', email_json)
@@ -118,32 +105,31 @@ describe Postmark::ApiClient do
118
105
  expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
119
106
  end
120
107
  expect(http_client).to receive(:post)
121
- expect { subject.deliver_message(message) }.not_to raise_error
108
+ expect {subject.deliver_message(message)}.not_to raise_error
122
109
  end
123
110
 
124
111
  it "retries on timeout" do
125
112
  expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
126
113
  expect(http_client).to receive(:post)
127
- expect { subject.deliver_message(message) }.not_to raise_error
114
+ expect {subject.deliver_message(message)}.not_to raise_error
128
115
  end
129
116
 
130
117
  it "proxies errors" do
131
118
  allow(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
132
- expect { subject.deliver_message(message) }.to raise_error(Postmark::TimeoutError)
119
+ expect {subject.deliver_message(message)}.to raise_error(Postmark::TimeoutError)
133
120
  end
134
121
 
135
122
  end
136
123
 
137
124
  describe "#deliver_messages" do
138
-
139
- let(:email) { message.to_postmark_hash }
140
- let(:emails) { [email, email, email] }
141
- let(:emails_json) { Postmark::Json.encode(emails) }
142
- let(:http_client) { subject.http_client }
143
- let(:response) { [{}, {}, {}] }
125
+ let(:email) {message.to_postmark_hash}
126
+ let(:emails) {[email, email, email]}
127
+ let(:emails_json) {Postmark::Json.encode(emails)}
128
+ let(:http_client) {subject.http_client}
129
+ let(:response) {[{}, {}, {}]}
144
130
 
145
131
  it 'turns array of messages into a JSON document and posts it to /email/batch' do
146
- expect(http_client).to receive(:post).with('email/batch', emails_json) { response }
132
+ expect(http_client).to receive(:post).with('email/batch', emails_json) {response}
147
133
  subject.deliver_messages([message, message, message])
148
134
  end
149
135
 
@@ -151,36 +137,31 @@ describe Postmark::ApiClient do
151
137
  2.times do
152
138
  expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
153
139
  end
154
- expect(http_client).to receive(:post) { response }
155
- expect { subject.deliver_messages([message, message, message]) }.not_to raise_error
140
+ expect(http_client).to receive(:post) {response}
141
+ expect {subject.deliver_messages([message, message, message])}.not_to raise_error
156
142
  end
157
143
 
158
144
  it "should retry on timeout" do
159
145
  expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
160
- expect(http_client).to receive(:post) { response }
161
- expect { subject.deliver_messages([message, message, message]) }.not_to raise_error
146
+ expect(http_client).to receive(:post) {response}
147
+ expect {subject.deliver_messages([message, message, message])}.not_to raise_error
162
148
  end
163
149
 
164
150
  end
165
151
 
166
152
  describe "#delivery_stats" do
167
- let(:http_client) { subject.http_client }
168
- let(:response) { {"Bounces" => [{"Foo" => "Bar"}]} }
153
+ let(:http_client) {subject.http_client}
154
+ let(:response) {{"Bounces" => [{"Foo" => "Bar"}]}}
169
155
 
170
156
  it 'requests data at /deliverystats' do
171
- expect(http_client).to receive(:get).with("deliverystats") { response }
157
+ expect(http_client).to receive(:get).with("deliverystats") {response}
172
158
  subject.delivery_stats.should have_key(:bounces)
173
159
  end
174
160
  end
175
161
 
176
162
  describe '#messages' do
177
-
178
163
  context 'given outbound' do
179
-
180
- let(:response) {
181
- {'TotalCount' => 5,
182
- 'Messages' => [{}].cycle(5).to_a}
183
- }
164
+ let(:response) {{'TotalCount' => 5, 'Messages' => [{}].cycle(5).to_a}}
184
165
 
185
166
  it 'returns an enumerator' do
186
167
  expect(subject.messages).to be_kind_of(Enumerable)
@@ -191,15 +172,10 @@ describe Postmark::ApiClient do
191
172
  with('messages/outbound', an_instance_of(Hash)).and_return(response)
192
173
  expect(subject.messages.count).to eq(5)
193
174
  end
194
-
195
175
  end
196
176
 
197
177
  context 'given inbound' do
198
-
199
- let(:response) {
200
- {'TotalCount' => 5,
201
- 'InboundMessages' => [{}].cycle(5).to_a}
202
- }
178
+ let(:response) {{'TotalCount' => 5, 'InboundMessages' => [{}].cycle(5).to_a}}
203
179
 
204
180
  it 'returns an enumerator' do
205
181
  expect(subject.messages(:inbound => true)).to be_kind_of(Enumerable)
@@ -216,37 +192,36 @@ describe Postmark::ApiClient do
216
192
  end
217
193
 
218
194
  describe '#get_messages' do
219
- let(:http_client) { subject.http_client }
195
+ let(:http_client) {subject.http_client}
220
196
 
221
197
  context 'given outbound' do
222
- let(:response) { {"TotalCount" => 1, "Messages" => [{}]} }
198
+ let(:response) {{"TotalCount" => 1, "Messages" => [{}]}}
223
199
 
224
200
  it 'requests data at /messages/outbound' do
225
201
  expect(http_client).to receive(:get).
226
- with('messages/outbound', :offset => 50, :count => 50).
227
- and_return(response)
202
+ with('messages/outbound', :offset => 50, :count => 50).
203
+ and_return(response)
228
204
  subject.get_messages(:offset => 50, :count => 50)
229
205
  end
230
206
 
231
207
  end
232
208
 
233
209
  context 'given inbound' do
234
- let(:response) { {"TotalCount" => 1, "InboundMessages" => [{}]} }
210
+ let(:response) {{"TotalCount" => 1, "InboundMessages" => [{}]}}
235
211
 
236
212
  it 'requests data at /messages/inbound' do
237
213
  expect(http_client).to receive(:get).
238
- with('messages/inbound', :offset => 50, :count => 50).
239
- and_return(response)
214
+ with('messages/inbound', :offset => 50, :count => 50).
215
+ and_return(response)
240
216
  subject.get_messages(:inbound => true, :offset => 50, :count => 50).
241
- should be_an(Array)
217
+ should be_an(Array)
242
218
  end
243
219
 
244
220
  end
245
221
  end
246
222
 
247
223
  describe '#get_messages_count' do
248
-
249
- let(:response) { {'TotalCount' => 42} }
224
+ let(:response) {{'TotalCount' => 42}}
250
225
 
251
226
  context 'given outbound' do
252
227
 
@@ -260,75 +235,66 @@ describe Postmark::ApiClient do
260
235
  end
261
236
 
262
237
  context 'given inbound' do
263
-
264
238
  it 'requests and returns inbound messages count' do
265
239
  allow(subject.http_client).to receive(:get).
266
240
  with('messages/inbound', an_instance_of(Hash)).and_return(response)
267
241
  expect(subject.get_messages_count(:inbound => true)).to eq(42)
268
242
  end
269
-
270
243
  end
271
244
 
272
245
  end
273
246
 
274
247
  describe '#get_message' do
275
- let(:id) { '8ad0e8b0-xxxx-xxxx-951d-223c581bb467' }
276
- let(:http_client) { subject.http_client }
277
- let(:response) { {"To" => "leonard@bigbangtheory.com"} }
248
+ let(:id) {'8ad0e8b0-xxxx-xxxx-951d-223c581bb467'}
249
+ let(:http_client) {subject.http_client}
250
+ let(:response) {{"To" => "leonard@bigbangtheory.com"}}
278
251
 
279
252
  context 'given outbound' do
280
-
281
253
  it 'requests a single message by id at /messages/outbound/:id/details' do
282
254
  expect(http_client).to receive(:get).
283
- with("messages/outbound/#{id}/details", {}).
284
- and_return(response)
255
+ with("messages/outbound/#{id}/details", {}).
256
+ and_return(response)
285
257
  subject.get_message(id).should have_key(:to)
286
258
  end
287
-
288
259
  end
289
260
 
290
261
  context 'given inbound' do
291
-
292
262
  it 'requests a single message by id at /messages/inbound/:id/details' do
293
263
  expect(http_client).to receive(:get).
294
- with("messages/inbound/#{id}/details", {}).
295
- and_return(response)
264
+ with("messages/inbound/#{id}/details", {}).
265
+ and_return(response)
296
266
  subject.get_message(id, :inbound => true).should have_key(:to)
297
267
  end
298
-
299
268
  end
300
269
  end
301
270
 
302
271
  describe '#dump_message' do
303
- let(:id) { '8ad0e8b0-xxxx-xxxx-951d-223c581bb467' }
304
- let(:http_client) { subject.http_client }
305
- let(:response) { {"Body" => "From: <leonard@bigbangtheory.com> \r\n ..."} }
272
+ let(:id) {'8ad0e8b0-xxxx-xxxx-951d-223c581bb467'}
273
+ let(:http_client) {subject.http_client}
274
+ let(:response) {{"Body" => "From: <leonard@bigbangtheory.com> \r\n ..."}}
306
275
 
307
276
  context 'given outbound' do
308
277
 
309
278
  it 'requests a single message by id at /messages/outbound/:id/dump' do
310
279
  expect(http_client).to receive(:get).
311
- with("messages/outbound/#{id}/dump", {}).
312
- and_return(response)
280
+ with("messages/outbound/#{id}/dump", {}).
281
+ and_return(response)
313
282
  subject.dump_message(id).should have_key(:body)
314
283
  end
315
284
 
316
285
  end
317
286
 
318
287
  context 'given inbound' do
319
-
320
288
  it 'requests a single message by id at /messages/inbound/:id/dump' do
321
289
  expect(http_client).to receive(:get).
322
- with("messages/inbound/#{id}/dump", {}).
323
- and_return(response)
290
+ with("messages/inbound/#{id}/dump", {}).
291
+ and_return(response)
324
292
  subject.dump_message(id, :inbound => true).should have_key(:body)
325
293
  end
326
-
327
294
  end
328
295
  end
329
296
 
330
297
  describe '#bounces' do
331
-
332
298
  it 'returns an Enumerator' do
333
299
  expect(subject.bounces).to be_kind_of(Enumerable)
334
300
  end
@@ -339,23 +305,22 @@ describe Postmark::ApiClient do
339
305
  and_return('TotalCount' => 1, 'Bounces' => [{}])
340
306
  expect(subject.bounces.first(5).count).to eq(1)
341
307
  end
342
-
343
308
  end
344
309
 
345
310
  describe "#get_bounces" do
346
- let(:http_client) { subject.http_client }
347
- let(:options) { {:foo => :bar} }
348
- let(:response) { {"Bounces" => []} }
311
+ let(:http_client) {subject.http_client}
312
+ let(:options) {{:foo => :bar}}
313
+ let(:response) {{"Bounces" => []}}
349
314
 
350
315
  it 'requests data at /bounces' do
351
- allow(http_client).to receive(:get).with("bounces", options) { response }
316
+ allow(http_client).to receive(:get).with("bounces", options) {response}
352
317
  expect(subject.get_bounces(options)).to be_an(Array)
353
318
  expect(subject.get_bounces(options).count).to be_zero
354
319
  end
355
320
  end
356
321
 
357
322
  describe "#get_bounced_tags" do
358
- let(:http_client) { subject.http_client }
323
+ let(:http_client) {subject.http_client}
359
324
 
360
325
  it 'requests data at /bounces/tags' do
361
326
  expect(http_client).to receive(:get).with("bounces/tags")
@@ -364,8 +329,8 @@ describe Postmark::ApiClient do
364
329
  end
365
330
 
366
331
  describe "#get_bounce" do
367
- let(:http_client) { subject.http_client }
368
- let(:id) { 42 }
332
+ let(:http_client) {subject.http_client}
333
+ let(:id) {42}
369
334
 
370
335
  it 'requests a single bounce by ID at /bounces/:id' do
371
336
  expect(http_client).to receive(:get).with("bounces/#{id}")
@@ -374,8 +339,8 @@ describe Postmark::ApiClient do
374
339
  end
375
340
 
376
341
  describe "#dump_bounce" do
377
- let(:http_client) { subject.http_client }
378
- let(:id) { 42 }
342
+ let(:http_client) {subject.http_client}
343
+ let(:id) {42}
379
344
 
380
345
  it 'requests a specific bounce data at /bounces/:id/dump' do
381
346
  expect(http_client).to receive(:get).with("bounces/#{id}/dump")
@@ -384,18 +349,17 @@ describe Postmark::ApiClient do
384
349
  end
385
350
 
386
351
  describe "#activate_bounce" do
387
- let(:http_client) { subject.http_client }
388
- let(:id) { 42 }
389
- let(:response) { {"Bounce" => {}} }
352
+ let(:http_client) {subject.http_client}
353
+ let(:id) {42}
354
+ let(:response) {{"Bounce" => {}}}
390
355
 
391
356
  it 'activates a specific bounce by sending a PUT request to /bounces/:id/activate' do
392
- expect(http_client).to receive(:put).with("bounces/#{id}/activate") { response }
357
+ expect(http_client).to receive(:put).with("bounces/#{id}/activate") {response}
393
358
  subject.activate_bounce(id)
394
359
  end
395
360
  end
396
361
 
397
362
  describe '#opens' do
398
-
399
363
  it 'returns an Enumerator' do
400
364
  expect(subject.opens).to be_kind_of(Enumerable)
401
365
  end
@@ -406,7 +370,6 @@ describe Postmark::ApiClient do
406
370
  and_return('TotalCount' => 1, 'Opens' => [{}])
407
371
  expect(subject.opens.first(5).count).to eq(1)
408
372
  end
409
-
410
373
  end
411
374
 
412
375
  describe '#clicks' do
@@ -423,63 +386,63 @@ describe Postmark::ApiClient do
423
386
  end
424
387
 
425
388
  describe '#get_opens' do
426
- let(:http_client) { subject.http_client }
427
- let(:options) { {:offset => 5} }
428
- let(:response) { {'Opens' => [], 'TotalCount' => 0} }
389
+ let(:http_client) {subject.http_client}
390
+ let(:options) {{:offset => 5}}
391
+ let(:response) {{'Opens' => [], 'TotalCount' => 0}}
429
392
 
430
393
  it 'performs a GET request to /messages/outbound/opens' do
431
- allow(http_client).to receive(:get).with('messages/outbound/opens', options) { response }
394
+ allow(http_client).to receive(:get).with('messages/outbound/opens', options) {response}
432
395
  expect(subject.get_opens(options)).to be_an(Array)
433
396
  expect(subject.get_opens(options).count).to be_zero
434
397
  end
435
398
  end
436
399
 
437
400
  describe '#get_clicks' do
438
- let(:http_client) { subject.http_client }
439
- let(:options) { {:offset => 5} }
440
- let(:response) { {'Clicks' => [], 'TotalCount' => 0} }
401
+ let(:http_client) {subject.http_client}
402
+ let(:options) {{:offset => 5}}
403
+ let(:response) {{'Clicks' => [], 'TotalCount' => 0}}
441
404
 
442
405
  it 'performs a GET request to /messages/outbound/clicks' do
443
- allow(http_client).to receive(:get).with('messages/outbound/clicks', options) { response }
406
+ allow(http_client).to receive(:get).with('messages/outbound/clicks', options) {response}
444
407
  expect(subject.get_clicks(options)).to be_an(Array)
445
408
  expect(subject.get_clicks(options).count).to be_zero
446
409
  end
447
410
  end
448
411
 
449
412
  describe '#get_opens_by_message_id' do
450
- let(:http_client) { subject.http_client }
451
- let(:message_id) { 42 }
452
- let(:options) { {:offset => 5} }
453
- let(:response) { {'Opens' => [], 'TotalCount' => 0} }
413
+ let(:http_client) {subject.http_client}
414
+ let(:message_id) {42}
415
+ let(:options) {{:offset => 5}}
416
+ let(:response) {{'Opens' => [], 'TotalCount' => 0}}
454
417
 
455
418
  it 'performs a GET request to /messages/outbound/opens' do
456
419
  allow(http_client).
457
420
  to receive(:get).with("messages/outbound/opens/#{message_id}",
458
421
  options).
459
- and_return(response)
422
+ and_return(response)
460
423
  expect(subject.get_opens_by_message_id(message_id, options)).to be_an(Array)
461
424
  expect(subject.get_opens_by_message_id(message_id, options).count).to be_zero
462
425
  end
463
426
  end
464
427
 
465
428
  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} }
429
+ let(:http_client) {subject.http_client}
430
+ let(:message_id) {42}
431
+ let(:options) {{:offset => 5}}
432
+ let(:response) {{'Clicks' => [], 'TotalCount' => 0}}
470
433
 
471
434
  it 'performs a GET request to /messages/outbound/clicks' do
472
435
  allow(http_client).
473
436
  to receive(:get).with("messages/outbound/clicks/#{message_id}",
474
437
  options).
475
- and_return(response)
438
+ and_return(response)
476
439
  expect(subject.get_clicks_by_message_id(message_id, options)).to be_an(Array)
477
440
  expect(subject.get_clicks_by_message_id(message_id, options).count).to be_zero
478
441
  end
479
442
  end
480
443
 
481
444
  describe '#opens_by_message_id' do
482
- let(:message_id) { 42 }
445
+ let(:message_id) {42}
483
446
 
484
447
  it 'returns an Enumerator' do
485
448
  expect(subject.opens_by_message_id(message_id)).to be_kind_of(Enumerable)
@@ -494,7 +457,7 @@ describe Postmark::ApiClient do
494
457
  end
495
458
 
496
459
  describe '#clicks_by_message_id' do
497
- let(:message_id) { 42 }
460
+ let(:message_id) {42}
498
461
 
499
462
  it 'returns an Enumerator' do
500
463
  expect(subject.clicks_by_message_id(message_id)).to be_kind_of(Enumerable)
@@ -509,25 +472,44 @@ describe Postmark::ApiClient do
509
472
  end
510
473
 
511
474
  describe '#create_trigger' do
512
- let(:http_client) { subject.http_client }
513
- let(:options) { {:foo => 'bar'} }
514
- let(:response) { {'Foo' => 'Bar'} }
475
+ let(:http_client) {subject.http_client}
515
476
 
516
- it 'performs a POST request to /triggers/tags with given options' do
517
- allow(http_client).to receive(:post).with('triggers/tags',
518
- {'Foo' => 'bar'}.to_json)
519
- subject.create_trigger(:tags, options)
477
+ context 'tags' do
478
+ let(:options) {{:foo => 'bar'}}
479
+ let(:response) {{'Foo' => 'Bar'}}
480
+
481
+ it 'performs a POST request to /triggers/tags with given options' do
482
+ allow(http_client).to receive(:post).with('triggers/tags',
483
+ {'Foo' => 'bar'}.to_json)
484
+ subject.create_trigger(:tags, options)
485
+ end
486
+
487
+ it 'symbolizes response keys' do
488
+ allow(http_client).to receive(:post).and_return(response)
489
+ expect(subject.create_trigger(:tags, options)).to eq(:foo => 'Bar')
490
+ end
520
491
  end
521
492
 
522
- it 'symbolizes response keys' do
523
- allow(http_client).to receive(:post).and_return(response)
524
- expect(subject.create_trigger(:tags, options)).to eq(:foo => 'Bar')
493
+ context 'inbound rules' do
494
+ let(:options) {{:rule => 'example.com'}}
495
+ let(:response) {{'Rule' => 'example.com'}}
496
+
497
+ it 'performs a POST request to /triggers/inboundrules with given options' do
498
+ allow(http_client).to receive(:post).with('triggers/inboundrules',
499
+ {'Rule' => 'example.com'}.to_json)
500
+ subject.create_trigger(:inbound_rules, options)
501
+ end
502
+
503
+ it 'symbolizes response keys' do
504
+ allow(http_client).to receive(:post).and_return(response)
505
+ expect(subject.create_trigger(:inbound_rules, options)).to eq(:rule => 'example.com')
506
+ end
525
507
  end
526
508
  end
527
509
 
528
510
  describe '#get_trigger' do
529
- let(:http_client) { subject.http_client }
530
- let(:id) { 42 }
511
+ let(:http_client) {subject.http_client}
512
+ let(:id) {42}
531
513
 
532
514
  it 'performs a GET request to /triggers/tags/:id' do
533
515
  allow(http_client).to receive(:get).with("triggers/tags/#{id}")
@@ -541,9 +523,9 @@ describe Postmark::ApiClient do
541
523
  end
542
524
 
543
525
  describe '#update_trigger' do
544
- let(:http_client) { subject.http_client }
545
- let(:options) { {:foo => 'bar'} }
546
- let(:id) { 42 }
526
+ let(:http_client) {subject.http_client}
527
+ let(:options) {{:foo => 'bar'}}
528
+ let(:id) {42}
547
529
 
548
530
  it 'performs a PUT request to /triggers/tags/:id' do
549
531
  allow(http_client).to receive(:put).with("triggers/tags/#{id}",
@@ -558,34 +540,63 @@ describe Postmark::ApiClient do
558
540
  end
559
541
 
560
542
  describe '#delete_trigger' do
561
- let(:http_client) { subject.http_client }
562
- let(:id) { 42 }
543
+ let(:http_client) {subject.http_client}
544
+
545
+ context 'tags' do
546
+ let(:id) {42}
547
+
548
+ it 'performs a DELETE request to /triggers/tags/:id' do
549
+ allow(http_client).to receive(:delete).with("triggers/tags/#{id}")
550
+ subject.delete_trigger(:tags, id)
551
+ end
563
552
 
564
- it 'performs a DELETE request to /triggers/tags/:id' do
565
- allow(http_client).to receive(:delete).with("triggers/tags/#{id}")
566
- subject.delete_trigger(:tags, id)
553
+ it 'symbolizes response keys' do
554
+ allow(http_client).to receive(:delete).and_return('Foo' => 'Bar')
555
+ expect(subject.delete_trigger(:tags, id)).to eq(:foo => 'Bar')
556
+ end
567
557
  end
558
+
559
+ context 'inbound rules' do
560
+ let(:id) {42}
568
561
 
569
- it 'symbolizes response keys' do
570
- allow(http_client).to receive(:delete).and_return('Foo' => 'Bar')
571
- expect(subject.delete_trigger(:tags, id)).to eq(:foo => 'Bar')
562
+ it 'performs a DELETE request to /triggers/inboundrules/:id' do
563
+ allow(http_client).to receive(:delete).with("triggers/inboundrules/#{id}")
564
+ subject.delete_trigger(:inbound_rules, id)
565
+ end
566
+
567
+ it 'symbolizes response keys' do
568
+ allow(http_client).to receive(:delete).and_return('Rule' => 'example.com')
569
+ expect(subject.delete_trigger(:tags, id)).to eq(:rule => 'example.com')
570
+ end
572
571
  end
573
572
  end
574
573
 
575
574
  describe '#get_triggers' do
576
- let(:http_client) { subject.http_client }
577
- let(:options) { {:offset => 5} }
578
- let(:response) { {'Tags' => [], 'TotalCount' => 0} }
575
+ let(:http_client) {subject.http_client}
576
+ let(:options) {{:offset => 5}}
579
577
 
580
- it 'performs a GET request to /triggers/tags' do
581
- allow(http_client).to receive(:get).with('triggers/tags', options) { response }
582
- expect(subject.get_triggers(:tags, options)).to be_an(Array)
583
- expect(subject.get_triggers(:tags, options).count).to be_zero
578
+ context 'tags' do
579
+ let(:response) {{'Tags' => [], 'TotalCount' => 0}}
580
+
581
+ it 'performs a GET request to /triggers/tags' do
582
+ allow(http_client).to receive(:get).with('triggers/tags', options) {response}
583
+ expect(subject.get_triggers(:tags, options)).to be_an(Array)
584
+ expect(subject.get_triggers(:tags, options).count).to be_zero
585
+ end
586
+ end
587
+
588
+ context 'inbound rules' do
589
+ let(:response) {{'InboundRules' => [], 'TotalCount' => 0}}
590
+
591
+ it 'performs a GET request to /triggers/inboundrules' do
592
+ allow(http_client).to receive(:get).with('triggers/inboundrules', options) {response}
593
+ expect(subject.get_triggers(:inbound_rules, options)).to be_an(Array)
594
+ expect(subject.get_triggers(:inbound_rules, options).count).to be_zero
595
+ end
584
596
  end
585
597
  end
586
598
 
587
599
  describe '#triggers' do
588
-
589
600
  it 'returns an Enumerator' do
590
601
  expect(subject.triggers(:tags)).to be_kind_of(Enumerable)
591
602
  end
@@ -596,53 +607,52 @@ describe Postmark::ApiClient do
596
607
  and_return('TotalCount' => 1, 'Tags' => [{}])
597
608
  expect(subject.triggers(:tags).first(5).count).to eq(1)
598
609
  end
599
-
600
610
  end
601
611
 
602
612
  describe "#server_info" do
603
- let(:http_client) { subject.http_client }
604
- let(:response) { {"Name" => "Testing",
605
- "Color" => "blue",
606
- "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
607
- "SmtpApiActivated" => true} }
613
+ let(:http_client) {subject.http_client}
614
+ let(:response) {{"Name" => "Testing",
615
+ "Color" => "blue",
616
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
617
+ "SmtpApiActivated" => true}}
608
618
 
609
619
  it 'requests server info from Postmark and converts it to ruby format' do
610
- expect(http_client).to receive(:get).with('server') { response }
620
+ expect(http_client).to receive(:get).with('server') {response}
611
621
  subject.server_info.should have_key(:inbound_hash)
612
622
  end
613
623
  end
614
624
 
615
625
  describe "#update_server_info" do
616
- let(:http_client) { subject.http_client }
617
- let(:response) { {"Name" => "Testing",
618
- "Color" => "blue",
619
- "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
620
- "SmtpApiActivated" => false} }
621
- let(:update) { {:smtp_api_activated => false} }
626
+ let(:http_client) {subject.http_client}
627
+ let(:response) {{"Name" => "Testing",
628
+ "Color" => "blue",
629
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
630
+ "SmtpApiActivated" => false}}
631
+ let(:update) {{:smtp_api_activated => false}}
622
632
 
623
633
  it 'updates server info in Postmark and converts it to ruby format' do
624
- expect(http_client).to receive(:put).with('server', anything) { response }
634
+ expect(http_client).to receive(:put).with('server', anything) {response}
625
635
  subject.update_server_info(update)[:smtp_api_activated].should be false
626
636
  end
627
637
  end
628
638
 
629
639
  describe '#get_templates' do
630
- let(:http_client) { subject.http_client }
640
+ let(:http_client) {subject.http_client}
631
641
  let(:response) do
632
642
  {
633
- 'TotalCount' => 31,
634
- 'Templates' => [
635
- {
636
- 'Active' => true,
637
- 'TemplateId' => 123,
638
- 'Name' => 'ABC'
639
- },
640
- {
641
- 'Active' => true,
642
- 'TemplateId' => 456,
643
- 'Name' => 'DEF'
644
- }
645
- ]
643
+ 'TotalCount' => 31,
644
+ 'Templates' => [
645
+ {
646
+ 'Active' => true,
647
+ 'TemplateId' => 123,
648
+ 'Name' => 'ABC'
649
+ },
650
+ {
651
+ 'Active' => true,
652
+ 'TemplateId' => 456,
653
+ 'Name' => 'DEF'
654
+ }
655
+ ]
646
656
  }
647
657
  end
648
658
 
@@ -671,16 +681,16 @@ describe Postmark::ApiClient do
671
681
  end
672
682
 
673
683
  describe '#get_template' do
674
- let(:http_client) { subject.http_client }
684
+ let(:http_client) {subject.http_client}
675
685
  let(:response) do
676
686
  {
677
- 'Name' => 'Template Name',
678
- 'TemplateId' => 123,
679
- 'Subject' => 'Subject',
680
- 'HtmlBody' => 'Html',
681
- 'TextBody' => 'Text',
682
- 'AssociatedServerId' => 456,
683
- 'Active' => true
687
+ 'Name' => 'Template Name',
688
+ 'TemplateId' => 123,
689
+ 'Subject' => 'Subject',
690
+ 'HtmlBody' => 'Html',
691
+ 'TextBody' => 'Text',
692
+ 'AssociatedServerId' => 456,
693
+ 'Active' => true
684
694
  }
685
695
  end
686
696
 
@@ -696,17 +706,17 @@ describe Postmark::ApiClient do
696
706
  end
697
707
 
698
708
  describe '#create_template' do
699
- let(:http_client) { subject.http_client }
709
+ let(:http_client) {subject.http_client}
700
710
  let(:response) do
701
711
  {
702
- 'TemplateId' => 123,
703
- 'Name' => 'template name',
704
- 'Active' => true
712
+ 'TemplateId' => 123,
713
+ 'Name' => 'template name',
714
+ 'Active' => true
705
715
  }
706
716
  end
707
717
 
708
718
  it 'performs a POST request to /templates with the given attributes' do
709
- expected_json = { 'Name' => 'template name' }.to_json
719
+ expected_json = {'Name' => 'template name'}.to_json
710
720
 
711
721
  expect(http_client).to receive(:post).with('templates', expected_json).and_return(response)
712
722
 
@@ -718,17 +728,17 @@ describe Postmark::ApiClient do
718
728
  end
719
729
 
720
730
  describe '#update_template' do
721
- let(:http_client) { subject.http_client }
731
+ let(:http_client) {subject.http_client}
722
732
  let(:response) do
723
733
  {
724
- 'TemplateId' => 123,
725
- 'Name' => 'template name',
726
- 'Active' => true
734
+ 'TemplateId' => 123,
735
+ 'Name' => 'template name',
736
+ 'Active' => true
727
737
  }
728
738
  end
729
739
 
730
740
  it 'performs a PUT request to /templates with the given attributes' do
731
- expected_json = { 'Name' => 'template name' }.to_json
741
+ expected_json = {'Name' => 'template name'}.to_json
732
742
 
733
743
  expect(http_client).to receive(:put).with('templates/123', expected_json).and_return(response)
734
744
 
@@ -740,11 +750,11 @@ describe Postmark::ApiClient do
740
750
  end
741
751
 
742
752
  describe '#delete_template' do
743
- let(:http_client) { subject.http_client }
753
+ let(:http_client) {subject.http_client}
744
754
  let(:response) do
745
755
  {
746
- 'ErrorCode' => 0,
747
- 'Message' => 'Template 123 removed.'
756
+ 'ErrorCode' => 0,
757
+ 'Message' => 'Template 123 removed.'
748
758
  }
749
759
  end
750
760
 
@@ -758,38 +768,38 @@ describe Postmark::ApiClient do
758
768
  end
759
769
 
760
770
  describe '#validate_template' do
761
- let(:http_client) { subject.http_client }
771
+ let(:http_client) {subject.http_client}
762
772
 
763
773
  context 'when template is valid' do
764
774
  let(:response) do
765
775
  {
766
- 'AllContentIsValid' => true,
767
- 'HtmlBody' => {
768
- 'ContentIsValid' => true,
769
- 'ValidationErrors' => [],
770
- 'RenderedContent' => '<html><head></head><body>MyName_Value</body></html>'
771
- },
772
- 'TextBody' => {
773
- 'ContentIsValid' => true,
774
- 'ValidationErrors' => [],
775
- 'RenderedContent' => 'MyName_Value'
776
- },
777
- 'Subject' => {
778
- 'ContentIsValid' => true,
779
- 'ValidationErrors' => [],
780
- 'RenderedContent' => 'MyName_Value'
781
- },
782
- 'SuggestedTemplateModel' => {
783
- 'MyName' => 'MyName_Value'
784
- }
776
+ 'AllContentIsValid' => true,
777
+ 'HtmlBody' => {
778
+ 'ContentIsValid' => true,
779
+ 'ValidationErrors' => [],
780
+ 'RenderedContent' => '<html><head></head><body>MyName_Value</body></html>'
781
+ },
782
+ 'TextBody' => {
783
+ 'ContentIsValid' => true,
784
+ 'ValidationErrors' => [],
785
+ 'RenderedContent' => 'MyName_Value'
786
+ },
787
+ 'Subject' => {
788
+ 'ContentIsValid' => true,
789
+ 'ValidationErrors' => [],
790
+ 'RenderedContent' => 'MyName_Value'
791
+ },
792
+ 'SuggestedTemplateModel' => {
793
+ 'MyName' => 'MyName_Value'
794
+ }
785
795
  }
786
796
  end
787
797
 
788
798
  it 'performs a POST request and returns unmodified suggested template model' do
789
799
  expected_template_json = {
790
- 'HtmlBody' => '{{MyName}}',
791
- 'TextBody' => '{{MyName}}',
792
- 'Subject' => '{{MyName}}'
800
+ 'HtmlBody' => '{{MyName}}',
801
+ 'TextBody' => '{{MyName}}',
802
+ 'Subject' => '{{MyName}}'
793
803
  }.to_json
794
804
 
795
805
  expect(http_client).to receive(:post).with('templates/validate', expected_template_json).and_return(response)
@@ -808,37 +818,37 @@ describe Postmark::ApiClient do
808
818
  context 'when template is invalid' do
809
819
  let(:response) do
810
820
  {
811
- 'AllContentIsValid' => false,
812
- 'HtmlBody' => {
813
- 'ContentIsValid' => false,
814
- 'ValidationErrors' => [
815
- {
816
- 'Message' => 'The \'each\' block being opened requires a model path to be specified in the form \'{#each <name>}\'.',
817
- 'Line' => 1,
818
- 'CharacterPosition' => 1
819
- }
820
- ],
821
- 'RenderedContent' => nil
822
- },
823
- 'TextBody' => {
824
- 'ContentIsValid' => true,
825
- 'ValidationErrors' => [],
826
- 'RenderedContent' => 'MyName_Value'
827
- },
828
- 'Subject' => {
829
- 'ContentIsValid' => true,
830
- 'ValidationErrors' => [],
831
- 'RenderedContent' => 'MyName_Value'
832
- },
833
- 'SuggestedTemplateModel' => nil
821
+ 'AllContentIsValid' => false,
822
+ 'HtmlBody' => {
823
+ 'ContentIsValid' => false,
824
+ 'ValidationErrors' => [
825
+ {
826
+ 'Message' => 'The \'each\' block being opened requires a model path to be specified in the form \'{#each <name>}\'.',
827
+ 'Line' => 1,
828
+ 'CharacterPosition' => 1
829
+ }
830
+ ],
831
+ 'RenderedContent' => nil
832
+ },
833
+ 'TextBody' => {
834
+ 'ContentIsValid' => true,
835
+ 'ValidationErrors' => [],
836
+ 'RenderedContent' => 'MyName_Value'
837
+ },
838
+ 'Subject' => {
839
+ 'ContentIsValid' => true,
840
+ 'ValidationErrors' => [],
841
+ 'RenderedContent' => 'MyName_Value'
842
+ },
843
+ 'SuggestedTemplateModel' => nil
834
844
  }
835
845
  end
836
846
 
837
847
  it 'performs a POST request and returns validation errors' do
838
848
  expected_template_json = {
839
- 'HtmlBody' => '{{#each}}',
840
- 'TextBody' => '{{MyName}}',
841
- 'Subject' => '{{MyName}}'
849
+ 'HtmlBody' => '{{#each}}',
850
+ 'TextBody' => '{{MyName}}',
851
+ 'Subject' => '{{MyName}}'
842
852
  }.to_json
843
853
 
844
854
  expect(http_client).to receive(:post).with('templates/validate', expected_template_json).and_return(response)
@@ -857,13 +867,13 @@ describe Postmark::ApiClient do
857
867
  end
858
868
 
859
869
  describe "#deliver_with_template" do
860
- let(:email) { Postmark::MessageHelper.to_postmark(message_hash) }
861
- let(:email_json) { Postmark::Json.encode(email) }
862
- let(:http_client) { subject.http_client }
863
- let(:response) { {"MessageID" => 42} }
870
+ let(:email) {Postmark::MessageHelper.to_postmark(message_hash)}
871
+ let(:email_json) {Postmark::Json.encode(email)}
872
+ let(:http_client) {subject.http_client}
873
+ let(:response) {{"MessageID" => 42}}
864
874
 
865
875
  it 'converts message hash to Postmark format and posts it to /email/withTemplate' do
866
- expect(http_client).to receive(:post).with('email/withTemplate', email_json) { response }
876
+ expect(http_client).to receive(:post).with('email/withTemplate', email_json) {response}
867
877
  subject.deliver_with_template(message_hash)
868
878
  end
869
879
 
@@ -871,54 +881,54 @@ describe Postmark::ApiClient do
871
881
  2.times do
872
882
  expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError, 500)
873
883
  end
874
- expect(http_client).to receive(:post) { response }
875
- expect { subject.deliver_with_template(message_hash) }.not_to raise_error
884
+ expect(http_client).to receive(:post) {response}
885
+ expect {subject.deliver_with_template(message_hash)}.not_to raise_error
876
886
  end
877
887
 
878
888
  it 'converts response to ruby format' do
879
- expect(http_client).to receive(:post).with('email/withTemplate', email_json) { response }
889
+ expect(http_client).to receive(:post).with('email/withTemplate', email_json) {response}
880
890
  r = subject.deliver_with_template(message_hash)
881
891
  r.should have_key(:message_id)
882
892
  end
883
893
  end
884
894
 
885
895
  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 }
896
+ let(:max_batch_size) {50}
897
+ let(:factor) {3.5}
898
+ let(:http_client) {subject.http_client}
889
899
  let(:postmark_response) do
890
900
  {
891
- 'ErrorCode' => 0,
892
- 'Message' => 'OK',
893
- 'SubmittedAt' => '2018-03-14T09:56:50.4288265-04:00',
894
- 'To' => 'recipient@example.org'
901
+ 'ErrorCode' => 0,
902
+ 'Message' => 'OK',
903
+ 'SubmittedAt' => '2018-03-14T09:56:50.4288265-04:00',
904
+ 'To' => 'recipient@example.org'
895
905
  }
896
906
  end
897
907
 
898
908
  let(:message_hashes) do
899
909
  Array.new((factor * max_batch_size).to_i) do
900
910
  {
901
- :template_id => 42,
902
- :alias => 'alias',
903
- :template_model => { :Foo => 'attr_value' },
904
- :from => 'sender@example.org',
905
- :to => 'recipient@example.org'
911
+ :template_id => 42,
912
+ :alias => 'alias',
913
+ :template_model => {:Foo => 'attr_value'},
914
+ :from => 'sender@example.org',
915
+ :to => 'recipient@example.org'
906
916
  }
907
917
  end
908
918
  end
909
919
 
910
- before { subject.max_batch_size = max_batch_size }
920
+ before {subject.max_batch_size = max_batch_size}
911
921
 
912
922
  it 'performs a total of (bath_size / max_batch_size) requests' do
913
923
  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 }
924
+ to receive(:post).with('email/batchWithTemplates', a_postmark_json).
925
+ at_most(factor.to_i).times do
926
+ Array.new(max_batch_size) {postmark_response}
917
927
  end
918
928
 
919
929
  expect(http_client).
920
- to receive(:post).with('email/batchWithTemplates', a_postmark_json).
921
- exactly((factor - factor.to_i).ceil).times do
930
+ to receive(:post).with('email/batchWithTemplates', a_postmark_json).
931
+ exactly((factor - factor.to_i).ceil).times do
922
932
  response = Array.new(((factor - factor.to_i) * max_batch_size).to_i) do
923
933
  postmark_response
924
934
  end
@@ -941,14 +951,14 @@ describe Postmark::ApiClient do
941
951
  describe '#get_stats_totals' do
942
952
  let(:response) do
943
953
  {
944
- "Sent" => 615,
945
- "BounceRate" => 10.406,
954
+ "Sent" => 615,
955
+ "BounceRate" => 10.406,
946
956
  }
947
957
  end
948
- let(:http_client) { subject.http_client }
958
+ let(:http_client) {subject.http_client}
949
959
 
950
960
  it 'converts response to ruby format' do
951
- expect(http_client).to receive(:get).with('stats/outbound', { :tag => 'foo' }) { response }
961
+ expect(http_client).to receive(:get).with('stats/outbound', {:tag => 'foo'}) {response}
952
962
  r = subject.get_stats_totals(:tag => 'foo')
953
963
  r.should have_key(:sent)
954
964
  r.should have_key(:bounce_rate)
@@ -958,31 +968,31 @@ describe Postmark::ApiClient do
958
968
  describe '#get_stats_counts' do
959
969
  let(:response) do
960
970
  {
961
- "Days" => [
962
- {
963
- "Date" => "2014-01-01",
964
- "Sent" => 140
965
- },
966
- {
967
- "Date" => "2014-01-02",
968
- "Sent" => 160
969
- },
970
- {
971
- "Date" => "2014-01-04",
972
- "Sent" => 50
973
- },
974
- {
975
- "Date" => "2014-01-05",
976
- "Sent" => 115
977
- }
978
- ],
979
- "Sent" => 615
971
+ "Days" => [
972
+ {
973
+ "Date" => "2014-01-01",
974
+ "Sent" => 140
975
+ },
976
+ {
977
+ "Date" => "2014-01-02",
978
+ "Sent" => 160
979
+ },
980
+ {
981
+ "Date" => "2014-01-04",
982
+ "Sent" => 50
983
+ },
984
+ {
985
+ "Date" => "2014-01-05",
986
+ "Sent" => 115
987
+ }
988
+ ],
989
+ "Sent" => 615
980
990
  }
981
991
  end
982
- let(:http_client) { subject.http_client }
992
+ let(:http_client) {subject.http_client}
983
993
 
984
994
  it 'converts response to ruby format' do
985
- expect(http_client).to receive(:get).with('stats/outbound/sends', { :tag => 'foo' }) { response }
995
+ expect(http_client).to receive(:get).with('stats/outbound/sends', {:tag => 'foo'}) {response}
986
996
  r = subject.get_stats_counts(:sends, :tag => 'foo')
987
997
  r.should have_key(:days)
988
998
  r.should have_key(:sent)
@@ -994,7 +1004,7 @@ describe Postmark::ApiClient do
994
1004
  end
995
1005
 
996
1006
  it 'uses fromdate that is passed in' do
997
- expect(http_client).to receive(:get).with('stats/outbound/sends', { :tag => 'foo', :fromdate => '2015-01-01' }) { response }
1007
+ expect(http_client).to receive(:get).with('stats/outbound/sends', {:tag => 'foo', :fromdate => '2015-01-01'}) {response}
998
1008
  r = subject.get_stats_counts(:sends, :tag => 'foo', :fromdate => '2015-01-01')
999
1009
  r.should have_key(:days)
1000
1010
  r.should have_key(:sent)
@@ -1006,7 +1016,7 @@ describe Postmark::ApiClient do
1006
1016
  end
1007
1017
 
1008
1018
  it 'uses stats type that is passed in' do
1009
- expect(http_client).to receive(:get).with('stats/outbound/opens/readtimes', { :tag => 'foo', :type => :readtimes }) { response }
1019
+ expect(http_client).to receive(:get).with('stats/outbound/opens/readtimes', {:tag => 'foo', :type => :readtimes}) {response}
1010
1020
  r = subject.get_stats_counts(:opens, :type => :readtimes, :tag => 'foo')
1011
1021
  r.should have_key(:days)
1012
1022
  r.should have_key(:sent)