mailgunner 2.3.0 → 2.4.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: 4f2850f4c4d7090a89e92f1f892da73b54dbdce6
4
- data.tar.gz: 793b27238fa767fe883dc634442715fa355f958c
3
+ metadata.gz: e755c6f546bd421940dffab1c41d0b803842b7d4
4
+ data.tar.gz: ec6bde54051dcdfd4a28dfcc6dfb9ca9b13bd2b0
5
5
  SHA512:
6
- metadata.gz: 49a2692751d5a67f6fb05aaebf2c73fcd389aa2841311de02dea82a1e156471e3b6802c5e2e7813e08ed5f1bbe83fb3993d451b0f946254ddba7a63274d9cf94
7
- data.tar.gz: ddd64af9eb4d81e9c9ddb6734d647681e8f82f863f732967c398a4a6b91a980c1d0f5a98a6dade7fa33d228b669f665209fad453016bac21fbcffa68d4f8a7af
6
+ metadata.gz: 71f7726130d76a1163d717b5e3437e4a6adecd4fab2a40ceeee62d05bbd7b9c180a930ba95b04744494cfa0288275938d2d8da4619d70d6c38ba719935b32e37
7
+ data.tar.gz: 3ddcc963e98c68ed4855d0d895c67b5c3511b6a5793c3c0c3f8dda2c2888183a9195615cbc29c677938d59ae9bd7004b91ce7d9b821a2c9138eeda24aca22b17
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
3
  require 'cgi'
4
+ require 'mailgunner/version'
4
5
  require 'mailgunner/delivery_method' if defined?(Mail)
5
6
  require 'mailgunner/railtie' if defined?(Rails)
6
7
 
@@ -96,6 +97,14 @@ module Mailgunner
96
97
  delete("/v3/domains/#{escape @domain}/credentials/#{escape login}")
97
98
  end
98
99
 
100
+ def get_connection_settings
101
+ get("/v3/domains/#{escape @domain}/connection")
102
+ end
103
+
104
+ def update_connection_settings(attributes)
105
+ put("/v3/domains/#{escape @domain}/connection", attributes)
106
+ end
107
+
99
108
  def get_unsubscribes(params = {})
100
109
  get("/v3/#{escape @domain}/unsubscribes", params)
101
110
  end
@@ -144,6 +153,10 @@ module Mailgunner
144
153
  delete("/v3/#{escape @domain}/bounces/#{escape address}")
145
154
  end
146
155
 
156
+ def delete_bounces
157
+ delete("/v3/#{escape @domain}/bounces")
158
+ end
159
+
147
160
  def get_stats(params = {})
148
161
  Kernel.warn 'Mailgunner::Client#get_stats is deprecated'
149
162
 
@@ -158,6 +171,26 @@ module Mailgunner
158
171
  get("/v3/#{escape @domain}/events", params)
159
172
  end
160
173
 
174
+ def get_tags(params = {})
175
+ get("/v3/#{escape @domain}/tags", params)
176
+ end
177
+
178
+ def get_tag(id)
179
+ get("/v3/#{escape @domain}/tags/#{escape id}")
180
+ end
181
+
182
+ def update_tag(id, attributes)
183
+ put("/v3/#{escape @domain}/tags/#{escape id}", attributes)
184
+ end
185
+
186
+ def get_tag_stats(id, params)
187
+ get("/v3/#{escape @domain}/tags/#{escape id}/stats", params)
188
+ end
189
+
190
+ def delete_tag(id)
191
+ delete("/v3/#{escape @domain}/tags/#{escape id}")
192
+ end
193
+
161
194
  def get_routes(params = {})
162
195
  get('/v3/routes', params)
163
196
  end
@@ -288,8 +321,11 @@ module Mailgunner
288
321
  transmit(Net::HTTP::Delete.new(path))
289
322
  end
290
323
 
324
+ USER_AGENT = "Ruby/#{RUBY_VERSION} Mailgunner/#{VERSION}"
325
+
291
326
  def transmit(message)
292
327
  message.basic_auth('api', @api_key)
328
+ message['User-Agent'] = USER_AGENT
293
329
 
