mailgun-ruby 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +30 -8
  3. data/.rubocop.yml +68 -0
  4. data/Gemfile +1 -1
  5. data/README.md +1 -1
  6. data/Rakefile +0 -5
  7. data/lib/mailgun/client.rb +12 -8
  8. data/lib/mailgun/domains/domains.rb +4 -2
  9. data/lib/mailgun/lists/opt_in_handler.rb +2 -4
  10. data/lib/mailgun/messages/batch_message.rb +2 -1
  11. data/lib/mailgun/messages/message_builder.rb +4 -32
  12. data/lib/mailgun/metrics/metrics.rb +6 -2
  13. data/lib/mailgun/response.rb +2 -2
  14. data/lib/mailgun/tags/analytics_tags.rb +9 -5
  15. data/lib/mailgun/tags/tags.rb +4 -2
  16. data/lib/mailgun/version.rb +1 -1
  17. data/lib/railgun/attachment.rb +4 -6
  18. data/lib/railgun/mailer.rb +2 -2
  19. data/mailgun.gemspec +4 -1
  20. data/spec/integration/analytics_tags_spec.rb +1 -1
  21. data/spec/integration/domains_spec.rb +7 -13
  22. data/spec/integration/events_spec.rb +1 -3
  23. data/spec/integration/list_members_spec.rb +1 -1
  24. data/spec/integration/logs_spec.rb +1 -1
  25. data/spec/integration/mailgun_spec.rb +3 -2
  26. data/spec/integration/metrics_spec.rb +9 -3
  27. data/spec/integration/suppressions_spec.rb +203 -26
  28. data/spec/integration/webhook_spec.rb +7 -2
  29. data/spec/spec_helper.rb +7 -0
  30. data/spec/unit/client_spec.rb +424 -0
  31. data/spec/unit/connection/test_client.rb +60 -13
  32. data/spec/unit/events/events_spec.rb +25 -9
  33. data/spec/unit/helpers/api_version_checker_spec.rb +206 -0
  34. data/spec/unit/lists/opt_in_handler_spec.rb +4 -2
  35. data/spec/unit/mailgun_spec.rb +7 -5
  36. data/spec/unit/messages/batch_message_spec.rb +25 -24
  37. data/spec/unit/messages/message_builder_spec.rb +83 -86
  38. data/spec/unit/railgun/content_type_spec.rb +7 -7
  39. data/spec/unit/railgun/mailer_spec.rb +17 -14
  40. data/spec/unit/response_spec.rb +225 -0
  41. data/vcr_cassettes/For_the_suppressions_handling_class/creates_a_single_bounce.yml +55 -0
  42. data/vcr_cassettes/suppressions.yml +1053 -170
  43. metadata +55 -5
