mailgun-ruby 1.2.8 → 1.2.9

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
  SHA256:
3
- metadata.gz: 84ab9b61b8cbfbb739f10e889834f96a21c949331ae01a10e657a6884ced8bf2
4
- data.tar.gz: a9f1fc8b89e867540dbd53bb5ea076b750e4e6670a6267e82c02540d57b7e47a
3
+ metadata.gz: f43539594603950ec212832426bd7755d2b61a466aa9a028eb54f1246687fa3d
4
+ data.tar.gz: 7c02110bf7e1aae3d6f18ad228e50954a058a36fc2e87b97bfc542ef71bb1a28
5
5
  SHA512:
6
- metadata.gz: 3abeb661fec6372da5ac9b6a517271320ef130e792a76e728aeb70fca45b34bda418329e29e45d4a53d427a70ebf2c6052448a317cdfebd9fe72a5a31b90ad10
7
- data.tar.gz: 3c0d9a4a0e570ef095d2aa3b66ff2379544aebb9933a676b8922135c90fc682eb7e27255933d196b6744edf98fdee87cc48f13945d49ee26ba928906deff0a99
6
+ metadata.gz: 96a39b566bd9b58ad0d799e22742f30b35d6e5d20af43f867fb4412c11408aece5eada65e6bd4153d11028553a2275b0317243eab52c1159b572e508a5192918
7
+ data.tar.gz: d1ab619f72f158253a353e53416d03730c0d37f957757a8294580ddaa98cdf912aa0d384a69e55702658450d12922b43c0ef780be6a044edf73248246a253bb5
data/README.md CHANGED
@@ -19,7 +19,7 @@ gem install mailgun-ruby
19
19
  Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'mailgun-ruby', '~>1.2.8'
22
+ gem 'mailgun-ruby', '~>1.2.9'
23
23
  ```
24
24
 
25
25
  Usage
data/docs/Domains.md CHANGED
@@ -28,6 +28,9 @@ domainer.create 'my.new.moreness', { some: 'options' }
28
28
 
29
29
  # Remove a domain
30
30
  domainer.remove 'this.one.is.not.needed.'
31
+
32
+ # Update a domain
33
+ domainer.update 'my.new.moreness', { some: 'options' }
31
34
  ```
32
35
 
33
36
  Suppressions for a Domain
data/docs/Snippets.md CHANGED
@@ -110,7 +110,7 @@ bm_obj.set_text_body "This is the text body."
110
110
  bm_obj.add_recipient :to, "a_user@example.com"
111
111
 
112
112
  # All message IDs returned in finalize method return
113
- message_ids = @bm_obj.finalize
113
+ message_ids = bm_obj.finalize
114
114
  ```
115
115
 
116
116
  ### Domains:
@@ -118,57 +118,57 @@ ____________________________________________________
118
118
  **Get a list of all domains:**
119
119
 
120
120
  ```ruby
121
- result = @mg_client.get "domains", {:limit => 5, :skip => 0}
121
+ result = mg_client.get "domains", {:limit => 5, :skip => 0}
122
122
  ```
123
123
 
124
124
  **Get a single domain:**
125
125
 
126
126
  ```ruby
127
- result = @mg_client.get "domains/#{domain}"
127
+ result = mg_client.get "domains/#{domain}"
128
128
  ```
129
129
 
130
130
  **Add a domain:**
131
131
 
132
132
  ```ruby