294
330
  yield message if block_given?
295
331
 
@@ -1,9 +1,7 @@
1
1
  module Mailgunner
2
2
  class Railtie < Rails::Railtie
3
- initializer 'mailgunner' do
4
- ActiveSupport.on_load(:action_mailer) do
5
- require 'mailgunner/delivery_method'
6
- end
3
+ config.before_initialize do
4
+ require 'mailgunner/delivery_method'
7
5
  end
8
6
  end
9
7
  end
@@ -0,0 +1,3 @@
1
+ module Mailgunner
2
+ VERSION = '2.4.0'
3
+ end
@@ -1,6 +1,8 @@
1
+ require_relative './lib/mailgunner/version'
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'mailgunner'
3
- s.version = '2.3.0'
5
+ s.version = Mailgunner::VERSION
4
6
  s.license = 'LGPL-3.0'
5
7
  s.platform = Gem::Platform::RUBY
6
8
  s.authors = ['Tim Craft']
@@ -26,6 +26,8 @@ describe 'Mailgunner::Client' do
26
26
  @encoded_address = 'user%40example.com'
27
27
 
28
28
  @login = 'bob.bar'
29
+
30
+ @id = 'idxxx'
29
31
  end
30
32
 
31
33
  describe 'http method' do
@@ -81,37 +83,27 @@ describe 'Mailgunner::Client' do
81
83
  end
82
84
 
83
85
  describe 'get_message method' do
84
- it 'fetches the domain message resource with the given key and returns the response object' do
85
- key = 'WyIzMmkey'
86
-
87
- stub_request(:get, "#@base_url/domains/#@domain/messages/#{key}").to_return(@json_response)
86
+ it 'fetches the domain message resource with the given id and returns the response object' do
87
+ stub_request(:get, "#@base_url/domains/#@domain/messages/#@id").to_return(@json_response)
88
88
 
89
- @client.get_message(key).must_equal(@json_response_object)
89
+ @client.get_message(@id).must_equal(@json_response_object)
90
90
  end
91
91
  end
92
92
 
93
93
  describe 'get_mime_message method' do
94
94
  it 'fetches the domain message resource with the given key and returns the response object' do
95
- key = 'WyIzMmkey'
96
-
97
- stub_request(:get, "#@base_url/domains/#@domain/messages/#{key}").
95
+ stub_request(:get, "#@base_url/domains/#@domain/messages/#@id").
98
96
  with(headers: {'Accept' => 'message/rfc2822'}).to_return(@json_response)
99
97
 
100
- @client.get_mime_message(key).must_equal(@json_response_object)
98
+ @client.get_mime_message(@id).must_equal(@json_response_object)
101
99
  end
102
100
  end
103
101
 
104
102
  describe 'send_message method' do
105
103
  it 'posts to the domain messages resource and returns the response object' do
106
- stub_request(:post, "#@base_url/#@domain/messages").to_return(@json_response)
104
+ stub_request(:post, "#@base_url/#@domain/messages").with(body: "to=#@encoded_address").to_return(@json_response)
107
105
 
108
- @client.send_message({}).must_equal(@json_response_object)
109
- end
110
-
111
- it 'encodes the message attributes' do
112
- stub_request(:post, "#@base_url/#@domain/messages").with(body: "to=#@encoded_address")
113
-
114
- @client.send_message({to: @address})
106
+ @client.send_message({to: @address}).must_equal(@json_response_object)
115
107
  end
116
108
 
117
109
  it 'raises an exception if the domain is not provided' do
@@ -158,11 +150,9 @@ describe 'Mailgunner::Client' do
158
150
 
159
151
  describe 'delete_message method' do
160
152
  it 'deletes the domain message resource with the given key and returns the response object' do
161
- key = 'WyIzMmkey'
162
-
163
- stub_request(:delete, "#@base_url/domains/#@domain/messages/#{key}").to_return(@json_response)
153
+ stub_request(:delete, "#@base_url/domains/#@domain/messages/#@id").to_return(@json_response)
164
154
 