@@ -0,0 +1,424 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'mailgun'
5
+ require 'mailgun/exceptions/exceptions'
6
+
7
+ describe Mailgun::Client do
8
+ # ---------------------------------------------------------------------------
9
+ # Shared helpers
10
+ # ---------------------------------------------------------------------------
11
+ # Build a client in test mode so no real HTTP calls are ever made.
12
+ subject(:client) { described_class.new(api_key, 'api.mailgun.net', 'v3', true, true) }
13
+
14
+ let(:api_key) { 'test-api-key-abc123' }
15
+ let(:message_params) do
16
+ {
17
+ from: 'bob@example.com',
18
+ to: 'sally@example.com',
19
+ subject: 'Hello!',
20
+ text: 'Test body.'
21
+ }
22
+ end
23
+ let(:domain) { 'example.com' }
24
+
25
+ # Fake HTTP response double reusable across examples
26
+ def fake_http_response(body: '{"message":"ok"}', status: 200)
27
+ double('http_response', body: body, status: status)
28
+ end
29
+
30
+ # ---------------------------------------------------------------------------
31
+ # .new / #initialize
32
+ # ---------------------------------------------------------------------------
33
+ describe '#initialize' do
34
+ it 'instantiates without raising' do
35
+ expect { described_class.new(api_key) }.not_to raise_error
36
+ end
37
+
38
+ it 'stores the api_version' do
39
+ c = described_class.new(api_key, 'api.mailgun.net', 'v3')
40
+ expect(c.api_version).to eq('v3')
41
+ end
42
+
43
+ it 'defaults test_mode to false when not specified' do
44
+ # Pass test_mode = false explicitly to avoid picking up global config
45
+ c = described_class.new(api_key, 'api.mailgun.net', 'v3', true, false)
46
+ expect(c.test_mode?).to be(false)
47
+ end
48
+
49
+ it 'accepts test_mode = true' do
50
+ c = described_class.new(api_key, 'api.mailgun.net', nil, true, true)
51
+ expect(c.test_mode?).to be(true)
52
+ end
53
+
54
+ it 'supports EU api host' do
55
+ expect { described_class.new(api_key, 'api.eu.mailgun.net') }.not_to raise_error
56
+ end
57
+ end
58
+
59
+ # ---------------------------------------------------------------------------
60
+ # #test_mode?
61
+ # ---------------------------------------------------------------------------
62
+ describe '#test_mode?' do
63
+ it 'returns true when the client is in test mode' do
64
+ expect(client.test_mode?).to be(true)
65
+ end
66
+
67
+ it 'returns false when test mode has been disabled' do
68
+ client.disable_test_mode!
69
+ expect(client.test_mode?).to be(false)
70
+ end
71
+ end
72
+
73
+ # ---------------------------------------------------------------------------
74
+ # #enable_test_mode!
75
+ # ---------------------------------------------------------------------------
76
+ describe '#enable_test_mode!' do
77
+ subject(:non_test_client) do
78
+ described_class.new(api_key, 'api.mailgun.net', 'v3', true, false)
79
+ end
80
+
81
+ it 'sets test_mode to true' do
82
+ non_test_client.enable_test_mode!
83
+ expect(non_test_client.test_mode?).to be(true)
84
+ end
85
+ end
86
+
87
+ # ---------------------------------------------------------------------------
88
+ # #disable_test_mode!
89
+ # ---------------------------------------------------------------------------
90
+ describe '#disable_test_mode!' do
91
+ it 'sets test_mode to false' do
92
+ client.disable_test_mode!
93
+ expect(client.test_mode?).to be(false)
94
+ end
95
+ end
96
+
97
+ # ---------------------------------------------------------------------------
98
+ # .deliveries
99
+ # ---------------------------------------------------------------------------
100
+ describe '.deliveries' do
101
+ before { described_class.deliveries.clear }
102
+
103
+ it 'returns an Array' do
104
+ expect(described_class.deliveries).to be_an(Array)
105
+ end
106
+
107
+ it 'accumulates messages sent in test mode' do
108
+ client.send_message(domain, message_params)
109
+ expect(described_class.deliveries).not_to be_empty
110
+ end
111
+
112
+ it 'stores the message data sent in test mode' do
113
+ client.send_message(domain, message_params)
114
+ expect(described_class.deliveries.last).to include(from: 'bob@example.com')
115
+ end
116
+
117
+ it 'accumulates multiple deliveries' do
118
+ 2.times { client.send_message(domain, message_params) }
119
+ expect(described_class.deliveries.size).to eq(2)
120
+ end
121
+ end
122
+
123
+ # ---------------------------------------------------------------------------
124
+ # #send_message — test mode
125
+ # ---------------------------------------------------------------------------
126
+ describe '#send_message (test mode)' do
127
+ before { described_class.deliveries.clear }
128
+
129
+ it 'returns a Mailgun::Response' do
130
+ result = client.send_message(domain, message_params)
131
+ expect(result).to be_a(Mailgun::Response)
132
+ end
133
+
134
+ it 'returns a 200 status response in test mode' do
135
+ result = client.send_message(domain, message_params)
136
+ expect(result.code).to eq(200)
137
+ end
138
+
139
+ it 'returns a body containing the Queued message in test mode' do
140
+ result = client.send_message(domain, message_params)
141
+ body = JSON.parse(result.body)
142
+ expect(body['message']).to eq('Queued. Thank you.')
143
+ end
144
+
145
+ it 'returns a body with a unique test-mode message id' do
146
+ result = client.send_message(domain, message_params)
147
+ body = JSON.parse(result.body)
148
+ expect(body['id']).to match(/test-mode-mail-.+@localhost/)
149
+ end
150
+
151
+ it 'does not make real HTTP calls in test mode' do
152
+ expect(client.instance_variable_get(:@http_client)).not_to receive(:post)
153
+ client.send_message(domain, message_params)
154
+ end
155
+
156
+ it 'records a copy of message data in .deliveries' do
157
+ client.send_message(domain, message_params)
158
+ expect(described_class.deliveries.last[:subject]).to eq('Hello!')
159
+ end
160
+
161
+ context 'with a MessageBuilder object' do
162
+ it 'stores the MessageBuilder in .deliveries' do
163
+ mb = Mailgun::MessageBuilder.new
164
+ mb.set_from_address('bob@example.com')
165
+ mb.add_recipient(:to, 'sally@example.com')
166
+ mb.set_subject('Hello via builder!')
167
+ mb.set_text_body('Body text.')
168
+
169
+ result = client.send_message(domain, mb)
170
+ expect(result).to be_a(Mailgun::Response)
171
+ expect(described_class.deliveries.last).to be_a(Mailgun::MessageBuilder)
172
+ end
173
+
174
+ it 'raises a Mailgun::ParameterError when mb is empty' do
175
+ mb = Mailgun::MessageBuilder.new
176
+
177
+ expect { client.send_message(domain, mb) }
178
+ .to raise_error(Mailgun::ParameterError)
179
+ end
180
+
181
+ it 'raises a Mailgun::ParameterError when from is missing' do
182
+ mb = Mailgun::MessageBuilder.new
183
+ mb.add_recipient(:to, 'sally@example.com')
184
+
185
+ expect { client.send_message(domain, mb) }
186
+ .to raise_error(Mailgun::ParameterError)
187
+ end
188
+ end
189
+ end
190
+
191
+ # ---------------------------------------------------------------------------
192
+ # #send_message — live mode (HTTP mocked at the Faraday level)
193
+ # ---------------------------------------------------------------------------
194
+ describe '#send_message (live mode)' do
195
+ subject(:live_client) do
196
+ described_class.new(api_key, 'api.mailgun.net', 'v3', true, false)
197
+ end
198
+
199
+ let(:success_response) { fake_http_response }
200
+
201
+ before do
202
+ allow(live_client.instance_variable_get(:@http_client))
203
+ .to receive(:post)
204
+ .and_return(success_response)
205
+ end
206
+
207
+ it 'posts to the messages endpoint and returns a Response' do
208
+ result = live_client.send_message(domain, message_params)
209
+ expect(result).to be_a(Mailgun::Response)
210
+ end
211
+
212
+ it 'strips nil values from the data hash before posting' do
213
+ params_with_nil = message_params.merge(cc: nil)
214
+ http = live_client.instance_variable_get(:@http_client)
215
+ expect(http).to receive(:post) do |_path, data, *|
216
+ expect(data).not_to have_key(:cc)
217
+ success_response
218
+ end
219
+ live_client.send_message(domain, params_with_nil)
220
+ end
221
+
222
+ it 'raises CommunicationError when the underlying request fails' do
223
+ allow(live_client.instance_variable_get(:@http_client))
224
+ .to receive(:post)
225
+ .and_raise(StandardError, 'connection refused')
226
+
227
+ expect { live_client.send_message(domain, message_params) }
228
+ .to raise_error(Mailgun::CommunicationError)
229
+ end
230
+
231
+ context 'with a MessageBuilder object' do
232
+ it 'posts to the messages endpoint and returns a Response' do
233
+ mb = Mailgun::MessageBuilder.new
234
+ mb.set_from_address('bob@example.com')
235
+ mb.add_recipient(:to, 'sally@example.com')
236
+ mb.set_subject('Hello via builder!')
237
+ mb.set_text_body('Body text.')
238
+
239
+ result = live_client.send_message(domain, mb)
240
+ expect(result).to be_a(Mailgun::Response)
241
+ end
242
+ end
243
+ end
244
+
245
+ # ---------------------------------------------------------------------------
246
+ # #get
247
+ # ---------------------------------------------------------------------------
248
+ describe '#get' do
249
+ let(:http_response) { fake_http_response }
250
+
251
+ before do
252
+ allow(client.instance_variable_get(:@http_client))
253
+ .to receive(:get)
254
+ .and_return(http_response)
255
+ end
256
+
257
+ it 'returns a Mailgun::Response' do
258
+ result = client.get("#{domain}/events", { event: 'delivered' })
259
+ expect(result).to be_a(Mailgun::Response)
260
+ end
261
+
262
+ it 'passes the resource path through to the http client' do
263
+ http = client.instance_variable_get(:@http_client)
264
+ expect(http).to receive(:get).with("#{domain}/events", anything, anything)
265
+ .and_return(http_response)
266
+ client.get("#{domain}/events")
267
+ end
268
+
269
+ it 'raises CommunicationError on failure' do
270
+ allow(client.instance_variable_get(:@http_client))
271
+ .to receive(:get)
272
+ .and_raise(StandardError, 'timeout')
273
+
274
+ expect { client.get("#{domain}/events") }
275
+ .to raise_error(Mailgun::CommunicationError)
276
+ end
277
+ end
278
+
279
+ # ---------------------------------------------------------------------------
280
+ # #post
281
+ # ---------------------------------------------------------------------------
282
+ describe '#post' do
283
+ let(:http_response) { fake_http_response }
284
+
285
+ before do
286
+ allow(client.instance_variable_get(:@http_client))
287
+ .to receive(:post)
288
+ .and_return(http_response)
289
+ end
290
+
291
+ it 'returns a Mailgun::Response' do
292
+ result = client.post("#{domain}/messages", message_params)
293
+ expect(result).to be_a(Mailgun::Response)
294
+ end
295
+
296
+ it 'raises CommunicationError on failure' do
297
+ allow(client.instance_variable_get(:@http_client))
298
+ .to receive(:post)
299
+ .and_raise(StandardError, 'connection error')
300
+
301
+ expect { client.post("#{domain}/messages", message_params) }
302
+ .to raise_error(Mailgun::CommunicationError)
303
+ end
304
+ end
305
+
306
+ # ---------------------------------------------------------------------------
307
+ # #put
308
+ # ---------------------------------------------------------------------------
309
+ describe '#put' do
310
+ let(:http_response) { fake_http_response }
311
+
312
+ before do
313
+ allow(client.instance_variable_get(:@http_client))
314
+ .to receive(:put)
315
+ .and_return(http_response)
316
+ end
317
+
318
+ it 'returns a Mailgun::Response' do
319
+ result = client.put("#{domain}/routes/abc123", { description: 'updated' })
320
+ expect(result).to be_a(Mailgun::Response)
321
+ end
322
+
323
+ it 'raises CommunicationError on failure' do
324
+ allow(client.instance_variable_get(:@http_client))
325
+ .to receive(:put)
326
+ .and_raise(StandardError, 'connection error')
327
+
328
+ expect { client.put("#{domain}/routes/abc123", {}) }
329
+ .to raise_error(Mailgun::CommunicationError)
330
+ end
331
+ end
332
+
333
+ # ---------------------------------------------------------------------------
334
+ # #delete
335
+ # ---------------------------------------------------------------------------
336
+ describe '#delete' do
337
+ let(:http_response) { fake_http_response(body: '{"message":"Bounced address has been removed"}') }
338
+
339
+ before do
340
+ allow(client.instance_variable_get(:@http_client))
341
+ .to receive(:delete)
342
+ .and_return(http_response)
343
+ end
344
+
345
+ it 'returns a Mailgun::Response' do
346
+ result = client.delete("#{domain}/bounces/test@example.com")
347
+ expect(result).to be_a(Mailgun::Response)
348
+ end
349
+
350
+ it 'raises CommunicationError on failure' do
351
+ allow(client.instance_variable_get(:@http_client))
352
+ .to receive(:delete)
353
+ .and_raise(StandardError, 'connection error')
354
+
355
+ expect { client.delete("#{domain}/bounces/test@example.com") }
356
+ .to raise_error(Mailgun::CommunicationError)
357
+ end
358
+
359
+ it 'sends params in the request' do
360
+ result = client.delete("#{domain}/bounces/test@example.com", params: 'test')
361
+ expect(result).to be_a(Mailgun::Response)
362
+ end
363
+
364
+ it 'sends params in the request when body_params truthy' do
365
+ result = client.delete("#{domain}/bounces/test@example.com", params: 'test', body_params: true)
366
+ expect(result).to be_a(Mailgun::Response)
367
+ end
368
+ end
369
+
370
+ # ---------------------------------------------------------------------------
371
+ # #set_api_key
372
+ # ---------------------------------------------------------------------------
373
+ describe '#set_api_key' do
374
+ it 'does not raise when updating the api key' do
375
+ expect { client.set_api_key('new-key-xyz') }.not_to raise_error
376
+ end
377
+ end
378
+
379
+ # ---------------------------------------------------------------------------
380
+ # #set_subaccount / #reset_subaccount
381
+ # ---------------------------------------------------------------------------
382
+ describe '#set_subaccount' do
383
+ it 'adds the subaccount header to the http client' do
384
+ client.set_subaccount('subaccount-id-123')
385
+ headers = client.instance_variable_get(:@http_client).headers
386
+ expect(headers[Mailgun::Client::SUBACCOUNT_HEADER]).to eq('subaccount-id-123')
387
+ end
388
+ end
389
+
390
+ describe '#reset_subaccount' do
391
+ it 'removes the subaccount header from the http client' do
392
+ client.set_subaccount('subaccount-id-123')
393
+ client.reset_subaccount
394
+ headers = client.instance_variable_get(:@http_client).headers
395
+ expect(headers[Mailgun::Client::SUBACCOUNT_HEADER]).to be_nil
396
+ end
397
+ end
398
+
399
+ # ---------------------------------------------------------------------------
400
+ # #suppressions
401
+ # ---------------------------------------------------------------------------
402
+ describe '#suppressions' do
403
+ it 'returns a Mailgun::Suppressions instance' do
404
+ expect(client.suppressions(domain)).to be_a(Mailgun::Suppressions)
405
+ end
406
+
407
+ it 'scopes the suppressions client to the given domain' do
408
+ suppressions = client.suppressions(domain)
409
+ expect(suppressions).to be_a(Mailgun::Suppressions)
410
+ end
411
+ end
412
+
413
+ # ---------------------------------------------------------------------------
414
+ # Mailgun.configure integration
415
+ # ---------------------------------------------------------------------------
416
+ describe 'Mailgun.configure integration' do
417
+ after { Mailgun.instance_variable_set(:@configuration, nil) }
418
+
419
+ it 'picks up the api_key from Mailgun.configure' do
420
+ Mailgun.configure { |config| config.api_key = 'configured-key' }
421
+ expect { described_class.new }.not_to raise_error
422
+ end
423
+ end
424
+ end
@@ -97,26 +97,73 @@ module Mailgun
97
97
  return Response.from_hash({ body: JSON.generate({ 'message' => 'Queued. Thank you.', 'id' => id }) })
