mailgun-ruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ module Mailgun
2
+
3
+ VERSION = "1.0.0"
4
+
5
+ end
data/mailgun.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailgun/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = "mailgun-ruby"
9
+ spec.version = Mailgun::VERSION
10
+ spec.homepage = "http://www.mailgun.com"
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.license = 'Apache'
13
+
14
+ spec.summary = "Mailgun's Official Ruby SDK"
15
+ spec.description = "This Gem allows you to interact with Mailgun's API. A few utilities are included!"
16
+
17
+ spec.authors = ["Mailgun", "Travis Swientek"]
18
+ spec.email = "support@mailgunhq.com"
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.post_install_message = %q{
26
+ ---------------------------------------------------------------
27
+ Congrats, you've successfully installed the Mailgun SDK!
28
+ Check out our documentation at http://documentation.mailgun.com
29
+
30
+ Contact us at support@mailgunhq.com with any questions.
31
+ ----------------------------------------------------------------
32
+ }
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.3"
35
+ spec.add_development_dependency "rspec", "~> 2.14"
36
+ spec.add_development_dependency "rake", "~> 10.1"
37
+
38
+ spec.add_dependency "rest-client", "~> 1.6"
39
+ spec.add_dependency "json", "~> 1.8"
40
+ spec.add_dependency "multimap", "~> 1.1"
41
+
42
+ end
@@ -0,0 +1,598 @@
1
+ require 'spec_helper'
2
+ require 'mailgun'
3
+
4
+ describe 'Mailgun instantiation' do
5
+ it 'instantiates an HttpClient object' do
6
+ expect {@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)}.not_to raise_error
7
+ end
8
+ end
9
+
10
+ describe 'The method send_message()' do
11
+ before(:all) do
12
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
13
+ random_number = rand(1 .. 5000000)
14
+ @domain = "integration-test-#{random_number}.example.com"
15
+ @mg_obj.post("domains", {:name => @domain})
16
+ end
17
+
18
+ it 'sends a standard message in test mode.' do
19
+ result = @mg_obj.send_message(@domain, {:from => 'bob@domain.com',
20
+ :to => 'sally@example.com',
21
+ :subject => 'Hash Integration Test',
22
+ :text => 'INTEGRATION TESTING',
23
+ 'o:testmode' => true})
24
+ result.to_hash!
25
+ result.body.should include("message")
26
+ result.body.should include("id")
27
+ end
28
+
29
+ it 'sends a message builder message in test mode.' do
30
+ mb_obj = Mailgun::MessageBuilder.new()
31
+ mb_obj.set_from_address("sender@example.com", {'first' => 'Sending', 'last' => 'User'})
32
+ mb_obj.add_recipient(:to, "recipient@example.com", {'first' => 'Recipient', 'last' => 'User'})
33
+ mb_obj.set_subject("Message Builder Integration Test")
34
+ mb_obj.set_text_body("This is the text body.")
35
+ mb_obj.set_test_mode(true)
36
+
37
+ result = @mg_obj.send_message(@domain, mb_obj)
38
+
39
+ result.to_hash!
40
+ result.body.should include("message")
41
+ result.body.should include("id")
42
+ end
43
+
44
+ it 'sends a custom MIME message in test mode.' do
45
+ mime_string = 'Delivered-To: mgbox01@gmail.com
46
+ Received: by luna.mailgun.net with HTTP; Tue, 26 Nov 2013 17:59:11 +0000
47
+ Mime-Version: 1.0
48
+ Content-Type: text/plain; charset="ascii"
49
+ Subject: Hello
50
+ From: Excited User <me@samples.mailgun.org>
51
+ To: sally@example.com
52
+ Message-Id: <20131126175911.25310.92289@samples.mailgun.org>
53
+ Content-Transfer-Encoding: 7bit
54
+ X-Mailgun-Sid: WyI2NTU4MSIsICJtZ2JveDAxQGdtYWlsLmNvbSIsICIxZmYiXQ==
55
+ Date: Tue, 26 Nov 2013 17:59:22 +0000
56
+ X-Mailgun-Drop-Message: yes
57
+ Sender: me@samples.mailgun.org
58
+
59
+ Testing some Mailgun awesomness!'
60
+
61
+ message_params = {:to => 'sally@example.com',
62
+ :message => mime_string}
63
+
64
+ result = @mg_obj.send_message(@domain, message_params)
65
+
66
+ result.to_hash!
67
+ result.body.should include("message")
68
+ result.body.should include("id")
69
+ end
70
+
71
+ after(:all) do
72
+ @mg_obj.delete("domains/#{@domain}")
73
+ end
74
+ end
75
+
76
+ describe 'For the domains endpoint' do
77
+ before(:all) do
78
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
79
+ random_number = rand(1 .. 5000000)
80
+ @domain = "integration-test-#{random_number}.example.com"
81
+ @result = @mg_obj.post("domains", {:name => @domain,
82
+ :smtp_password => 'super_secret',
83
+ :spam_action => 'tag'})
84
+
85
+ @result.to_hash!
86
+ @result.body.should include("domain")
87
+ expect(@result.body["domain"]["name"]).to eq(@domain)
88
+ expect(@result.body["domain"]["spam_action"]).to eq("tag")
89
+ expect(@result.body["domain"]["smtp_password"]).to eq("super_secret")
90
+ end
91
+
92
+ it 'get the domain.' do
93
+ result = @mg_obj.get("domains/#{@domain}")
94
+
95
+ result.to_hash!
96
+ result.body.should include("domain")
97
+ result.body["domain"]["name"].should eq(@domain)
98
+ end
99
+
100
+ it 'gets a list of domains.' do
101
+ result = @mg_obj.get("domains")
102
+
103
+ result.to_hash!
104
+ expect(result.body["total_count"]).to be > 0
105
+ end
106
+
107
+ it 'deletes a domain.' do
108
+ result = @mg_obj.delete("domains/#{@domain}")
109
+
110
+ result.to_hash!
111
+ expect(result.body["message"]).to eq("Domain has been deleted")
112
+ end
113
+
114
+ after(:all) do
115
+ @mg_obj.delete("domains/#{@domain}")
116
+ end
117
+ end
118
+
119
+ describe 'For the Unsubscribes endpoint' do
120
+ before(:all) do
121
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
122
+ random_number = rand(1 .. 5000000)
123
+ @domain = "integration-test-#{random_number}.example.com"
124
+ @mg_obj.post("domains", {:name => @domain})
125
+ end
126
+
127
+ before(:each) do
128
+ random_number = rand(1 .. 5000000)
129
+ @email = "integration-test-#{random_number}@example.com"
130
+ @result = @mg_obj.post("#{@domain}/unsubscribes",
131
+ {:address => @email,
132
+ :tag => '*'})
133
+
134
+ @result.to_hash!
135
+ expect(@result.body["message"]).to eq("Address has been added to the unsubscribes table")
136
+ expect(@result.body["address"]).to eq(@email)
137
+ end
138
+
139
+ it 'get an unsubscribee.' do
140
+ result = @mg_obj.get("#{@domain}/unsubscribes/#{@email}")
141
+
142
+ result.to_hash!
143
+ expect(result.body["total_count"]).to eq 1
144
+ expect(result.body["items"][0]["address"]).to eq(@email)
145
+ end
146
+
147
+ it 'gets a list of unsubscribes.' do
148
+ result = @mg_obj.get("#{@domain}/unsubscribes")
149
+
150
+ result.to_hash!
151
+ expect(result.body["total_count"]).to be > 0
152
+ end
153
+
154
+ after(:each) do
155
+ @mg_obj.delete("#{@domain}/unsubscribes/#{@email}")
156
+ end
157
+
158
+ after(:all) do
159
+ @mg_obj.delete("domains/#{@domain}")
160
+ end
161
+ end
162
+
163
+ describe 'For the Complaints endpoint' do
164
+ before(:all) do
165
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
166
+ random_number = rand(1 .. 5000000)
167
+ @domain = "integration-test-#{random_number}.example.com"
168
+ @mg_obj.post("domains", {:name => @domain})
169
+ end
170
+
171
+ before(:each) do
172
+ random_number = rand(1 .. 5000000)
173
+ @email = "integration-test-#{random_number}@example.com"
174
+ @result = @mg_obj.post("#{@domain}/complaints", {:address => @email})
175
+
176
+ @result.to_hash!
177
+ expect(@result.body["message"]).to eq("Address has been added to the complaints table")
178
+ expect(@result.body["address"]).to eq(@email)
179
+ end
180
+
181
+ it 'get a complaint.' do
182
+ result = @mg_obj.get("#{@domain}/complaints/#{@email}")
183
+
184
+ result.to_hash!
185
+ expect(result.body["complaint"]["count"]).to eq 1
186
+ expect(result.body["complaint"]["address"]).to eq(@email)
187
+ end
188
+
189
+ it 'gets a list of complaints.' do
190
+ result = @mg_obj.get("#{@domain}/complaints")
191
+
192
+ result.to_hash!
193
+ expect(result.body["total_count"]).to be > 0
194
+ end
195
+
196
+ after(:each) do
197
+ @mg_obj.delete("#{@domain}/complaints/#{@email}")
198
+ end
199
+
200
+ after(:all) do
201
+ @mg_obj.delete("domains/#{@domain}")
202
+ end
203
+ end
204
+
205
+ describe 'For the Bounces endpoint' do
206
+ before(:all) do
207
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
208
+ random_number = rand(1 .. 5000000)
209
+ @domain = "integration-test-#{random_number}.example.com"
210
+ @mg_obj.post("domains", {:name => @domain})
211
+ end
212
+
213
+ before(:each) do
214
+ random_number = rand(1 .. 5000000)
215
+ @email = "integration-test-#{random_number}@example.com"
216
+ @result = @mg_obj.post("#{@domain}/bounces",
217
+ {:address => @email,
218
+ :code => 550,
219
+ :error => "Integration Test"})
220
+
221
+ @result.to_hash!
222
+ expect(@result.body["message"]).to eq("Address has been added to the bounces table")
223
+ expect(@result.body["address"]).to eq(@email)
224
+ end
225
+
226
+ it 'get a bounce.' do
227
+ result = @mg_obj.get("#{@domain}/bounces/#{@email}")
228
+
229
+ result.to_hash!
230
+ expect(result.body["bounce"]["code"]).to eq("550")
231
+ expect(result.body["bounce"]["address"]).to eq(@email)
232
+ expect(result.body["bounce"]["error"]).to eq("Integration Test")
233
+ end
234
+
235
+ it 'gets a list of bounces.' do
236
+ result = @mg_obj.get("#{@domain}/bounces")
237
+
238
+ result.to_hash!
239
+ expect(result.body["total_count"]).to be > 0
240
+ end
241
+
242
+ after(:each) do
243
+ @mg_obj.delete("#{@domain}/bounces/#{@email}")
244
+ end
245
+
246
+ after(:all) do
247
+ @mg_obj.delete("domains/#{@domain}")
248
+ end
249
+ end
250
+
251
+ describe 'For the Stats endpoint' do
252
+ before(:all) do
253
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
254
+ random_number = rand(1 .. 5000000)
255
+ @domain = "integration-test-#{random_number}.example.com"
256
+ @mg_obj.post("domains", {:name => @domain})
257
+ end
258
+
259
+ it 'get some stats.' do
260
+ @mg_obj.get("#{@domain}/stats", {:limit => 50, :skip => 10, :event => 'sent'})
261
+ end
262
+
263
+ after(:all) do
264
+ @mg_obj.delete("domains/#{@domain}")
265
+ end
266
+ end
267
+
268
+ describe 'For the Events endpoint' do
269
+ before(:all) do
270
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
271
+ random_number = rand(1 .. 5000000)
272
+ @domain = "integration-test-#{random_number}.example.com"
273
+ @mg_obj.post("domains", {:name => @domain})
274
+ end
275
+
276
+ it 'get an event.' do
277
+ result = @mg_obj.get("#{@domain}/events", {:limit => 1})
278
+
279
+ result.to_hash!
280
+ expect(result.body["items"].length).to be_within(1).of(1)
281
+ expect(result.body["paging"]).to include("next")
282
+ expect(result.body["paging"]).to include("previous")
283
+ end
284
+
285
+ after(:all) do
286
+ @mg_obj.delete("domains/#{@domain}")
287
+ end
288
+ end
289
+
290
+ describe 'For the Routes endpoint' do
291
+ before(:all) do
292
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
293
+ end
294
+
295
+ before(:each) do
296
+ result = @mg_obj.post("routes", {:priority => 10,
297
+ :description => 'Integration Test Route',
298
+ :expression => 'match_recipient(".*@example.com")',
299
+ :action => 'forward("alice@example.com")'})
300
+
301
+ result.to_hash!
302
+ expect(result.body["message"]).to eq("Route has been created")
303
+ expect(result.body["route"]["description"]).to eq("Integration Test Route")
304
+ expect(result.body["route"]["actions"]).to include('forward("alice@example.com")')
305
+ expect(result.body["route"]["expression"]).to include('match_recipient(".*@example.com")')
306
+ expect(result.body["route"]["priority"]).to eq(10)
307
+
308
+ @route_id = result.body["route"]["id"]
309
+ end
310
+
311
+ it 'get the route.' do
312
+ result = @mg_obj.get("routes/#{@route_id}")
313
+
314
+ result.to_hash!
315
+ expect(result.body["route"]["description"]).to eq("Integration Test Route")
316
+ expect(result.body["route"]["actions"]).to include('forward("alice@example.com")')
317
+ expect(result.body["route"]["expression"]).to include('match_recipient(".*@example.com")')
318
+ expect(result.body["route"]["priority"]).to eq(10)
319
+ end
320
+
321
+ it 'gets a list of all routes.' do
322
+ result = @mg_obj.get("routes", {:limit => 50})
323
+
324
+ result.to_hash!
325
+ expect(result.body["total_count"]).to be > 0
326
+ end
327
+
328
+ it 'updates the route.' do
329
+ result = @mg_obj.put("routes/#{@route_id}", {:priority => 10,
330
+ :description => 'Integration Test Route Update',
331
+ :expression => 'match_recipient(".*@example.com")',
332
+ :action => 'forward("update@example.com")'})
333
+
334
+ result.to_hash!
335
+ expect(result.body["message"]).to eq("Route has been updated")
336
+ expect(result.body["description"]).to eq("Integration Test Route Update")
337
+ expect(result.body["actions"]).to include('forward("update@example.com")')
338
+ expect(result.body["expression"]).to include('match_recipient(".*@example.com")')
339
+ expect(result.body["priority"]).to eq(10)
340
+ end
341
+
342
+ after(:each) do
343
+ @mg_obj.delete("routes/#{@route_id}")
344
+ end
345
+ end
346
+
347
+ describe 'For the campaigns endpoint' do
348
+ before(:all) do
349
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
350
+ random_number = rand(1 .. 5000000)
351
+ @domain = "integration-test-#{random_number}.example.com"
352
+ @mg_obj.post("domains", {:name => @domain})
353
+ end
354
+
355
+ before(:each) do
356
+ random_number = rand(1 .. 5000000)
357
+ @campaign_id = "integration_test_#{random_number}"
358
+ result = @mg_obj.post("#{@domain}/campaigns", {:name => 'My Campaign',
359
+ :id => @campaign_id})
360
+
361
+ result.to_hash!
362
+ expect(result.body["message"]).to eq("Campaign created")
363
+ expect(result.body["campaign"]["id"]).to eq(@campaign_id)
364
+ expect(result.body["campaign"]["name"]).to eq('My Campaign')
365
+ end
366
+
367
+ it 'get a campaign.' do
368
+ result = @mg_obj.get("#{@domain}/campaigns/#{@campaign_id}")
369
+
370
+ result.to_hash!
371
+ expect(result.body["id"]).to eq(@campaign_id)
372
+ expect(result.body["name"]).to eq('My Campaign')
373
+ end
374
+
375
+ it 'gets a list of all campaigns.' do
376
+ result = @mg_obj.get("#{@domain}/campaigns", {:limit => 50})
377
+
378
+ result.to_hash!
379
+ expect(result.body["total_count"]).to be > 0
380
+ end
381
+
382
+ it 'update a campaign.' do
383
+ result = @mg_obj.put("#{@domain}/campaigns/#{@campaign_id}", {:name => 'My Updated Campaign',
384
+ :id => @campaign_id})
385
+
386
+ result.to_hash!
387
+ expect(result.body["message"]).to eq("Campaign updated")
388
+ expect(result.body["campaign"]["id"]).to eq(@campaign_id)
389
+ expect(result.body["campaign"]["name"]).to eq('My Updated Campaign')
390
+ end
391
+
392
+ it 'get campaign events.' do
393
+ expect{@mg_obj.get("#{@domain}/campaigns/#{@campaign_id}/events", {:groupby => "clicked"})}.not_to raise_error
394
+ end
395
+
396
+ it 'get campaign stats.' do
397
+ expect{@mg_obj.get("#{@domain}/campaigns/#{@campaign_id}/stats", {:groupby => "domain"})}.not_to raise_error
398
+ end
399
+
400
+ after(:each) do
401
+ @mg_obj.delete("#{@domain}/campaigns/#{@campaign_id}")
402
+ end
403
+ after(:all) do
404
+ @mg_obj.delete("domains/#{@domain}")
405
+ end
406
+ end
407
+
408
+ describe 'For the webhooks endpoint' do
409
+ before(:all) do
410
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
411
+ random_number = rand(1 .. 5000000)
412
+ @domain = "integration-test-#{random_number}.example.com"
413
+ @mg_obj.post("domains", {:name => @domain})
414
+ end
415
+
416
+ before(:each) do
417
+ random_number = rand(1 .. 5000000)
418
+ @campaign_id = "integration_test_#{random_number}"
419
+ result = @mg_obj.post("domains/#{@domain}/webhooks", {:id => 'bounce',
420
+ :url => 'http://example.com/mailgun/events/bounce'})
421
+
422
+ result.to_hash!
423
+ expect(result.body["message"]).to eq("Webhook has been created")
424
+ expect(result.body["webhook"]["url"]).to eq('http://example.com/mailgun/events/bounce')
425
+ end
426
+
427
+ it 'get a webhook.' do
428
+ result = @mg_obj.get("domains/#{@domain}/webhooks/bounce")
429
+
430
+ result.to_hash!
431
+ expect(result.body["webhook"]["url"]).to eq('http://example.com/mailgun/events/bounce')
432
+ end
433
+
434
+ it 'gets a list of all webhooks.' do
435
+ result = @mg_obj.get("domains/#{@domain}/webhooks")
436
+
437
+ result.to_hash!
438
+ expect(result.body["webhooks"]["bounce"]["url"]).to eq('http://example.com/mailgun/events/bounce')
439
+ end
440
+
441
+ it 'update a webhook.' do
442
+ result = @mg_obj.put("domains/#{@domain}/webhooks/bounce", {:id => 'bounce',
443
+ :url => 'http://example.com/mailgun/events/new_bounce'})
444
+
445
+ result.to_hash!
446
+ expect(result.body["message"]).to eq("Webhook has been updated")
447
+ expect(result.body["webhook"]["url"]).to eq('http://example.com/mailgun/events/new_bounce')
448
+ end
449
+
450
+ after(:each) do
451
+ @mg_obj.delete("domains/#{@domain}/webhooks/bounce")
452
+ end
453
+
454
+ after(:all) do
455
+ @mg_obj.delete("domains/#{@domain}")
456
+ end
457
+ end
458
+
459
+ describe 'For the Mailing Lists endpoint' do
460
+ before(:all) do
461
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
462
+ random_number = rand(1 .. 5000000)
463
+ @domain = "integration-test-#{random_number}.example.com"
464
+ @mg_obj.post("domains", {:name => @domain})
465
+ end
466
+
467
+ before(:each) do
468
+ random_number = rand(1 .. 5000000)
469
+ @ml_address = "integration_test_#{random_number}@#{@domain}"
470
+ result = @mg_obj.post("lists", {:address => @ml_address,
471
+ :name => 'Integration Test List',
472
+ :description => 'This list should be deleted automatically.',
473
+ :access_level => 'members'})
474
+
475
+ result.to_hash!
476
+ expect(result.body["message"]).to eq("Mailing list has been created")
477
+ expect(result.body["list"]["address"]).to eq(@ml_address)
478
+ expect(result.body["list"]["name"]).to eq('Integration Test List')
479
+ end
480
+
481
+ it 'get a list.' do
482
+ result = @mg_obj.get("lists/#{@ml_address}")
483
+
484
+ result.to_hash!
485
+ expect(result.body["list"]["address"]).to eq(@ml_address)
486
+ expect(result.body["list"]["name"]).to eq('Integration Test List')
487
+ end
488
+
489
+ it 'gets a list of all lists.' do
490
+ result = @mg_obj.get("lists", {:limit => 50})
491
+
492
+ result.to_hash!
493
+ expect(result.body["total_count"]).to be > 0
494
+ end
495
+
496
+ it 'update a list.' do
497
+ result = @mg_obj.put("lists/#{@ml_address}",
498
+ {:address => @ml_address,
499
+ :name => 'Integration Test List Update',
500
+ :description => 'This list should be deleted automatically.',
501
+ :access_level => 'readonly'})
502
+
503
+ result.to_hash!
504
+ expect(result.body["message"]).to eq("Mailing list has been updated")
505
+ expect(result.body["list"]["address"]).to eq(@ml_address)
506
+ expect(result.body["list"]["name"]).to eq('Integration Test List Update')
507
+ expect(result.body["list"]["access_level"]).to eq('readonly')
508
+ end
509
+
510
+ after(:each) do
511
+ @mg_obj.delete("lists/#{@ml_address}")
512
+ end
513
+
514
+ after(:all) do
515
+ @mg_obj.delete("domains/#{@domain}")
516
+ end
517
+ end
518
+
519
+ describe 'For the Mailing Lists Members endpoint' do
520
+ before(:all) do
521
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
522
+ random_number = rand(1 .. 5000000)
523
+ @domain = "integration-test-#{random_number}.example.com"
524
+ @ml_address = "integration_test_#{random_number}@#{@domain}"
525
+ @ml_member = "integration_test_member_#{random_number}@#{@domain}"
526
+ @mg_obj.post("domains", {:name => @domain})
527
+ @mg_obj.post("lists", {:address => @ml_address,
528
+ :name => 'Integration Test List',
529
+ :description => 'This list should be deleted automatically.',
530
+ :access_level => 'members'})
531
+ end
532
+
533
+ before(:each) do
534
+ result = @mg_obj.post("lists/#{@ml_address}/members",
535
+ {:address => @ml_member,
536
+ :name => 'Jane Doe',
537
+ :subscribed => true,
538
+ :upsert => 'no'})
539
+
540
+ result.to_hash!
541
+ expect(result.body["message"]).to eq("Mailing list member has been created")
542
+ expect(result.body["member"]["address"]).to eq(@ml_member)
543
+ expect(result.body["member"]["name"]).to eq('Jane Doe')
544
+ end
545
+
546
+ it 'get a list member.' do
547
+ result = @mg_obj.get("lists/#{@ml_address}/members/#{@ml_member}")
548
+
549
+ result.to_hash!
550
+ expect(result.body["member"]["address"]).to eq(@ml_member)
551
+ expect(result.body["member"]["name"]).to eq('Jane Doe')
552
+ end
553
+
554
+ it 'updates a list member.' do
555
+ result = @mg_obj.put("lists/#{@ml_address}/members/#{@ml_member}",
556
+ {:name => 'Jane Doe Update',
557
+ :subscribed => false})
558
+
559
+ result.to_hash!
560
+ expect(result.body["message"]).to eq("Mailing list member has been updated")
561
+ expect(result.body["member"]["address"]).to eq(@ml_member)
562
+ expect(result.body["member"]["name"]).to eq('Jane Doe Update')
563
+ expect(result.body["member"]["subscribed"]).to eq(false)
564
+ end
565
+
566
+ after(:each) do
567
+ @mg_obj.delete("lists/#{@ml_address}/members/#{@ml_member}")
568
+ end
569
+
570
+ after(:all) do
571
+ @mg_obj.delete("domains/#{@domain}")
572
+ end
573
+ end
574
+
575
+ describe 'For the Email Validation endpoint' do
576
+ before(:all) do
577
+ @mg_obj = Mailgun::Client.new(PUB_APIKEY)
578
+ end
579
+
580
+ it 'validates an address.' do
581
+ result = @mg_obj.get("address/validate",
582
+ {:address => "test@example.com"})
583
+
584
+ result.to_hash!
585
+ expect(result.body["is_valid"]).to eq(false)
586
+ expect(result.body["address"]).to eq("test@example.com")
587
+ end
588
+
589
+ it 'parses an address.' do
590
+ result = @mg_obj.get("address/parse",
591
+ {:addresses => "Alice <alice@example.com>,bob@example.com,example.com"})
592
+
593
+ result.to_hash!
594
+ expect(result.body["parsed"]).to include("Alice <alice@example.com>")
595
+ expect(result.body["parsed"]).to include("bob@example.com")
596
+ expect(result.body["unparseable"]).to include("example.com")
597
+ end
598
+ end