165
- @client.delete_message(key)
155
+ @client.delete_message(@id).must_equal(@json_response_object)
166
156
  end
167
157
  end
168
158
 
@@ -184,15 +174,9 @@ describe 'Mailgunner::Client' do
184
174
 
185
175
  describe 'add_domain method' do
186
176
  it 'posts to the domains resource and returns the response object' do
187
- stub_request(:post, "#@base_url/domains").to_return(@json_response)
188
-
189
- @client.add_domain({}).must_equal(@json_response_object)
190
- end
191
-
192
- it 'encodes the domain attributes' do
193
- stub_request(:post, "#@base_url/domains").with(body: "name=#@domain")
177
+ stub_request(:post, "#@base_url/domains").with(body: "name=#@domain").to_return(@json_response)
194
178
 
195
- @client.add_domain({name: @domain})
179
+ @client.add_domain({name: @domain}).must_equal(@json_response_object)
196
180
  end
197
181
  end
198
182
 
@@ -222,15 +206,9 @@ describe 'Mailgunner::Client' do
222
206
 
223
207
  describe 'update_credentials method' do
224
208
  it 'updates the domain credentials resource with the given login and returns the response object' do
225
- stub_request(:put, "#@base_url/domains/#@domain/credentials/#@login").to_return(@json_response)
209
+ stub_request(:put, "#@base_url/domains/#@domain/credentials/#@login").with(body: 'password=secret').to_return(@json_response)
226
210
 
227
- @client.update_credentials(@login, {}).must_equal(@json_response_object)
228
- end
229
-
230
- it 'encodes the password attribute' do
231
- stub_request(:put, "#@base_url/domains/#@domain/credentials/#@login").with(body: 'password=secret')
232
-
233
- @client.update_credentials(@login, password: 'secret')
211
+ @client.update_credentials(@login, {password: 'secret'}).must_equal(@json_response_object)
234
212
  end
235
213
  end
236
214
 
@@ -242,6 +220,22 @@ describe 'Mailgunner::Client' do
242
220
  end
243
221
  end
244
222
 
223
+ describe 'get_connection_settings method' do
224
+ it 'fetches the domain connection settings resource and returns the response object' do
225
+ stub_request(:get, "#@base_url/domains/#@domain/connection").to_return(@json_response)
226
+
227
+ @client.get_connection_settings.must_equal(@json_response_object)
228
+ end
229
+ end
230
+
231
+ describe 'update_connection_settings method' do
232
+ it 'updates the domain connection settings resource and returns the response object' do
233
+ stub_request(:put, "#@base_url/domains/#@domain/connection").with(body: 'require_tls=true').to_return(@json_response)
234
+
235
+ @client.update_connection_settings({require_tls: true}).must_equal(@json_response_object)
236
+ end
237
+ end
238
+
245
239
  describe 'get_unsubscribes method' do
246
240
  it 'fetches the domain unsubscribes resource and returns the response object' do
247
241
  stub_request(:get, "#@base_url/#@domain/unsubscribes").to_return(@json_response)
@@ -274,15 +268,9 @@ describe 'Mailgunner::Client' do
274
268
 
275
269
  describe 'add_unsubscribe method' do
276
270
  it 'posts to the domain unsubscribes resource and returns the response object' do
277
- stub_request(:post, "#@base_url/#@domain/unsubscribes").to_return(@json_response)
271
+ stub_request(:post, "#@base_url/#@domain/unsubscribes").with(body: "address=#@encoded_address").to_return(@json_response)
278
272
 
279
- @client.add_unsubscribe({}).must_equal(@json_response_object)
280
- end
281
-
282
- it 'encodes the unsubscribe attributes' do
283
- stub_request(:post, "#@base_url/#@domain/unsubscribes").with(body: "address=#@encoded_address")
284
-
285
- @client.add_unsubscribe({address: @address})
273
+ @client.add_unsubscribe({address: @address}).must_equal(@json_response_object)
286
274
  end
287
275
  end
288
276
 
@@ -310,15 +298,9 @@ describe 'Mailgunner::Client' do
310
298
 
311
299
  describe 'add_complaint method' do