98
98
  end
99
99
  if resource_endpoint == 'bounces'
100
- return Response.from_hash({ body: JSON.generate({ 'total_count' => 1,
101
- 'items' => { 'created_at' => 'Fri, 21 Oct 2011 11:02:55 GMT', 'status' => 550, 'address' => 'baz@example.com',
102
- 'error' => 'Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found' } }) })
100
+ return Response.from_hash(
101
+ { body: JSON.generate(
102
+ {
103
+ 'total_count' => 1,
104
+ 'items' =>
105
+ {
106
+ 'created_at' => 'Fri, 21 Oct 2011 11:02:55 GMT',
107
+ 'status' => 550,
108
+ 'address' => 'baz@example.com',
109
+ 'error' => "Message was not accepted -- invalid mailbox. \
110
+ Local mailbox baz@example.com is unavailable: user not found"
111
+ }
112
+ }
113
+ ) }
114
+ )
103
115
  end
104
116
  if resource_endpoint == 'lists'
105
- return Response.from_hash({ body: JSON.generate({
106
- 'member' => { 'vars' => { 'age' => 26 }, 'name' => 'Foo Bar', 'subscribed' => false,
107
- 'address' => 'bar@example.com' }, 'message' => 'Mailing list member has been updated'
108
- }) })
117
+ return Response.from_hash(
118
+ { body: JSON.generate(
119
+ {
120
+ 'member' =>
121
+ {
122
+ 'vars' => { 'age' => 26 },
123
+ 'name' => 'Foo Bar',
124
+ 'subscribed' => false,
125
+ 'address' => 'bar@example.com'
126
+ },
127
+ 'message' => 'Mailing list member has been updated'
128
+ }
129
+ ) }
130
+ )
109
131
  end