133
- result = @mg_client.post "domains", {:name => 'anothersample.mailgun.org',
133
+ result = mg_client.post "domains", {:name => 'anothersample.mailgun.org',
134
134
  :smtp_password => 'super_secret',
135
135
  :spam_action => 'tag'}
136
136
  ```
137
137
  **Delete a Domain: **
138
138
 
139
139
  ```ruby
140
- result = @mg_client.delete "domains/#{domain}"
140
+ result = mg_client.delete "domains/#{domain}"
141
141
  ```
142
142
  ### Unsubscribes:
143
143
  ____________________________________________________
144
144
  **Get List of Unsubscribes: **
145
145
 
146
146
  ```ruby
147
- result = @mg_client.get "#{domain}/unsubscribes", {:limit => 50, :skip => 10}
147
+ result = mg_client.get "#{domain}/unsubscribes", {:limit => 50, :skip => 10}
148
148
  ```
149
149
 
150
150
  **Get Single Unsubscribe: **
151
151
 
152
152
  ```ruby
153
- result = @mg_client.get "#{domain}/unsubscribes/#{email_address}"
153
+ result = mg_client.get "#{domain}/unsubscribes/#{email_address}"
154
154
  ```
155
155
 
156
156
  **Unsubscribe a Recipient: **
157
157
 
158
158
  ```ruby
159
- result = @mg_client.post "#{domain}/unsubscribes", {:address => 'bob@example.com', :tag => 'mypromotion'}
159
+ result = mg_client.post "#{domain}/unsubscribes", {:address => 'bob@example.com', :tag => 'mypromotion'}
160
160
  ```
161
161
 
162
162
  **Unsubscribe from all messages for a domain: **
163
163
 
164
164
  ```ruby
165
- result = @mg_client.post "#{domain}/unsubscribes", {:address => 'bob@example.com', :tag => '*'}
165
+ result = mg_client.post "#{domain}/unsubscribes", {:address => 'bob@example.com', :tag => '*'}
166
166
  ```
167
167
 
168
168
  **Remove an unsubscribe: **
169
169
 
170
170
  ```ruby
171
- result = @mg_client.delete "#{domain}/unsubscribes/#{email_address}"
171
+ result = mg_client.delete "#{domain}/unsubscribes/#{email_address}"
172
172
  ```
173
173
 
174
174
  ### Complaints:
@@ -176,24 +176,24 @@ ____________________________________________________
176
176
  **Get List of Complaints: **
177
177
 
178
178
  ```ruby
179
- result = @mg_client.get "#{domain}/complaints", {:limit => 50, :skip => 10}
179
+ result = mg_client.get "#{domain}/complaints", {:limit => 50, :skip => 10}
180
180
  ```
181
181
 
182
182
  **Get a Single Complaint: **
183
183
 
184
184
  ```ruby
185
- result = @mg_client.get "#{domain}/complaints/#{email_address}"
185
+ result = mg_client.get "#{domain}/complaints/#{email_address}"
186
186
  ```
187
187
  **Create a complaint: **
188
188
 
189
189
  ```ruby
190
- result = @mg_client.post "#{domain}/complaint", {:address => 'bob@example.com'}
190
+ result = mg_client.post "#{domain}/complaint", {:address => 'bob@example.com'}
191
191
  ```
192
192
 
193
193
  **Remove a complaint: **
194
194
 
195
195
  ```ruby
196
- result = @mg_client.delete "#{domain}/complaint/#{email_address}"
196
+ result = mg_client.delete "#{domain}/complaint/#{email_address}"
197
197
  ```
198
198
 
199
199
  ### Bounces:
@@ -201,19 +201,19 @@ ____________________________________________________
201
201
  **Get List of Bounces: **
202
202
 
203
203
  ```ruby
204
- result = @mg_client.get "#{domain}/bounces", {:limit => 50, :skip => 10}
204
+ result = mg_client.get "#{domain}/bounces", {:limit => 50, :skip => 10}
205
205
  ```
206
206
 
207
207
  **Get a Single Bounce Event: **
208
208
 
209
209
  ```ruby
210
- result = @mg_client.get "#{domain}/bounces/#{email_address}"
210
+ result = mg_client.get "#{domain}/bounces/#{email_address}"
211
211
  ```
212
212
 
213
213
  **Create a Bounce: **
214
214
 
215
215
  ```ruby
216
- result = @mg_client.post "#{domain}/bounces", {:address => 'bob@example.com',
216
+ result = mg_client.post "#{domain}/bounces", {:address => 'bob@example.com',
217
217
  :code => 550,
218
218
  :error => 'Mailbox does not exist.'}
219
219
  ```
@@ -221,7 +221,7 @@ result = @mg_client.post "#{domain}/bounces", {:address => 'bob@example.com',
221
221
  **Remove a Bounced Address: **
222
222
 
223
223
  ```ruby
224
- result = @mg_client.delete "#{domain}/bounces/#{email_address}"
224
+ result = mg_client.delete "#{domain}/bounces/#{email_address}"
225
225
  ```
226
226
 
227
227
  ### Statistics:
@@ -229,7 +229,7 @@ ____________________________________________________
229
229
  **Get Statistics: **
230
230
 
231
231
  ```ruby
232
- result = @mg_client.get "#{domain}/stats", {:limit => 50,
232
+ result = mg_client.get "#{domain}/stats", {:limit => 50,
233
233
  :skip => 10,
234
234
  :event => 'sent',
235
235
  "start-date" => 'Mon, 13 Feb 2015 00:00:00 GMT'}
@@ -238,14 +238,14 @@ result = @mg_client.get "#{domain}/stats", {:limit => 50,
238
238
  **Remove a Tag: **
239
239
 
240
240
  ```ruby
241
- result = @mg_client.delete "#{domain}/tags/#{tag}"
241
+ result = mg_client.delete "#{domain}/tags/#{tag}"
242
242
  ```
243
243
  ### Events:
244
244
  ____________________________________________________
245
245
  **Get Event: **
246
246
 
247
247
  ```ruby
248
- result = @mg_client.get "#{domain}/events", {:event => 'rejected'}
248
+ result = mg_client.get "#{domain}/events", {:event => 'rejected'}
249
249
  ```
250
250
 
251
251
  ### Routes:
@@ -253,18 +253,18 @@ ____________________________________________________
253
253
  **Get List of Routes: **
254
254
 
255
255
  ```ruby
256
- result = @mg_client.get "routes", {:limit => 50, :skip => 10}
256
+ result = mg_client.get "routes", {:limit => 50, :skip => 10}
257
257
  ```
258
258
 
259
259
  **Get a Single Route by ID: **
260
260
 
261
261
  ```ruby
262
- result = @mg_client.get "routes/#{route_id}"
262
+ result = mg_client.get "routes/#{route_id}"
263
263
  ```
264
264
  **Create a Route: **
265
265
 
266
266
  ```ruby
267
- result = @mg_client.post "routes", {:priority => 10,
267
+ result = mg_client.post "routes", {:priority => 10,
268
268
  :description => 'This is a test route',
269
269
  :expression => 'match_recipient(".*@gmail.com")',
270
270
  :action => 'forward("alice@example.com")'}
@@ -272,7 +272,7 @@ result = @mg_client.post "routes", {:priority => 10,
272
272
  **Update a Route: **
273
273
 
274
274
  ```ruby
275
- result = @mg_client.put "routes/#{route_id}", {:priority => 10,
275
+ result = mg_client.put "routes/#{route_id}", {:priority => 10,
276
276
  :description => 'This is a test route',
277
277
  :expression => 'match_recipient(".*@gmail.com")',
278
278
  :action => 'forward("alice@example.com")'}
@@ -280,46 +280,46 @@ result = @mg_client.put "routes/#{route_id}", {:priority => 10,
280
280
  **Remove a Route: **
281
281
 
282
282
  ```ruby
283
- result = @mg_client.delete "routes/#{route_id}"
283
+ result = mg_client.delete "routes/#{route_id}"
284
284
  ```
285
285
  ### Campaigns:
286
286
  ____________________________________________________
287
287
  **Get List of Campaigns: **
288
288
 
289
289
  ```ruby
290
- result = @mg_client.get "#{domain}/campaigns", {:limit => 50, :skip => 10}
290
+ result = mg_client.get "#{domain}/campaigns", {:limit => 50, :skip => 10}
291
291
  ```
292
292
 
293
293
  **Get a Single Campaign: **
294
294
 
295
295
  ```ruby
296
- result = @mg_client.get "#{domain}/campaigns/#{campaign_id}"
296
+ result = mg_client.get "#{domain}/campaigns/#{campaign_id}"
297
297
  ```
298
298
 
299
299
  **Create a Campaign: **
300
300
 
301
301
  ```ruby
302
- result = @mg_client.post "#{domain}/campaigns", {:name => 'My Campaign',
302
+ result = mg_client.post "#{domain}/campaigns", {:name => 'My Campaign',
303
303
  :id => 'campaign_123_2014'}
304
304
  ```
305
305
 
306
306
  **Update a Campaign: **
307
307
 
308
308
  ```ruby
309
- result = @mg_client.put "#{domain}/campaigns/#{campaign_id}", {:name => 'My Campaign',
309
+ result = mg_client.put "#{domain}/campaigns/#{campaign_id}", {:name => 'My Campaign',
310
310
  :id => 'campaign_123_2014'}
311
311
  ```
312
312
 
313
313
  **Remove a Campaign: **
314
314
 
315
315
  ```ruby
316
- result = @mg_client.delete "#{domain}/campaigns/#{campaign_id}"
316
+ result = mg_client.delete "#{domain}/campaigns/#{campaign_id}"
317
317
  ```
318
318
 
319
319
  **Get Campaign Events: **
320
320
 
321
321
  ```ruby
322
- result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/events", {:event => 'clicked',
322
+ result = mg_client.get "#{domain}/campaigns/#{campaign_id}/events", {:event => 'clicked',
323
323
  :recipient => 'test@example.com',
324
324
  :country => 'US',
325
325
  :region => 'TX',
@@ -331,13 +331,13 @@ result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/events", {:event =>
331
331
  **Get a Single Campaign's Stats: **
332
332
 
333
333
  ```ruby
334
- result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/stats", {:groupby => 'domain'}
334
+ result = mg_client.get "#{domain}/campaigns/#{campaign_id}/stats", {:groupby => 'domain'}
335
335
  ```
336
336
 
337
337
  **Get a Single Campaign's Click Stats: **
338
338
 
339
339
  ```ruby
340
- result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/clicks", {:groupby => 'hour',
340
+ result = mg_client.get "#{domain}/campaigns/#{campaign_id}/clicks", {:groupby => 'hour',
341
341
  :country => 'US',
342
342
  :region => 'TX',
343
343
  :city => 'Austin',
@@ -349,7 +349,7 @@ result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/clicks", {:groupby =
349
349
  **Get a Single Campaign's Click Opens: **
350
350
 
351
351
  ```ruby
352
- result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/opens", {:groupby => 'hour',
352
+ result = mg_client.get "#{domain}/campaigns/#{campaign_id}/opens", {:groupby => 'hour',
353
353
  :country => 'US',
354
354
  :region => 'TX',
355
355
  :city => 'Austin',
@@ -361,7 +361,7 @@ result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/opens", {:groupby =>
361
361
  **Get a Single Campaign's Click Unsubscribes: **
362
362
 
363
363
  ```ruby
364
- result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/unsubscribes", {:groupby => 'hour',
364
+ result = mg_client.get "#{domain}/campaigns/#{campaign_id}/unsubscribes", {:groupby => 'hour',
365
365
  :country => 'US',
366
366
  :region => 'TX',
367
367
  :city => 'Austin',
@@ -373,7 +373,7 @@ result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/unsubscribes", {:gro
373
373
  **Get a Single Campaign's Click Complaints: **
374
374
 
375
375
  ```ruby
376
- result = @mg_client.get "#{domain}/campaigns/#{campaign_id}/complaints", {:groupby => 'hour',
376
+ result = mg_client.get "#{domain}/campaigns/#{campaign_id}/complaints", {:groupby => 'hour',
377
377
  :limit => 100,
378
378
  :page => 1,
379
379
  :count => true}
@@ -385,33 +385,33 @@ ____________________________________________________
385
385
  **Get List of Webhooks: **
386
386
 
387
387
  ```ruby
388
- result = @mg_client.get "domains/#{domain}/webhooks"
388
+ result = mg_client.get "domains/#{domain}/webhooks"
389
389
  ```
390
390
 
391
391
  **Get a Webhook Properties: **
392
392
 
393
393
  ```ruby
394
- result = @mg_client.get "domains/#{domain}/webhooks/#{webhook_id}"
394
+ result = mg_client.get "domains/#{domain}/webhooks/#{webhook_id}"
395
395
  ```
396
396
 
397
397
  **Create a Webhook: **
398
398
 
399
399
  ```ruby
400
- result = @mg_client.post "domains/#{domain}/webhooks", {:id => 'bounce',
400
+ result = mg_client.post "domains/#{domain}/webhooks", {:id => 'bounce',
401
401
  :url => 'http://example.com/mailgun/events/bounce'}
402
402
  ```
403
403
 
404
404
  **Update a Webhook: **
405
405
 
406
406
  ```ruby
407
- result = @mg_client.put "domains/#{domain}/webhooks/#{webhook_id}", {:id => 'bounce',
407
+ result = mg_client.put "domains/#{domain}/webhooks/#{webhook_id}", {:id => 'bounce',
408
408
  :url => 'http://example.com/mailgun/events/bounce'}
409
409
  ```
410
410
 
411
411
  **Remove a Webhook: **
412
412
 
413
413
  ```ruby
414
- result = @mg_client.delete "domains/#{domain}/webhooks/#{webhook_id}"
414
+ result = mg_client.delete "domains/#{domain}/webhooks/#{webhook_id}"
415
415
  ```
416
416
 
417
417
  ### Mailing Lists:
@@ -420,19 +420,19 @@ ____________________________________________________
420
420
  **Get list of Lists: **
421
421
 
422
422
  ```ruby
423
- result = @mg_client.get "lists"
423
+ result = mg_client.get "lists"
424
424
  ```
425
425
 
426
426
  **Get List Properties: **
427
427
 
428
428
  ```ruby
429
- result = @mg_client.get "lists/#{list_address}"
429
+ result = mg_client.get "lists/#{list_address}"
430
430
  ```
431
431
 
432
432
  **Create a List: **
433
433
 
434
434
  ```ruby
435
- result = @mg_client.post "lists", {:address => 'dev.group@samples.mailgun.org',
435
+ result = mg_client.post "lists", {:address => 'dev.group@samples.mailgun.org',
436
436
  :name => 'Development Group List',
437
437
  :description => 'List of all developers.',
438
438
  :access_level => 'members'}
@@ -441,7 +441,7 @@ result = @mg_client.post "lists", {:address => 'dev.group@samples.mailgun.org',
441
441
  **Update a List: **
442
442
 
443
443
  ```ruby
444
- result = @mg_client.put "lists/#{list_address}", {:address => 'dev.group@samples.mailgun.org',
444
+ result = mg_client.put "lists/#{list_address}", {:address => 'dev.group@samples.mailgun.org',
445
445
  :name => 'Development Group List',
446
446
  :description => 'List of all developers.',
447
447
  :access_level => 'members'}
@@ -450,25 +450,25 @@ result = @mg_client.put "lists/#{list_address}", {:address => 'dev.group@samples
450
450
  **Remove a List: **
451
451
 
452
452
  ```ruby
453
- result = @mg_client.delete "lists/#{list_address}"
453
+ result = mg_client.delete "lists/#{list_address}"
454
454
  ```
455
455
 
456
456
  **Get List Members: **
457
457
 
458
458
  ```ruby
459
- result = @mg_client.get "lists/#{list_address}/members"
459
+ result = mg_client.get "lists/#{list_address}/members"
460
460
  ```
461
461
 
462
462
  **Get List Member Properties: **
463
463
 
464
464
  ```ruby
465
- result = @mg_client.get "lists/#{list_address}/members/#{member_address}"
465
+ result = mg_client.get "lists/#{list_address}/members/#{member_address}"
466
466
  ```
467
467
 
468
468
  **Add Member to List: **
469
469
 
470
470
  ```ruby
471
- result = @mg_client.post "lists/#{list_address}/members/#{member_address}", {:address => 'jane@samples.mailgun.org',
471
+ result = mg_client.post "lists/#{list_address}/members/#{member_address}", {:address => 'jane@samples.mailgun.org',
472
472
  :name => 'Jane Doe',
473
473
  :vars => '{"first": "Jane", "last": "Doe"}',
474
474
  :subscribed => true,
@@ -478,7 +478,7 @@ result = @mg_client.post "lists/#{list_address}/members/#{member_address}", {:ad
478
478
  **Update Member on List: **
479
479
 
480
480
  ```ruby
481
- result = @mg_client.put "lists/#{list_address}/members/#{member_address}", {:address => 'jane@samples.mailgun.org',
481
+ result = mg_client.put "lists/#{list_address}/members/#{member_address}", {:address => 'jane@samples.mailgun.org',
482
482
  :name => 'Jane Doe',
483
483
  :vars => '{"first": "Jane", "last": "Doe"}',
484
484
  :subscribed => true}
@@ -487,13 +487,13 @@ result = @mg_client.put "lists/#{list_address}/members/#{member_address}", {:add
487
487
  **Delete a Member from List: **
488
488
 
489
489
  ```ruby
490
- result = @mg_client.delete "lists/#{list_address}/members/#{member_address}"
490
+ result = mg_client.delete "lists/#{list_address}/members/#{member_address}"
491
491
  ```
492
492
 
493
493
  **Get Stats for List: **
494
494
 
495
495
  ```ruby
496
- result = @mg_client.get "lists/#{list_address}/stats"
496
+ result = mg_client.get "lists/#{list_address}/stats"
497
497
  ```
498
498
 
499
499
  ### Email Validation:
@@ -501,14 +501,7 @@ ____________________________________________________
501
501
  **Validate Single Address: **
502
502
 
503
503
  ```ruby
504
- result = @mg_client.get "address/validate", {:address => 'test@example.com'}
505
- ```
506
-
507
- **Parse Addresses: **
508
-
509
- ```ruby
510
- result = @mg_client.get "address/parse", {:addresses => 'test@example.com, "First Last <first.last@example.com>',
511
- :syntax_only => true}
504
+ result = mg_client.get "address/validate", {:address => 'test@example.com'}
512
505
  ```
513
506
 
514
507
 
@@ -4,45 +4,20 @@ module Mailgun
4
4
 
5
5
  # Mailgun::Address is a simple interface to the Email Validation API.
6
6
  class Address
7
-
8
- # @param [String] api_key Mailgun API - public key
9
- def initialize(api_key = "")
10
- if api_key == "" then
11
- fail ParameterError.new('Public API key is required for Mailgun::Address.initialize()', nil)
12
- end
13
-
14
- @api_key = api_key
15
- @client = Mailgun::Client.new(api_key = api_key)
7
+ def initialize
8
+ @client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v4')
16
9
  end
17
10
 
18
11
  # Given an arbitrary address, validates it based on defined checks.
19
12
  #
20
13
  # @param [String] address Email address to validate (max 512 chars.)
21
14
  def validate(address, mailbox_verification = false)
22
- params = {:address => address}
15
+ params = {address: address}
23
16
  params[:mailbox_verification] = true if mailbox_verification
24
17
 
25
18
  res = @client.get "address/validate", params
26
19
  return res.to_h!
27
20
  end
28
-
29
- # Parses a delimiter separated list of email addresses into two lists:
30
- # parsed addresses and unparsable portions. The parsed addresses are a
31
- # list of addresses that are syntactically valid (and optionally have
32
- # DNS and ESP specific grammar checks) the unparsable list is a list
33
- # of characters sequences that the parser was not able to understand.
34
- # These often align with invalid email addresses, but not always.
35
- # Delimiter characters are comma (,) and semicolon (;).
36
- #
37
- # @param [Array] addresses Addresses to parse
38
- # @param [TrueClass|FalseClass] syntax_only Perform only syntax checks
39
- def parse(addresses, syntax_only = true)
40
- validate_addrs = addresses.join(";")
41
-
42
- res = @client.get "address/parse", {:addresses => validate_addrs,
43
- :syntax_only => syntax_only.to_s}
44
- return res.to_h!
45
- end
46
21
  end
47
22
 
48
23
  end
@@ -205,7 +205,16 @@ module Mailgun
205
205
  #
206
206
  # @param [StandardException] e upstream exception object
207
207
  def communication_error(e)
208
- return CommunicationError.new(e.message, e.response) if e.respond_to? :response
208
+ if e.respond_to?(:response)
209
+ return case e.response.code
210
+ when Unauthorized::CODE
211
+ Unauthorized.new(e.message, e.response)
212
+ when BadRequest::CODE
213
+ BadRequest.new(e.message, e.response)
214
+ else
215
+ CommunicationError.new(e.message, e.response)
216
+ end
217
+ end
209
218
  CommunicationError.new(e.message)
210
219
  end
211
220
 
@@ -53,8 +53,9 @@ module Mailgun
53
53
  # domain - [String] Name of the domain (ex. domain.com)
54
54
  # options - [Hash] of
55
55
  # smtp_password - [String] Password for SMTP authentication
56
- # spam_action - [String] disabled or tag
56
+ # spam_action - [String] disabled, blocked or tag
57
57
  # Disable, no spam filtering will occur for inbound messages.
58
+ # Block, inbound spam messages will not be delivered.
58
59
  # Tag, messages will be tagged wtih a spam header. See Spam Filter.
59
60
  # wildcard - [Boolean] true or false Determines whether the domain will accept email for sub-domains.
60
61
  #
@@ -80,5 +81,22 @@ module Mailgun
80
81
  alias_method :delete, :remove
81
82
  alias_method :delete_domain, :remove
82
83
 
84
+ # Public: Update domain
85
+ #
86
+ # domain - [String] Name of the domain (ex. domain.com)
87
+ # options - [Hash] of
88
+ # spam_action - [String] disabled, blocked or tag
89
+ # Disable, no spam filtering will occur for inbound messages.
90
+ # Block, inbound spam messages will not be delivered.
91
+ # Tag, messages will be tagged wtih a spam header. See Spam Filter.
92
+ # web_scheme - [String] http or https
93
+ # Set your open, click and unsubscribe URLs to use http or https
94
+ # wildcard - [Boolean] true or false Determines whether the domain will accept email for sub-domains.
95
+ #
96
+ # Returns [Hash] of updated domain
97
+ def update(domain, options = {})
98
+ fail(ParameterError, 'No domain given to add on Mailgun', caller) unless domain
99
+ @client.put("domains/#{domain}", options).to_h
100
+ end
83
101
  end
84
102
  end
@@ -58,7 +58,6 @@ module Mailgun
58
58
  rescue
59
59
  api_message = 'Unknown API error'
60
60
  end
61
- api_message = api_message + ' - Invalid Domain or API key' if api_message == FORBIDDEN
62
61
 
63
62
  message = message || ''
64
63
  message = message + ': ' + api_message
@@ -68,6 +67,26 @@ module Mailgun
68
67
  @code = NOCODE
69
68
  super(message, response)
70
69
  end
70
+ end
71
+
72
+ # Public: Class for managing unauthorized 401 errors
73
+ # Inherits from Mailgun::CommunicationError
74
+ class Unauthorized < CommunicationError
75
+ CODE = 401
71
76
 
77
+ def initialize(error_message, response)
78
+ error_message = error_message + ' - Invalid Domain or API key'
79
+ super(error_message, response)
80
+ end
81
+ end
82
+
83
+ # Public: Class for managing bad request 400 errors
84
+ # Inherits from Mailgun::CommunicationError
85
+ class BadRequest < CommunicationError
86
+ CODE = 400
87
+
88
+ def initialize(error_message, response)
89
+ super(error_message, response)
90
+ end
72
91
  end
73
92
  end
@@ -406,7 +406,7 @@ module Mailgun
406
406
  def make_json(obj)
407
407
  return JSON.parse(obj).to_json if obj.is_a?(String)
408
408
  return obj.to_json if obj.is_a?(Hash)
409
- return JSON.generate(obj).to_json
409
+ JSON.generate(obj).to_json
410
410
  rescue
411
411
  raise Mailgun::ParameterError, 'Provided data could not be made into JSON. Try a JSON string or Hash.', obj
412
412
  end
@@ -429,7 +429,7 @@ module Mailgun
429
429
  full_name = vars['full_name']
430
430
  elsif vars['first'] || vars['last']
431
431
  full_name = "#{vars['first']} #{vars['last']}".strip
432
- end
432
+ end
433
433
 
434
434
  return "'#{full_name}' <#{address}>" if full_name
435
435
  address
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.2.8'
3
+ VERSION = '1.2.9'
4
4
  end
@@ -33,7 +33,7 @@ module Railgun
33
33
  config[:api_version] || 'v3',
34
34
  config[:api_ssl].nil? ? true : config[:api_ssl],
35
35
  false,
36
- config[:timeout],
36
+ config[:timeout]
37
37
  )
38
38
  @domain = @config[:domain]
39
39
 
@@ -36,4 +36,12 @@ describe 'For the domains endpoint', vcr: vcr_opts do
36
36
 
37
37
  expect(result).to be_truthy
38
38
  end
39
+
40
+ it 'updates the domain' do
41
+ result = @mg_obj.update(@domain, { spam_action: 'block', web_scheme: 'https', wildcard: true })
42
+
43
+ expect(result['domain']["spam_action"]).to eq('block')
44
+ expect(result['domain']["web_scheme"]).to eq('https')
45
+ expect(result['domain']["wildcard"]).to eq(true)
46
+ end
39
47
  end
@@ -7,7 +7,7 @@ vcr_opts = { :cassette_name => "email_validation" }
7
7
 
8
8
  describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
9
9
  before(:all) do
10
- @mg_obj = Mailgun::Address.new(PUB_APIKEY)
10
+ @mg_obj = Mailgun::Address.new
11
11
 
12
12
  @valid = ["Alice <alice@example.com>", "bob@example.com"]
13
13
  @invalid = ["example.org"]
@@ -15,13 +15,6 @@ describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
15
15
  @all_addrs = @valid + @invalid
16
16
  end
17
17
 
18
- it 'returns parsed and unparsable lists' do
19
- res = @mg_obj.parse(@all_addrs)
20
-
21
- expect(res["parsed"]).to eq(@valid)
22
- expect(res["unparseable"]).to eq(@invalid)
23
- end
24
-
25
18
  it 'validates alice@mailgun.net with info' do
26
19
  res = @mg_obj.validate("alice@mailgun.net")
27
20
 
@@ -34,6 +34,78 @@ describe 'Client exceptions', vcr: vcr_opts do
34
34
  end
35
35
  end
36
36
 
37
+ vcr_opts = { :cassette_name => "exceptions-invalid-api-key" }
38
+
39
+ describe 'Client exceptions', vcr: vcr_opts do
40
+ before(:all) do
41
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
42
+ @domain = TESTDOMAIN
43
+ end
44
+
45
+ it 'displays error information that API key is invalid' do
46
+ begin
47
+ @mg_obj.send_message(@domain, {
48
+ :from => "sally@#{@domain}",
49
+ :to => "sally@#{@domain}",
50
+ :subject => 'Exception Integration Test',
51
+ :text => 'INTEGRATION TESTING'
52
+ })
53
+ rescue Mailgun::Unauthorized => err
54
+ expect(err.message).to eq('401 Unauthorized - Invalid Domain or API key: Forbidden')
55
+ else
56
+ fail
57
+ end
58
+ end
59
+ end
60
+
61
+ vcr_opts = { :cassette_name => "exceptions-invalid-data" }
62
+
63
+ describe 'Client exceptions', vcr: vcr_opts do
64
+ before(:all) do
65
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
66
+ @domain = TESTDOMAIN
67
+ end
68
+
69
+ it 'display useful error information' do
70
+ begin
71
+ @mg_obj.send_message(@domain, {
72
+ :from => "sally@#{@domain}",
73
+ :to => "sally#{@domain}",
74
+ :subject => 'Exception Integration Test',
75
+ :text => 'INTEGRATION TESTING'
76
+ })
77
+ rescue Mailgun::BadRequest => err
78
+ expect(err.message).to eq('400 Bad Request: to parameter is not a valid address. please check documentation')
79
+ else
80
+ fail
81
+ end
82
+ end
83
+ end
84
+
85
+ vcr_opts = { :cassette_name => "exceptions-not-allowed" }
86
+
87
+ describe 'Client exceptions', vcr: vcr_opts do
88
+ before(:all) do
89
+ @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
90
+ @domain = TESTDOMAIN
91
+ end
92
+
93
+ it 'display useful error information' do
94
+ begin
95
+ @mg_obj.send_message(@domain, {
96
+ :from => "invalid@#{@domain}",
97
+ :to => "invalid#{@domain}",
98
+ :subject => 'Exception Integration Test',
99
+ :text => 'INTEGRATION TESTING'
100
+ })
101
+ rescue Mailgun::CommunicationError => err
102
+ expect(err.message).to include('403 Forbidden')
103
+ else
104
+ fail
105
+ end
106
+ end
107
+ end
108
+
37
109
  vcr_opts = { :cassette_name => "send_message" }
38
110
 
39
111
  describe 'The method send_message()', vcr: vcr_opts do
@@ -357,4 +357,54 @@ http_interactions:
357
357
  }
358
358
  http_version:
359
359
  recorded_at: Fri, 15 Jan 2016 20:12:54 GMT
360
- recorded_with: VCR 3.0.1
360
+ - request:
361
+ method: put
362
+ uri: https://api.mailgun.net/v3/domains/integration-test.domain.invalid
363
+ body:
364
+ encoding: UTF-8
365
+ string: spam_action=block&web_scheme=https&wildcard=true
366
+ headers:
367
+ Accept:
368
+ - "*/*"
369
+ User-Agent:
370
+ - rest-client/2.1.0 (darwin21.6.0 x86_64) ruby/2.5.1p57
371
+ Content-Length:
372
+ - '48'
373
+ Content-Type:
374
+ - application/x-www-form-urlencoded
375
+ Accept-Encoding:
376
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
377
+ Host:
378
+ - api.mailgun.net
379
+ Authorization:
380
+ - Basic YXBpOmQ5MTViNWNkYjlhNTgzNjg1ZDhmM2ZiMWJlYzBmMjBmLTA3YmM3YjA1LWZhNDgxNmEx
381
+ response:
382
+ status:
383
+ code: 200
384
+ message: OK
385
+ headers:
386
+ Access-Control-Allow-Credentials:
387
+ - 'true'
388
+ Access-Control-Allow-Origin:
389
+ - "*"
390
+ Cache-Control:
391
+ - no-store
392
+ Content-Length:
393
+ - '445'
394
+ Content-Type:
395
+ - application/json; charset=utf-8
396
+ Date:
397
+ - Mon, 17 Apr 2023 13:03:16 GMT
398
+ Strict-Transport-Security:
399
+ - max-age=63072000; includeSubDomains
400
+ X-Xss-Protection:
401
+ - 1; mode=block
402
+ body:
403
+ encoding: UTF-8
404
+ string: '{"message":"Domain has been updated","domain":{"created_at":"Mon, 25
405
+ Jan 2021 10:11:26 GMT","id":"600e994e20b1a14a5990856d","is_disabled":false,"name":"integration-test.domain.invalid","require_tls":false,"skip_verification":false,"smtp_login":"postmaster@DOMAIN.TEST","spam_action":"block","state":"active","type":"sandbox","web_prefix":"email","web_scheme":"https","wildcard":true}}
406
+
407
+ '
408
+ http_version:
409
+ recorded_at: Mon, 17 Apr 2023 13:04:47 GMT
410
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.mailgun.net/v3/DOMAIN.TEST/messages
6
+ body:
7
+ encoding: UTF-8
8
+ string: from=sally%test.com&to=sally%test.com&subject=Exception+Integration+Test&text=INTEGRATION+TESTING
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - rest-client/2.1.0 (darwin21.6.0 x86_64) ruby/2.5.1p57
14
+ Content-Length:
15
+ - '119'
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ Host:
21
+ - api.mailgun.net
22
+ Authorization:
23
+ - Basic YXBpOmQ5MTViNWNkYjlhNTgzNjg1ZDhmM2YwNS1mYTQ4MTZhMQ==
24
+ response:
25
+ status:
26
+ code: 401
27
+ message: Unauthorized
28
+ headers:
29
+ Access-Control-Allow-Credentials:
30
+ - 'true'
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Cache-Control:
34
+ - no-store
35
+ Content-Length:
36
+ - '9'
37
+ Content-Type:
38
+ - text/plain; charset=utf-8
39
+ Date:
40
+ - Sun, 28 May 2023 11:29:25 GMT
41
+ Strict-Transport-Security:
42
+ - max-age=63072000; includeSubDomains
43
+ Www-Authenticate:
44
+ - Basic realm="MG API"
45
+ X-Xss-Protection:
46
+ - 1; mode=block
47
+ body:
48
+ encoding: UTF-8
49
+ string: Forbidden
50
+ http_version:
51
+ recorded_at: Sun, 28 May 2023 11:29:25 GMT
52
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.mailgun.net/v3/DOMAIN.TEST/messages
6
+ body:
7
+ encoding: UTF-8
8
+ string: from=sally%40gmail.com&to=sallygmail.com&subject=Exception+Integration+Test&text=INTEGRATION+TESTING
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - rest-client/2.1.0 (darwin21.6.0 x86_64) ruby/2.5.1p57
14
+ Content-Length:
15
+ - '116'
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ Host:
21
+ - api.mailgun.net
22
+ Authorization:
23
+ - Basic YXBpOmQ5MTViNWNkYjlhNTgzNjg1ZDhmM2ZiMWJlYzBmMjBmLTA3YmM3YjA1LWZhNDgxNmEx
24
+ response:
25
+ status:
26
+ code: 400
27
+ message: Bad Request
28
+ headers:
29
+ Access-Control-Allow-Credentials:
30
+ - 'true'
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Cache-Control:
34
+ - no-store
35
+ Content-Length:
36
+ - '78'
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Date:
40
+ - Sun, 28 May 2023 11:35:04 GMT
41
+ Strict-Transport-Security:
42
+ - max-age=63072000; includeSubDomains
43
+ X-Xss-Protection:
44
+ - 1; mode=block
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"message":"to parameter is not a valid address. please check documentation"}
48
+
49
+ '
50
+ http_version:
51
+ recorded_at: Sun, 28 May 2023 11:35:04 GMT
52
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.mailgun.net/v3/DOMAIN.TEST/messages
6
+ body:
7
+ encoding: UTF-8
8
+ string: from=sally%test.com&to=sally%test.com&subject=Exception+Integration+Test&text=INTEGRATION+TESTING
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - rest-client/2.1.0 (darwin21.6.0 x86_64) ruby/2.5.1p57
14
+ Content-Length:
15
+ - '121'
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ Host:
21
+ - api.mailgun.net
22
+ Authorization:
23
+ - Basic YXBpOmQ5MTViNWNkYjlhNTgzNjg1ZDhmM2ZiMWJlYzBmMjBmLTA3YmM3YjA1LWZhNDgxNmEx
24
+ response:
25
+ status:
26
+ code: 403
27
+ message: Forbidden
28
+ headers:
29
+ Access-Control-Allow-Credentials:
30
+ - 'true'
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Cache-Control:
34
+ - no-store
35
+ Content-Length:
36
+ - '219'
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Date:
40
+ - Sun, 28 May 2023 11:40:00 GMT
41
+ Strict-Transport-Security:
42
+ - max-age=63072000; includeSubDomains
43
+ X-Xss-Protection:
44
+ - 1; mode=block
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"message":"Domain DOMAIN.TEST is not allowed to send: Free accounts
48
+ are for test purposes only. Please upgrade or add the address to authorized
49
+ recipients in Account Settings."}
50
+
51
+ '
52
+ http_version:
53
+ recorded_at: Sun, 28 May 2023 11:40:00 GMT
54
+ recorded_with: VCR 3.0.3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailgun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-17 00:00:00.000000000 Z
12
+ date: 2023-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -220,6 +220,9 @@ files:
220
220
  - vcr_cassettes/domains.yml
221
221
  - vcr_cassettes/email_validation.yml
222
222
  - vcr_cassettes/events.yml
223
+ - vcr_cassettes/exceptions-invalid-api-key.yml
224
+ - vcr_cassettes/exceptions-invalid-data.yml
225
+ - vcr_cassettes/exceptions-not-allowed.yml
223
226
  - vcr_cassettes/exceptions.yml
224
227
  - vcr_cassettes/list_members.yml
225
228
  - vcr_cassettes/mailer_invalid_domain.yml
@@ -251,7 +254,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
254
  - !ruby/object:Gem::Version
252
255
  version: '0'
253
256
  requirements: []
254
- rubygems_version: 3.0.3
257
+ rubyforge_project:
258
+ rubygems_version: 2.7.6
255
259
  signing_key:
256
260
  specification_version: 4
257
261
  summary: Mailgun's Official Ruby SDK