312
300
  it 'posts to the domain complaints resource and returns the response object' do
313
- stub_request(:post, "#@base_url/#@domain/complaints").to_return(@json_response)
314
-
315
- @client.add_complaint({}).must_equal(@json_response_object)
316
- end
317
-
318
- it 'encodes the complaint attributes' do
319
- stub_request(:post, "#@base_url/#@domain/complaints").with(body: "address=#@encoded_address")
301
+ stub_request(:post, "#@base_url/#@domain/complaints").with(body: "address=#@encoded_address").to_return(@json_response)
320
302
 
321
- @client.add_complaint({address: @address})
303
+ @client.add_complaint({address: @address}).must_equal(@json_response_object)
322
304
  end
323
305
  end
324
306
 
@@ -354,15 +336,9 @@ describe 'Mailgunner::Client' do
354
336
 
355
337
  describe 'add_bounce method' do
356
338
  it 'posts to the domain bounces resource and returns the response object' do
357
- stub_request(:post, "#@base_url/#@domain/bounces").to_return(@json_response)
339
+ stub_request(:post, "#@base_url/#@domain/bounces").with(body: "address=#@encoded_address").to_return(@json_response)
358
340
 
359
- @client.add_bounce({}).must_equal(@json_response_object)
360
- end
361
-
362
- it 'encodes the bounce attributes' do
363
- stub_request(:post, "#@base_url/#@domain/bounces").with(body: "address=#@encoded_address")
364
-
365
- @client.add_bounce({address: @address})
341
+ @client.add_bounce({address: @address}).must_equal(@json_response_object)
366
342
  end
367
343
  end
368
344
 
@@ -374,6 +350,14 @@ describe 'Mailgunner::Client' do
374
350
  end
375
351
  end
376
352
 
353
+ describe 'delete_bounces method' do
354
+ it 'deletes the domain bounces resource and returns the response object' do
355
+ stub_request(:delete, "#@base_url/#@domain/bounces").to_return(@json_response)
356
+
357
+ @client.delete_bounces.must_equal(@json_response_object)
358
+ end
359
+ end
360
+
377
361
  describe 'get_stats method' do
378
362
  before do
379
363
  Kernel.stubs(:warn)
@@ -440,6 +424,52 @@ describe 'Mailgunner::Client' do
440
424
  end
441
425
  end
442
426
 
427
+ describe 'get_tags method' do
428
+ it 'fetches the domain tags resource and returns the response object' do
429
+ stub_request(:get, "#@base_url/#@domain/tags").to_return(@json_response)
430
+
431
+ @client.get_tags.must_equal(@json_response_object)
432
+ end
433
+
434
+ it 'encodes optional limit parameter' do
435
+ stub_request(:get, "#@base_url/#@domain/tags?limit=2")
436
+
437
+ @client.get_tags(limit: 2)
438
+ end
439
+ end
440
+
441
+ describe 'get_tag method' do
442
+ it 'fetches the domain tag resource with the given id and returns the response object' do
443
+ stub_request(:get, "#@base_url/#@domain/tags/#@id").to_return(@json_response)
444
+
445
+ @client.get_tag(@id).must_equal(@json_response_object)
446
+ end
447
+ end
448
+
449
+ describe 'update_tag method' do
450
+ it 'updates the domain tag resource with the given id and returns the response object' do
451
+ stub_request(:put, "#@base_url/#@domain/tags/#@id").with(body: 'description=Tag+description').to_return(@json_response)
452
+
453
+ @client.update_tag(@id, {description: 'Tag description'}).must_equal(@json_response_object)
454
+ end
455
+ end
456
+
457
+ describe 'get_tag_stats method' do
458
+ it 'fetches the domain tag stats resource with the given id and returns the response object' do
459
+ stub_request(:get, "#@base_url/#@domain/tags/#@id/stats?event=accepted").to_return(@json_response)
460
+
461
+ @client.get_tag_stats(@id, event: 'accepted').must_equal(@json_response_object)
462
+ end
463
+ end
464
+
465
+ describe 'delete_tag method' do
466
+ it 'deletes the domain tag resource with the given id and returns the response object' do
467
+ stub_request(:delete, "#@base_url/#@domain/tags/#@id").to_return(@json_response)
468
+
469
+ @client.delete_tag(@id).must_equal(@json_response_object)
470
+ end
471
+ end
472
+
443
473
  describe 'get_routes method' do