110
132
  if resource_endpoint == 'campaigns'
111
- return Response.from_hash({ body: JSON.generate({ 'message' => 'Campaign has been deleted',
112
- 'id' => 'ABC123' }) })
133
+ return Response.from_hash(
134
+ {
135
+ body: JSON.generate(
136
+ {
137
+ 'message' => 'Campaign has been deleted',
138
+ 'id' => 'ABC123'
139
+ }
140
+ )
141
+ }
142
+ )
113
143
  end
114
144
  return unless resource_endpoint == 'events'
115
145
 
116
- Response.from_hash({ body: JSON.generate({ 'items' => [],
117
- 'paging' => {
118
- 'next' => 'https://api.mailgun.net/v3/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIFsiZiJdLCBudWxsLCB7ImFjY291bnQuaWQiOiAiNGU4MjMwZjYxNDc2ZDg2NzEzMDBjNDc2IiwgImRvbWFpbi5uYW1lIjogInRoaXNpc2F0ZXN0ZG9tYWluZm9ybWFpbGd1bi5jb20iLCAic2V2ZXJpdHkiOiAiTk9UIGludGVybmFsIn0sIDEwMCwgbnVsbF0=', 'previous' => 'https://api.mailgun.net/v2/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDdUMDA6NDU6NTEuNzQxODkyKzAwOjAwIn0sIFsicCIsICJmIl0sIG51bGwsIHsiYWNjb3VudC5pZCI6ICI0ZTgyMzBmNjE0NzZkODY3MTMwMGM0NzYiLCAiZG9tYWluLm5hbWUiOiAidGhpc2lzYXRlc3Rkb21haW5mb3JtYWlsZ3VuLmNvbSIsICJzZXZlcml0eSI6ICJOT1QgaW50ZXJuYWwifSwgMTAwLCBudWxsXQ=='
119
- } }) })
146
+ Response.from_hash(
147
+ { body: JSON.generate(
148
+ { 'items' => [],
149
+ 'paging' => {
150
+ 'next' =>
151
+ "https://api.mailgun.net/v3/thisisatestdomainformailgun.com/events/W3siYiI6I\
152
+ CIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzK\
153
+ zAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUM\
154
+ DA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIFsiZiJdLCBudWxsLCB7ImFjY291bnQuaWQiOiAiNGU4MjMwZjYxNDc2ZDg2N\
155
+ zEzMDBjNDc2IiwgImRvbWFpbi5uYW1lIjogInRoaXNpc2F0ZXN0ZG9tYWluZm9ybWFpbGd1bi5jb20iLCAic2V2ZXJpd\
156
+ HkiOiAiTk9UIGludGVybmFsIn0sIDEwMCwgbnVsbF0=",
157
+ 'previous' =>
158
+ "https://api.mailgun.net/v2/thisisatestdomainformailgun.com/events/W3siYiI6IC\
159
+ IyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzA\
160
+ wOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDdUMDA6\
161
+ NDU6NTEuNzQxODkyKzAwOjAwIn0sIFsicCIsICJmIl0sIG51bGwsIHsiYWNjb3VudC5pZCI6ICI0ZTgyMzBmNjE0NzZkO\
162
+ DY3MTMwMGM0NzYiLCAiZG9tYWluLm5hbWUiOiAidGhpc2lzYXRlc3Rkb21haW5mb3JtYWlsZ3VuLmNvbSIsICJzZXZlcm\
163
+ l0eSI6ICJOT1QgaW50ZXJuYWwifSwgMTAwLCBudWxsXQ=="
164
+ } }
165
+ ) }
166
+ )
120
167
  end
121
168
  end
122
169
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'The method get' do
6
- it 'should return a proper hash of log data.' do
6
+ it 'returns a proper hash of log data.' do
7
7
  @mg_obj = Mailgun::UnitClient.new('events')
8
8
  events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
9
9
  result = events.get
@@ -14,7 +14,7 @@ describe 'The method get' do
14
14
  end
15
15
 
16
16
  describe 'Pagination' do
17
- it 'should return a proper hash of log data.' do
17
+ it 'returns a proper hash of log data.' do
18
18
  @mg_obj = Mailgun::UnitClient.new('events')
19
19
  events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
20
20
  result = events.get
@@ -25,17 +25,33 @@ describe 'Pagination' do
25
25
  expect(json['paging']).to include('previous')
26
26
  end
27
27
 
28
- it 'should calculate proper next-page url' do
28
+ it 'calculates proper next-page url' do
29
29
  events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
30
- output = events.send(:extract_endpoint_from,
31
- '/v3/samples.mailgun.org/events/W3siYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIHsiYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIFsiZiJdLCBudWxsLCBbWyJhY2NvdW50LmlkIiwgIjU4MDUyMTg2NzhmYTE2MTNjNzkwYjUwZiJdLCBbImRvbWFpbi5uYW1lIiwgInNhbmRib3gyOTcwMTUyYWYzZDM0NTU5YmZjN2U3MTcwM2E2Y2YyNC5tYWlsZ3VuLm9yZyJdXSwgMTAwLCBudWxsXQ==')
30
+ output = events.send(
31
+ :extract_endpoint_from,
32
+ "/v3/samples.mailgun.org/events/W3siYiI6ICIyMDE3LTA1\
33
+ LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMj\
34
+ A6MDY6NTQuNTc3KzAwOjAwIn0sIHsiYiI6ICIyMDE3LTA1LTEwVDIwOjA2\
35
+ OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNT\
36
+ c3KzAwOjAwIn0sIFsiZiJdLCBudWxsLCBbWyJhY2NvdW50LmlkIiwgIjU4\
37
+ MDUyMTg2NzhmYTE2MTNjNzkwYjUwZiJdLCBbImRvbWFpbi5uYW1lIiwgIn\
38
+ NhbmRib3gyOTcwMTUyYWYzZDM0NTU5YmZjN2U3MTcwM2E2Y2YyNC5tYWls\
39
+ Z3VuLm9yZyJdXSwgMTAwLCBudWxsXQ=="
40
+ )
32
41
 