444
474
  it 'fetches the routes resource and returns the response object' do
445
475
  stub_request(:get, "#@base_url/routes").to_return(@json_response)
@@ -456,45 +486,33 @@ describe 'Mailgunner::Client' do
456
486
 
457
487
  describe 'get_route method' do
458
488
  it 'fetches the route resource with the given id and returns the response object' do
459
- stub_request(:get, "#@base_url/routes/4f3bad2335335426750048c6").to_return(@json_response)
489
+ stub_request(:get, "#@base_url/routes/#@id").to_return(@json_response)
460
490
 
461
- @client.get_route('4f3bad2335335426750048c6').must_equal(@json_response_object)
491
+ @client.get_route(@id).must_equal(@json_response_object)
462
492
  end
463
493
  end
464
494
 
465
495
  describe 'add_route method' do
466
496
  it 'posts to the routes resource and returns the response object' do
467
- stub_request(:post, "#@base_url/routes").to_return(@json_response)
497
+ stub_request(:post, "#@base_url/routes").with(body: 'description=Example+route&priority=1').to_return(@json_response)
468
498
 
469
- @client.add_route({}).must_equal(@json_response_object)
470
- end
471
-
472
- it 'encodes the route attributes' do
473
- stub_request(:post, "#@base_url/routes").with(body: 'description=Example+route&priority=1')
474
-
475
- @client.add_route({description: 'Example route', priority: 1})
499
+ @client.add_route({description: 'Example route', priority: 1}).must_equal(@json_response_object)
476
500
  end
477
501
  end
478
502
 
479
503
  describe 'update_route method' do
480
504
  it 'updates the route resource with the given id and returns the response object' do
481
- stub_request(:put, "#@base_url/routes/4f3bad2335335426750048c6").to_return(@json_response)
505
+ stub_request(:put, "#@base_url/routes/#@id").with(body: 'priority=10').to_return(@json_response)
482
506
 
483
- @client.update_route('4f3bad2335335426750048c6', {}).must_equal(@json_response_object)
484
- end
485
-
486
- it 'encodes the route attributes' do
487
- stub_request(:put, "#@base_url/routes/4f3bad2335335426750048c6").with(body: 'priority=10')
488
-
489
- @client.update_route('4f3bad2335335426750048c6', {priority: 10})
507
+ @client.update_route(@id, {priority: 10}).must_equal(@json_response_object)
490
508
  end
491
509
  end
492
510
 
493
511
  describe 'delete_route method' do
494
512
  it 'deletes the route resource with the given id and returns the response object' do
495
- stub_request(:delete, "#@base_url/routes/4f3bad2335335426750048c6").to_return(@json_response)
513
+ stub_request(:delete, "#@base_url/routes/#@id").to_return(@json_response)
496
514
 
497
- @client.delete_route('4f3bad2335335426750048c6').must_equal(@json_response_object)
515
+ @client.delete_route(@id).must_equal(@json_response_object)
498
516
  end
499
517
  end
500
518
 
@@ -514,129 +532,117 @@ describe 'Mailgunner::Client' do
514
532
 
515
533
  describe 'get_campaign method' do
516
534
  it 'fetches the campaign resource with the given id and returns the response object' do
517
- stub_request(:get, "#@base_url/#@domain/campaigns/id").to_return(@json_response)
535
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id").to_return(@json_response)
518
536
 
519
- @client.get_campaign('id').must_equal(@json_response_object)
537
+ @client.get_campaign(@id).must_equal(@json_response_object)
520
538
  end
521
539
  end
522
540
 
523
541
  describe 'add_campaign method' do
524
542
  it 'posts to the domain campaigns resource and returns the response object' do
525
- stub_request(:post, "#@base_url/#@domain/campaigns").to_return(@json_response)
543
+ stub_request(:post, "#@base_url/#@domain/campaigns").with(body: "id=#@id").to_return(@json_response)
526
544
 
527
- @client.add_campaign({}).must_equal(@json_response_object)
528
- end
529
-
530
- it 'encodes the campaign attributes' do
531
- stub_request(:post, "#@base_url/#@domain/campaigns").with(body: 'id=id')
532
-
533
- @client.add_campaign({id: 'id'})
545
+ @client.add_campaign({id: @id}).must_equal(@json_response_object)
534
546
  end
535
547
  end
536
548
 
537
549
  describe 'update_campaign method' do
538
550
  it 'updates the campaign resource and returns the response object' do
539
- stub_request(:put, "#@base_url/#@domain/campaigns/id").to_return(@json_response)
540
-
541
- @client.update_campaign('id', {}).must_equal(@json_response_object)
542
- end
543
-
544
- it 'encodes the campaign attributes' do
545
- stub_request(:put, "#@base_url/#@domain/campaigns/id").with(body: 'name=Example+Campaign')
551
+ stub_request(:put, "#@base_url/#@domain/campaigns/#@id").with(body: 'name=Example+Campaign').to_return(@json_response)
546
552
 
547
- @client.update_campaign('id', {name: 'Example Campaign'})
553
+ @client.update_campaign(@id, {name: 'Example Campaign'}).must_equal(@json_response_object)
548
554
  end
549
555
  end
550
556
 
551
557
  describe 'delete_campaign method' do
552
558
  it 'deletes the domain campaign resource with the given id and returns the response object' do
553
- stub_request(:delete, "#@base_url/#@domain/campaigns/id").to_return(@json_response)
559
+ stub_request(:delete, "#@base_url/#@domain/campaigns/#@id").to_return(@json_response)
554
560
 
555
- @client.delete_campaign('id').must_equal(@json_response_object)
561
+ @client.delete_campaign(@id).must_equal(@json_response_object)
556
562
  end
557
563
  end
558
564
 
559
565
  describe 'get_campaign_events method' do
560
566
  it 'fetches the domain campaign events resource and returns the response object' do
561
- stub_request(:get, "#@base_url/#@domain/campaigns/id/events").to_return(@json_response)
567
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/events").to_return(@json_response)
562
568
 
563
- @client.get_campaign_events('id').must_equal(@json_response_object)
569
+ @client.get_campaign_events(@id).must_equal(@json_response_object)
564
570
  end
565
571
 
566
572
  it 'encodes the optional parameters' do
567
- stub_request(:get, "#@base_url/#@domain/campaigns/id/events?country=US&limit=100")
573
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/events?country=US&limit=100")
568
574
 
569
- @client.get_campaign_events('id', country: 'US', limit: 100)
575
+ @client.get_campaign_events(@id, country: 'US', limit: 100)
570
576
  end
571
577
  end
572
578
 
573
579
  describe 'get_campaign_stats method' do
574
580
  it 'fetches the domain campaign stats resource and returns the response object' do
575
- stub_request(:get, "#@base_url/#@domain/campaigns/id/stats").to_return(@json_response)
581
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/stats").to_return(@json_response)
576
582
 
577
- @client.get_campaign_stats('id').must_equal(@json_response_object)
583
+ @client.get_campaign_stats(@id).must_equal(@json_response_object)
578
584
  end
579
585
 
580
586
  it 'encodes the optional parameters' do
581
- stub_request(:get, "#@base_url/#@domain/campaigns/id/stats?groupby=dailyhour")
587
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/stats?groupby=dailyhour")
582
588
 
583
- @client.get_campaign_stats('id', groupby: 'dailyhour')
589
+ @client.get_campaign_stats(@id, groupby: 'dailyhour')
584
590
  end
585
591
  end
586
592
 
587
593
  describe 'get_campaign_clicks method' do
588
594
  it 'fetches the domain campaign clicks resource and returns the response object' do
589
- stub_request(:get, "#@base_url/#@domain/campaigns/id/clicks").to_return(@json_response)
595
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/clicks").to_return(@json_response)
590
596
 