33
- expect(output).to eq 'W3siYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIHsiYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIFsiZiJdLCBudWxsLCBbWyJhY2NvdW50LmlkIiwgIjU4MDUyMTg2NzhmYTE2MTNjNzkwYjUwZiJdLCBbImRvbWFpbi5uYW1lIiwgInNhbmRib3gyOTcwMTUyYWYzZDM0NTU5YmZjN2U3MTcwM2E2Y2YyNC5tYWlsZ3VuLm9yZyJdXSwgMTAwLCBudWxsXQ=='
42
+ expect(output).to eq "W3siYiI6ICIyMDE3LTA1LTEwVDIwOjA2O\
43
+ jU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3\
44
+ KzAwOjAwIn0sIHsiYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDo\
45
+ wMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIF\
46
+ siZiJdLCBudWxsLCBbWyJhY2NvdW50LmlkIiwgIjU4MDUyMTg2NzhmYTE2M\
47
+ TNjNzkwYjUwZiJdLCBbImRvbWFpbi5uYW1lIiwgInNhbmRib3gyOTcwMTUy\
48
+ YWYzZDM0NTU5YmZjN2U3MTcwM2E2Y2YyNC5tYWlsZ3VuLm9yZyJdXSwgMTA\
49
+ wLCBudWxsXQ=="
34
50
  end
35
51
  end
36
52
 
37
53
  describe 'The method next' do
38
- it 'should return the next series of data.' do
54
+ it 'returns the next series of data.' do
39
55
  @mg_obj = Mailgun::UnitClient.new('events')
40
56
  events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
41
57
  result = events.next
@@ -46,7 +62,7 @@ describe 'The method next' do
46
62
  end
47
63
 
48
64
  describe 'The method previous' do
49
- it 'should return the previous series of data.' do
65
+ it 'returns the previous series of data.' do
50
66
  @mg_obj = Mailgun::UnitClient.new('events')
51
67
  events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
52
68
  result = events.previous
@@ -57,7 +73,7 @@ describe 'The method previous' do
57
73
  end
58
74
 
59
75
  describe 'The method each' do
60
- it 'should iterate over all event items.' do
76
+ it 'iterates over all event items.' do
61
77
  @mg_obj = Mailgun::UnitClient.new('events')
62
78
  events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
63
79
  # Events from the UnitClient are actually empty.