591
- @client.get_campaign_clicks('id').must_equal(@json_response_object)
597
+ @client.get_campaign_clicks(@id).must_equal(@json_response_object)
592
598
  end
593
599
 
594
600
  it 'encodes the optional parameters' do
595
- stub_request(:get, "#@base_url/#@domain/campaigns/id/clicks?groupby=month&limit=100")
601
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/clicks?groupby=month&limit=100")
596
602
 
597
- @client.get_campaign_clicks('id', groupby: 'month', limit: 100)
603
+ @client.get_campaign_clicks(@id, groupby: 'month', limit: 100)
598
604
  end
599
605
  end
600
606
 
601
607
  describe 'get_campaign_opens method' do
602
608
  it 'fetches the domain campaign opens resource and returns the response object' do
603
- stub_request(:get, "#@base_url/#@domain/campaigns/id/opens").to_return(@json_response)
609
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/opens").to_return(@json_response)
604
610
 
605
- @client.get_campaign_opens('id').must_equal(@json_response_object)
611
+ @client.get_campaign_opens(@id).must_equal(@json_response_object)
606
612
  end
607
613
 
608
614
  it 'encodes the optional parameters' do
609
- stub_request(:get, "#@base_url/#@domain/campaigns/id/opens?groupby=month&limit=100")
615
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/opens?groupby=month&limit=100")
610
616
 
611
- @client.get_campaign_opens('id', groupby: 'month', limit: 100)
617
+ @client.get_campaign_opens(@id, groupby: 'month', limit: 100)
612
618
  end
613
619
  end
614
620
 
615
621
  describe 'get_campaign_unsubscribes method' do
616
622
  it 'fetches the domain campaign unsubscribes resource and returns the response object' do
617
- stub_request(:get, "#@base_url/#@domain/campaigns/id/unsubscribes").to_return(@json_response)
623
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes").to_return(@json_response)
618
624
 
619
- @client.get_campaign_unsubscribes('id').must_equal(@json_response_object)
625
+ @client.get_campaign_unsubscribes(@id).must_equal(@json_response_object)
620
626
  end
621
627
 
622
628
  it 'encodes the optional parameters' do
623
- stub_request(:get, "#@base_url/#@domain/campaigns/id/unsubscribes?groupby=month&limit=100")
629
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes?groupby=month&limit=100")
624
630
 
625
- @client.get_campaign_unsubscribes('id', groupby: 'month', limit: 100)
631
+ @client.get_campaign_unsubscribes(@id, groupby: 'month', limit: 100)
626
632
  end
627
633
  end
628
634
 
629
635
  describe 'get_campaign_complaints method' do
630
636
  it 'fetches the domain campaign complaints resource and returns the response object' do
631
- stub_request(:get, "#@base_url/#@domain/campaigns/id/complaints").to_return(@json_response)
637
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/complaints").to_return(@json_response)
632
638
 
633
- @client.get_campaign_complaints('id').must_equal(@json_response_object)
639
+ @client.get_campaign_complaints(@id).must_equal(@json_response_object)
634
640
  end
635
641
 
636
642
  it 'encodes the optional parameters' do
637
- stub_request(:get, "#@base_url/#@domain/campaigns/id/complaints?groupby=month&limit=100")
643
+ stub_request(:get, "#@base_url/#@domain/campaigns/#@id/complaints?groupby=month&limit=100")
638
644
 
639
- @client.get_campaign_complaints('id', groupby: 'month', limit: 100)
645
+ @client.get_campaign_complaints(@id, groupby: 'month', limit: 100)
640
646
  end
641
647
  end
642
648
 
@@ -664,29 +670,17 @@ describe 'Mailgunner::Client' do
664
670
 
665
671
  describe 'add_list method' do
666
672
  it 'posts to the lists resource and returns the response object' do
667
- stub_request(:post, "#@base_url/lists").to_return(@json_response)
673
+ stub_request(:post, "#@base_url/lists").with(body: 'address=developers%40mailgun.net').to_return(@json_response)
668
674
 
669
- @client.add_list({}).must_equal(@json_response_object)
670
- end
671
-
672
- it 'encodes the list attributes' do
673
- stub_request(:post, "#@base_url/lists").with(body: 'address=developers%40mailgun.net')
674
-
675
- @client.add_list({address: 'developers@mailgun.net'})
675
+ @client.add_list({address: 'developers@mailgun.net'}).must_equal(@json_response_object)
676
676
  end
677
677
  end
678
678
 
679
679
  describe 'update_list method' do
680
680
  it 'updates the list resource and returns the response object' do
681
- stub_request(:put, "#@base_url/lists/developers%40mailgun.net").to_return(@json_response)
682
-
683
- @client.update_list('developers@mailgun.net', {}).must_equal(@json_response_object)
684
- end
685
-
686
- it 'encodes the list attributes' do
687
- stub_request(:put, "#@base_url/lists/developers%40mailgun.net").with(body: 'name=Example+list')
681
+ stub_request(:put, "#@base_url/lists/developers%40mailgun.net").with(body: 'name=Example+list').to_return(@json_response)
688
682
 
689
- @client.update_list('developers@mailgun.net', {name: 'Example list'})
683
+ @client.update_list('developers@mailgun.net', {name: 'Example list'}).must_equal(@json_response_object)
690
684
  end
691
685
  end
692
686
 
@@ -722,29 +716,17 @@ describe 'Mailgunner::Client' do
722
716
 
723
717
  describe 'add_list_member method' do
724
718
  it 'posts to the list members resource and returns the response object' do
725
- stub_request(:post, "#@base_url/lists/developers%40mailgun.net/members").to_return(@json_response)
719
+ stub_request(:post, "#@base_url/lists/developers%40mailgun.net/members").with(body: "address=#@encoded_address").to_return(@json_response)
726
720
 
727
- @client.add_list_member('developers@mailgun.net', {}).must_equal(@json_response_object)
728
- end
729
-
730
- it 'encodes the list attributes' do
731
- stub_request(:post, "#@base_url/lists/developers%40mailgun.net/members").with(body: "address=#@encoded_address")
732
-
733
- @client.add_list_member('developers@mailgun.net', {address: @address})
721
+ @client.add_list_member('developers@mailgun.net', {address: @address}).must_equal(@json_response_object)
734
722
  end
735
723
  end
736
724
 
737
725
  describe 'update_list_member method' do
738
726
  it 'updates the list member resource with the given address and returns the response object' do
739
- stub_request(:put, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address").to_return(@json_response)
740
-
741
- @client.update_list_member('developers@mailgun.net', @address, {}).must_equal(@json_response_object)
742
- end
727
+ stub_request(:put, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address").with(body: 'subscribed=no').to_return(@json_response)
743
728
 
744
- it 'encodes the list member attributes' do
745
- stub_request(:put, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address").with(body: 'subscribed=no')
746
-
747
- @client.update_list_member('developers@mailgun.net', @address, {subscribed: 'no'})
729
+ @client.update_list_member('developers@mailgun.net', @address, {subscribed: 'no'}).must_equal(@json_response_object)
748
730
  end
749
731
  end
750
732
 
@@ -755,4 +737,12 @@ describe 'Mailgunner::Client' do
755
737
  @client.delete_list_member('developers@mailgun.net', @address).must_equal(@json_response_object)
756
738
  end
757
739
  end
740
+
741
+ it 'sets the user agent header' do
742
+ headers = {'User-Agent' => /\ARuby\/\d+\.\d+\.\d+ Mailgunner\/\d+\.\d+\.\d+\z/}
743
+
744
+ stub_request(:get, "#@base_url/domains/#@domain/messages/#@id").with(headers: headers)
745
+
746
+ @client.get_message(@id)
747
+ end
758
748
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-28 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -92,6 +92,7 @@ files:
92
92
  - lib/mailgunner.rb
93
93
  - lib/mailgunner/delivery_method.rb
94
94
  - lib/mailgunner/railtie.rb
95
+ - lib/mailgunner/version.rb
95
96
  - mailgunner.gemspec
96
97
  - spec/mailgunner_delivery_method_spec.rb
97
98
  - spec/mailgunner_spec.rb