mailgunner 2.4.0 → 2.5.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: e755c6f546bd421940dffab1c41d0b803842b7d4
4
- data.tar.gz: ec6bde54051dcdfd4a28dfcc6dfb9ca9b13bd2b0
3
+ metadata.gz: d953d49216e0419f517316128a12974aefc63ce7
4
+ data.tar.gz: 23857d5d6ddf925bb6d07a5f20c5069afe80d0e2
5
5
  SHA512:
6
- metadata.gz: 71f7726130d76a1163d717b5e3437e4a6adecd4fab2a40ceeee62d05bbd7b9c180a930ba95b04744494cfa0288275938d2d8da4619d70d6c38ba719935b32e37
7
- data.tar.gz: 3ddcc963e98c68ed4855d0d895c67b5c3511b6a5793c3c0c3f8dda2c2888183a9195615cbc29c677938d59ae9bd7004b91ce7d9b821a2c9138eeda24aca22b17
6
+ metadata.gz: 2b4c452b40c78d8d569efdc93ce24d0980616546e69fedde804721331ff47d536f93ceba3341c6f0ff7854a4a7957979e21121ba766980f29d01a876f2a0a5d5
7
+ data.tar.gz: 6e531aa0c226284e539f5e5b9128e30ef9c3fcd21da511dbacc95ec2c8c8b6ebe0ec41ef2d60469a2510a5b10355a3a91b17ce3c73a1842d10a79acb1fd441ae
@@ -1,9 +1,4 @@
1
- Copyright (c) TIMCRAFT <http://timcraft.com>
1
+ Copyright (c) 2012-2018 TIMCRAFT
2
2
 
3
3
  This is an Open Source project licensed under the terms of the LGPLv3 license.
4
4
  Please see <http://www.gnu.org/licenses/lgpl-3.0.html> for license text.
5
-
6
- This code is distributed in the hope that it will be useful,
7
- but WITHOUT ANY WARRANTY; without even the implied warranty of
8
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
- GNU Lesser General Public License for more details.
data/README.md CHANGED
@@ -1,18 +1,17 @@
1
- mailgunner
2
- ==========
1
+ # mailgunner
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/mailgunner.svg)](https://badge.fury.io/rb/mailgunner) [![Build Status](https://api.travis-ci.org/timcraft/mailgunner.svg?branch=master)](https://travis-ci.org/timcraft/mailgunner)
3
4
 
4
5
 
5
6
  Ruby client for the [Mailgun API](http://documentation.mailgun.net/api_reference.html).
6
7
 
7
8
 
8
- Installation
9
- ------------
9
+ ## Installation
10
10
 
11
11
  $ gem install mailgunner
12
12
 
13
13
 
14
- Quick start
15
- -----------
14
+ ## Quick start
16
15
 
17
16
  ```ruby
18
17
  require 'mailgunner'
@@ -26,8 +25,7 @@ response = mailgun.get_stats(limit: 5)
26
25
  ```
27
26
 
28
27
 
29
- Storing the API key
30
- -------------------
28
+ ## Storing the API key
31
29
 
32
30
  Best practice for storing credentials for external services is to use environment
33
31
  variables, as described by [12factor.net/config](http://www.12factor.net/config).
@@ -36,8 +34,7 @@ from the MAILGUN_API_KEY and MAILGUN_SMTP_LOGIN environment variables. These wil
36
34
  exist if you are using Mailgun on Heroku, or you can set them manually.
37
35
 
38
36
 
39
- ActionMailer integration
40
- ------------------------
37
+ ## ActionMailer integration
41
38
 
42
39
  Mailgunner integrates with [ActionMailer](https://rubygems.org/gems/actionmailer).
43
40
  If you are using Rails, you can use Mailgunner to send mail via Mailgun by adding
@@ -47,11 +44,21 @@ the following line to `config/environments/production.rb`:
47
44
  config.action_mailer.delivery_method = :mailgun
48
45
  ````
49
46
 
47
+ If for some reason you can't set the required ENV variables, you can configure Mailgunner
48
+ through ActionMailer settings:
49
+
50
+ ```ruby
51
+ config.action_mailer.mailgun_settings = {
52
+ domain: 'test.com'
53
+ api_key: 'your-api-key'
54
+ }
55
+
56
+ ```
57
+
50
58
  Outside of Rails you can set `ActionMailer::Base.delivery_method` directly.
51
59
 
52
60
 
53
- Email validation
54
- ----------------
61
+ ## Email validation
55
62
 
56
63
  If you only need to use Mailgun's [email address validation service](http://documentation.mailgun.com/api-email-validation.html),
57
64
  you can instead use your Mailgun public key to authenticate like this:
@@ -2,18 +2,11 @@ require 'net/http'
2
2
  require 'json'
3
3
  require 'cgi'
4
4
  require 'mailgunner/version'
5
+ require 'mailgunner/errors'
5
6
  require 'mailgunner/delivery_method' if defined?(Mail)
6
7
  require 'mailgunner/railtie' if defined?(Rails)
7
8
 
8
9
  module Mailgunner
9
- class Error < StandardError; end
10
-
11
- module NoDomainProvided
12
- def self.to_s
13
- raise Error, 'No domain provided'
14
- end
15
- end
16
-
17
10
  class Client
18
11
  attr_accessor :domain, :api_key, :http
19
12
 
@@ -211,6 +204,26 @@ module Mailgunner
211
204
  delete("/v3/routes/#{escape id}")
212
205
  end
213
206
 
207
+ def get_webhooks
208
+ get("/v3/domains/#{escape @domain}/webhooks")
209
+ end
210
+
211
+ def get_webhook(id)
212
+ get("/v3/domains/#{escape @domain}/webhooks/#{escape id}")
213
+ end
214
+
215
+ def add_webhook(attributes = {})
216
+ post("/v3/domains/#{escape @domain}/webhooks", attributes)
217
+ end
218
+
219
+ def update_webhook(id, attributes = {})
220
+ put("/v3/domains/#{escape @domain}/webhooks/#{escape id}", attributes)
221
+ end
222
+
223
+ def delete_webhook(id)
224
+ delete("/v3/domains/#{escape @domain}/webhooks/#{escape id}")
225
+ end
226
+
214
227
  def get_campaigns(params = {})
215
228
  get("/v3/#{escape @domain}/campaigns", params)
216
229
  end
@@ -333,31 +346,36 @@ module Mailgunner
333
346
  end
334
347
 
335
348
  def parse(response)
336
- if Net::HTTPSuccess === response
337
- json?(response) ? JSON.parse(response.body) : response.body
349
+ case response
350
+ when Net::HTTPSuccess
351
+ parse_success(response)
352
+ when Net::HTTPUnauthorized
353
+ raise AuthenticationError, "HTTP #{response.code}"
354
+ when Net::HTTPClientError
355
+ raise ClientError, "HTTP #{response.code}"
356
+ when Net::HTTPServerError
357
+ raise ServerError, "HTTP #{response.code}"
338
358
  else
339
- if json?(response)
340
- raise Error, "HTTP #{response.code}: #{JSON.parse(response.body).fetch('message')}"
341
- else
342
- raise Error, "HTTP #{response.code}"
343
- end
359
+ raise Error, "HTTP #{response.code}"
344
360
  end
345
361
  end
346
362
 
363
+ def parse_success(response)
364
+ return JSON.parse(response.body) if json?(response)
365
+
366
+ response.body
367
+ end
368
+
347
369
  def json?(response)
348
370
  content_type = response['Content-Type']
349
371
 
350
372
  content_type && content_type.split(';').first == 'application/json'
351
373
  end
352
374
 
353
- def request_uri(path, hash)
354
- return path if hash.empty?
355
-
356
- query_params = hash.map do |key, values|
357
- Array(values).map { |value| "#{escape(key)}=#{escape(value)}" }
358
- end
375
+ def request_uri(path, params)
376
+ return path if params.empty?
359
377
 
360
- path + '?' + query_params.flatten.join('&')
378
+ path + '?' + params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
361
379
  end
362
380
 
363
381
  def escape(component)
@@ -2,8 +2,6 @@ require 'mail/check_delivery_params'
2
2
 
3
3
  module Mailgunner
4
4
  class DeliveryMethod
5
- include Mail::CheckDeliveryParams
6
-
7
5
  attr_accessor :settings
8
6
 
9
7
  def initialize(values)
@@ -11,10 +9,24 @@ module Mailgunner
11
9
  end
12
10
 
13
11
  def deliver!(mail)
14
- check_delivery_params(mail)
12
+ check(mail)
15
13
 
16
14
  @client.send_mime(mail)
17
15
  end
16
+
17
+ private
18
+
19
+ if Mail::CheckDeliveryParams.respond_to?(:check) # mail v2.6.6+
20
+ def check(mail)
21
+ Mail::CheckDeliveryParams.check(mail)
22
+ end
23
+ else
24
+ include Mail::CheckDeliveryParams
25
+
26
+ def check(mail)
27
+ check_delivery_params(mail)
28
+ end
29
+ end
18
30
  end
19
31
 
20
32
  if defined?(ActionMailer)
@@ -0,0 +1,15 @@
1
+ module Mailgunner
2
+ class Error < StandardError; end
3
+
4
+ class ClientError < Error; end
5
+
6
+ class AuthenticationError < ClientError; end
7
+
8
+ class ServerError < Error; end
9
+
10
+ module NoDomainProvided
11
+ def self.to_s
12
+ raise Error, 'No domain provided'
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Mailgunner
2
- VERSION = '2.4.0'
2
+ VERSION = '2.5.0'
3
3
  end
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.summary = 'Ruby client for the Mailgun API'
13
13
  s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md mailgunner.gemspec)
14
14
  s.required_ruby_version = '>= 1.9.3'
15
- s.add_development_dependency('rake', '~> 10.1')
16
- s.add_development_dependency('webmock', '~> 1.18')
17
- s.add_development_dependency('mail', '~> 2.5')
18
- s.add_development_dependency('actionmailer', '~> 4.0')
19
- s.add_development_dependency('mocha', '~> 1.0')
15
+ s.add_development_dependency('rake', '>= 12')
16
+ s.add_development_dependency('webmock', '~> 3')
17
+ s.add_development_dependency('mail', '~> 2')
18
+ s.add_development_dependency('actionmailer', '~> 5')
19
+ s.add_development_dependency('mocha', '~> 1')
20
20
  s.require_path = 'lib'
21
21
  end
@@ -18,7 +18,9 @@ describe 'Mailgunner::DeliveryMethod' do
18
18
 
19
19
  @domain = 'samples.mailgun.org'
20
20
 
21
- @base_url = "https://api:#@api_key@api.mailgun.net/v3"
21
+ @base_url = 'https://api.mailgun.net/v3'
22
+
23
+ @auth = ['api', @api_key]
22
24
 
23
25
  @address = 'user@example.com'
24
26
 
@@ -28,20 +30,8 @@ describe 'Mailgunner::DeliveryMethod' do
28
30
  end
29
31
 
30
32
  it 'delivers the mail to mailgun in mime format' do
31
- stub_request(:post, "#@base_url/#@domain/messages.mime")
33
+ stub_request(:post, "#@base_url/#@domain/messages.mime").with(basic_auth: @auth)
32
34
 
33
35
  ExampleMailer.registration_confirmation(email: @address).deliver_now
34
36
  end
35
-
36
- it 'raises an exception if the api returns an error' do
37
- stub_request(:post, "#@base_url/#@domain/messages.mime").to_return({
38
- status: 403,
39
- headers: {'Content-Type' => 'application/json'},
40
- body: '{"message": "Invalid API key"}'
41
- })
42
-
43
- exception = proc { ExampleMailer.registration_confirmation(email: @address).deliver_now }.must_raise(Mailgunner::Error)
44
-
45
- exception.message.must_include('Invalid API key')
46
- end
47
37
  end
@@ -5,17 +5,13 @@ require 'mailgunner'
5
5
  require 'json'
6
6
  require 'mail'
7
7
 
8
- WebMock::Config.instance.query_values_notation = :flat_array
9
-
10
8
  describe 'Mailgunner::Client' do
11
9
  before do
12
10
  @domain = 'samples.mailgun.org'
13
11
 
14
12
  @api_key = 'xxx'
15
13
 
16
- @base_url = "https://api:#{@api_key}@api.mailgun.net/v3"
17
-
18
- @json_response = {headers: {'Content-Type' => 'application/json;charset=utf-8'}, body: '{"key":"value"}'}
14
+ @base_url = 'https://@api.mailgun.net/v3'
19
15
 
20
16
  @json_response_object = {'key' => 'value'}
21
17
 
@@ -30,6 +26,20 @@ describe 'Mailgunner::Client' do
30
26
  @id = 'idxxx'
31
27
  end
32
28
 
29
+ def stub(http_method, url, body: nil, headers: nil)
30
+ headers ||= {}
31
+ headers['User-Agent'] = /\ARuby\/\d+\.\d+\.\d+ Mailgunner\/\d+\.\d+\.\d+\z/
32
+
33
+ params = {basic_auth: ['api', @api_key]}
34
+ params[:headers] = headers
35
+ params[:body] = body if body
36
+
37
+ response_headers = {'Content-Type' => 'application/json;charset=utf-8'}
38
+ response_body = '{"key":"value"}'
39
+
40
+ stub_request(http_method, url).with(params).to_return(headers: response_headers, body: response_body)
41
+ end
42
+
33
43
  describe 'http method' do
34
44
  it 'returns a net http object that uses ssl' do
35
45
  @client.http.must_be_instance_of(Net::HTTP)
@@ -68,7 +78,7 @@ describe 'Mailgunner::Client' do
68
78
 
69
79
  describe 'validate_address method' do
70
80
  it 'calls the address validate resource with the given email address and returns the response object' do
71
- stub_request(:get, "#@base_url/address/validate?address=#@encoded_address").to_return(@json_response)
81
+ stub(:get, "#@base_url/address/validate?address=#@encoded_address")
72
82
 
73
83
  @client.validate_address(@address).must_equal(@json_response_object)
74
84
  end
@@ -76,7 +86,7 @@ describe 'Mailgunner::Client' do
76
86
 
77
87
  describe 'parse_addresses method' do
78
88
  it 'calls the address parse resource with the given email addresses and returns the response object' do
79
- stub_request(:get, "#@base_url/address/parse?addresses=bob%40example.com%2Ceve%40example.com").to_return(@json_response)
89
+ stub(:get, "#@base_url/address/parse?addresses=bob%40example.com%2Ceve%40example.com")
80
90
 
81
91
  @client.parse_addresses(['bob@example.com', 'eve@example.com']).must_equal(@json_response_object)
82
92
  end
@@ -84,7 +94,7 @@ describe 'Mailgunner::Client' do
84
94
 
85
95
  describe 'get_message method' do
86
96
  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)
97
+ stub(:get, "#@base_url/domains/#@domain/messages/#@id")
88
98
 
89
99
  @client.get_message(@id).must_equal(@json_response_object)
90
100
  end
@@ -92,8 +102,7 @@ describe 'Mailgunner::Client' do
92
102
 
93
103
  describe 'get_mime_message method' do
94
104
  it 'fetches the domain message resource with the given key and returns the response object' do
95
- stub_request(:get, "#@base_url/domains/#@domain/messages/#@id").
96
- with(headers: {'Accept' => 'message/rfc2822'}).to_return(@json_response)
105
+ stub(:get, "#@base_url/domains/#@domain/messages/#@id", headers: {'Accept' => 'message/rfc2822'})
97
106
 
98
107
  @client.get_mime_message(@id).must_equal(@json_response_object)
99
108
  end
@@ -101,7 +110,7 @@ describe 'Mailgunner::Client' do
101
110
 
102
111
  describe 'send_message method' do
103
112
  it 'posts to the domain messages resource and returns the response object' do
104
- stub_request(:post, "#@base_url/#@domain/messages").with(body: "to=#@encoded_address").to_return(@json_response)
113
+ stub(:post, "#@base_url/#@domain/messages", body: "to=#@encoded_address")
105
114
 
106
115
  @client.send_message({to: @address}).must_equal(@json_response_object)
107
116
  end
@@ -129,7 +138,7 @@ describe 'Mailgunner::Client' do
129
138
  end
130
139
 
131
140
  it 'posts to the domain messages resource and returns the response object' do
132
- stub_request(:post, "#@base_url/#@domain/messages.mime").to_return(@json_response)
141
+ stub(:post, "#@base_url/#@domain/messages.mime")
133
142
 
134
143
  @client.send_mime(@mail).must_equal(@json_response_object)
135
144
  end
@@ -138,7 +147,7 @@ describe 'Mailgunner::Client' do
138
147
  @mail.cc = 'carol@example.com'
139
148
  @mail.bcc = 'dave@example.com'
140
149
 
141
- stub_request(:post, "#@base_url/#@domain/messages.mime")
150
+ stub(:post, "#@base_url/#@domain/messages.mime")
142
151
 
143
152
  recipients = 'alice@example.com,carol@example.com,dave@example.com'
144
153
 
@@ -150,7 +159,7 @@ describe 'Mailgunner::Client' do
150
159
 
151
160
  describe 'delete_message method' do
152
161
  it 'deletes the domain message resource with the given key and returns the response object' do
153
- stub_request(:delete, "#@base_url/domains/#@domain/messages/#@id").to_return(@json_response)
162
+ stub(:delete, "#@base_url/domains/#@domain/messages/#@id")
154
163
 
155
164
  @client.delete_message(@id).must_equal(@json_response_object)
156
165
  end
@@ -158,7 +167,7 @@ describe 'Mailgunner::Client' do
158
167
 
159
168
  describe 'get_domains method' do
160
169
  it 'fetches the domains resource and returns the response object' do
161
- stub_request(:get, "#@base_url/domains").to_return(@json_response)
170
+ stub(:get, "#@base_url/domains")
162
171
 
163
172
  @client.get_domains.must_equal(@json_response_object)
164
173
  end
@@ -166,7 +175,7 @@ describe 'Mailgunner::Client' do
166
175
 
167
176
  describe 'get_domain method' do
168
177
  it 'fetches the domain resource and returns the response object' do
169
- stub_request(:get, "#@base_url/domains/#@domain").to_return(@json_response)
178
+ stub(:get, "#@base_url/domains/#@domain")
170
179
 
171
180
  @client.get_domain(@domain).must_equal(@json_response_object)
172
181
  end
@@ -174,7 +183,7 @@ describe 'Mailgunner::Client' do
174
183
 
175
184
  describe 'add_domain method' do
176
185
  it 'posts to the domains resource and returns the response object' do
177
- stub_request(:post, "#@base_url/domains").with(body: "name=#@domain").to_return(@json_response)
186
+ stub(:post, "#@base_url/domains", body: "name=#@domain")
178
187
 
179
188
  @client.add_domain({name: @domain}).must_equal(@json_response_object)
180
189
  end
@@ -182,7 +191,7 @@ describe 'Mailgunner::Client' do
182
191
 
183
192
  describe 'delete_domain method' do
184
193
  it 'deletes the domain resource with the given name and returns the response object' do
185
- stub_request(:delete, "#@base_url/domains/#@domain").to_return(@json_response)
194
+ stub(:delete, "#@base_url/domains/#@domain")
186
195
 
187
196
  @client.delete_domain(@domain).must_equal(@json_response_object)
188
197
  end
@@ -190,7 +199,7 @@ describe 'Mailgunner::Client' do
190
199
 
191
200
  describe 'get_credentials method' do
192
201
  it 'fetches the domain credentials resource and returns the response object' do
193
- stub_request(:get, "#@base_url/domains/#@domain/credentials").to_return(@json_response)
202
+ stub(:get, "#@base_url/domains/#@domain/credentials")
194
203
 
195
204
  @client.get_credentials.must_equal(@json_response_object)
196
205
  end
@@ -198,7 +207,7 @@ describe 'Mailgunner::Client' do
198
207
 
199
208
  describe 'add_credentials method' do
200
209
  it 'posts to the domain credentials resource and returns the response object' do
201
- stub_request(:post, "#@base_url/domains/#@domain/credentials").with(body: "login=#@login").to_return(@json_response)
210
+ stub(:post, "#@base_url/domains/#@domain/credentials", body: "login=#@login")
202
211
 
203
212
  @client.add_credentials(login: @login).must_equal(@json_response_object)
204
213
  end
@@ -206,7 +215,7 @@ describe 'Mailgunner::Client' do
206
215
 
207
216
  describe 'update_credentials method' do
208
217
  it 'updates the domain credentials resource with the given login and returns the response object' do
209
- stub_request(:put, "#@base_url/domains/#@domain/credentials/#@login").with(body: 'password=secret').to_return(@json_response)
218
+ stub(:put, "#@base_url/domains/#@domain/credentials/#@login", body: 'password=secret')
210
219
 
211
220
  @client.update_credentials(@login, {password: 'secret'}).must_equal(@json_response_object)
212
221
  end
@@ -214,7 +223,7 @@ describe 'Mailgunner::Client' do
214
223
 
215
224
  describe 'delete_credentials method' do
216
225
  it 'deletes the domain credentials resource with the given login and returns the response object' do
217
- stub_request(:delete, "#@base_url/domains/#@domain/credentials/#@login").to_return(@json_response)
226
+ stub(:delete, "#@base_url/domains/#@domain/credentials/#@login")
218
227
 
219
228
  @client.delete_credentials(@login).must_equal(@json_response_object)
220
229
  end
@@ -222,7 +231,7 @@ describe 'Mailgunner::Client' do
222
231
 
223
232
  describe 'get_connection_settings method' do
224
233
  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)
234
+ stub(:get, "#@base_url/domains/#@domain/connection")
226
235
 
227
236
  @client.get_connection_settings.must_equal(@json_response_object)
228
237
  end
@@ -230,7 +239,7 @@ describe 'Mailgunner::Client' do
230
239
 
231
240
  describe 'update_connection_settings method' do
232
241
  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)
242
+ stub(:put, "#@base_url/domains/#@domain/connection", body: 'require_tls=true')
234
243
 
235
244
  @client.update_connection_settings({require_tls: true}).must_equal(@json_response_object)
236
245
  end
@@ -238,13 +247,13 @@ describe 'Mailgunner::Client' do
238
247
 
239
248
  describe 'get_unsubscribes method' do
240
249
  it 'fetches the domain unsubscribes resource and returns the response object' do
241
- stub_request(:get, "#@base_url/#@domain/unsubscribes").to_return(@json_response)
250
+ stub(:get, "#@base_url/#@domain/unsubscribes")
242
251
 
243
252
  @client.get_unsubscribes.must_equal(@json_response_object)
244
253
  end
245
254
 
246
255
  it 'encodes skip and limit parameters' do
247
- stub_request(:get, "#@base_url/#@domain/unsubscribes?skip=1&limit=2")
256
+ stub(:get, "#@base_url/#@domain/unsubscribes?skip=1&limit=2")
248
257
 
249
258
  @client.get_unsubscribes(skip: 1, limit: 2)
250
259
  end
@@ -252,7 +261,7 @@ describe 'Mailgunner::Client' do
252
261
 
253
262
  describe 'get_unsubscribe method' do
254
263
  it 'fetches the unsubscribe resource with the given address and returns the response object' do
255
- stub_request(:get, "#@base_url/#@domain/unsubscribes/#@encoded_address").to_return(@json_response)
264
+ stub(:get, "#@base_url/#@domain/unsubscribes/#@encoded_address")
256
265
 
257
266
  @client.get_unsubscribe(@address).must_equal(@json_response_object)
258
267
  end
@@ -260,7 +269,7 @@ describe 'Mailgunner::Client' do
260
269
 
261
270
  describe 'delete_unsubscribe method' do
262
271
  it 'deletes the domain unsubscribe resource with the given address and returns the response object' do
263
- stub_request(:delete, "#@base_url/#@domain/unsubscribes/#@encoded_address").to_return(@json_response)
272
+ stub(:delete, "#@base_url/#@domain/unsubscribes/#@encoded_address")
264
273
 
265
274
  @client.delete_unsubscribe(@address).must_equal(@json_response_object)
266
275
  end
@@ -268,7 +277,7 @@ describe 'Mailgunner::Client' do
268
277
 
269
278
  describe 'add_unsubscribe method' do
270
279
  it 'posts to the domain unsubscribes resource and returns the response object' do
271
- stub_request(:post, "#@base_url/#@domain/unsubscribes").with(body: "address=#@encoded_address").to_return(@json_response)
280
+ stub(:post, "#@base_url/#@domain/unsubscribes", body: "address=#@encoded_address")
272
281
 
273
282
  @client.add_unsubscribe({address: @address}).must_equal(@json_response_object)
274
283
  end
@@ -276,13 +285,13 @@ describe 'Mailgunner::Client' do
276
285
 
277
286
  describe 'get_complaints method' do
278
287
  it 'fetches the domain complaints resource and returns the response object' do
279
- stub_request(:get, "#@base_url/#@domain/complaints").to_return(@json_response)
288
+ stub(:get, "#@base_url/#@domain/complaints")
280
289
 
281
290
  @client.get_complaints.must_equal(@json_response_object)
282
291
  end
283
292
 
284
293
  it 'encodes skip and limit parameters' do
285
- stub_request(:get, "#@base_url/#@domain/complaints?skip=1&limit=2")
294
+ stub(:get, "#@base_url/#@domain/complaints?skip=1&limit=2")
286
295
 
287
296
  @client.get_complaints(skip: 1, limit: 2)
288
297
  end
@@ -290,7 +299,7 @@ describe 'Mailgunner::Client' do
290
299
 
291
300
  describe 'get_complaint method' do
292
301
  it 'fetches the complaint resource with the given address and returns the response object' do
293
- stub_request(:get, "#@base_url/#@domain/complaints/#@encoded_address").to_return(@json_response)
302
+ stub(:get, "#@base_url/#@domain/complaints/#@encoded_address")
294
303
 
295
304
  @client.get_complaint(@address).must_equal(@json_response_object)
296
305
  end
@@ -298,7 +307,7 @@ describe 'Mailgunner::Client' do
298
307
 
299
308
  describe 'add_complaint method' do
300
309
  it 'posts to the domain complaints resource and returns the response object' do
301
- stub_request(:post, "#@base_url/#@domain/complaints").with(body: "address=#@encoded_address").to_return(@json_response)
310
+ stub(:post, "#@base_url/#@domain/complaints", body: "address=#@encoded_address")
302
311
 
303
312
  @client.add_complaint({address: @address}).must_equal(@json_response_object)
304
313
  end
@@ -306,7 +315,7 @@ describe 'Mailgunner::Client' do
306
315
 
307
316
  describe 'delete_complaint method' do
308
317
  it 'deletes the domain complaint resource with the given address and returns the response object' do
309
- stub_request(:delete, "#@base_url/#@domain/complaints/#@encoded_address").to_return(@json_response)
318
+ stub(:delete, "#@base_url/#@domain/complaints/#@encoded_address")
310
319
 
311
320
  @client.delete_complaint(@address).must_equal(@json_response_object)
312
321
  end
@@ -314,13 +323,13 @@ describe 'Mailgunner::Client' do
314
323
 
315
324
  describe 'get_bounces method' do
316
325
  it 'fetches the domain bounces resource and returns the response object' do
317
- stub_request(:get, "#@base_url/#@domain/bounces").to_return(@json_response)
326
+ stub(:get, "#@base_url/#@domain/bounces")
318
327
 
319
328
  @client.get_bounces.must_equal(@json_response_object)
320
329
  end
321
330
 
322
331
  it 'encodes skip and limit parameters' do
323
- stub_request(:get, "#@base_url/#@domain/bounces?skip=1&limit=2")
332
+ stub(:get, "#@base_url/#@domain/bounces?skip=1&limit=2")
324
333
 
325
334
  @client.get_bounces(skip: 1, limit: 2)
326
335
  end
@@ -328,7 +337,7 @@ describe 'Mailgunner::Client' do
328
337
 
329
338
  describe 'get_bounce method' do
330
339
  it 'fetches the bounce resource with the given address and returns the response object' do
331
- stub_request(:get, "#@base_url/#@domain/bounces/#@encoded_address").to_return(@json_response)
340
+ stub(:get, "#@base_url/#@domain/bounces/#@encoded_address")
332
341
 
333
342
  @client.get_bounce(@address).must_equal(@json_response_object)
334
343
  end
@@ -336,7 +345,7 @@ describe 'Mailgunner::Client' do
336
345
 
337
346
  describe 'add_bounce method' do
338
347
  it 'posts to the domain bounces resource and returns the response object' do
339
- stub_request(:post, "#@base_url/#@domain/bounces").with(body: "address=#@encoded_address").to_return(@json_response)
348
+ stub(:post, "#@base_url/#@domain/bounces", body: "address=#@encoded_address")
340
349
 
341
350
  @client.add_bounce({address: @address}).must_equal(@json_response_object)
342
351
  end
@@ -344,7 +353,7 @@ describe 'Mailgunner::Client' do
344
353
 
345
354
  describe 'delete_bounce method' do
346
355
  it 'deletes the domain bounce resource with the given address and returns the response object' do
347
- stub_request(:delete, "#@base_url/#@domain/bounces/#@encoded_address").to_return(@json_response)
356
+ stub(:delete, "#@base_url/#@domain/bounces/#@encoded_address")
348
357
 
349
358
  @client.delete_bounce(@address).must_equal(@json_response_object)
350
359
  end
@@ -352,7 +361,7 @@ describe 'Mailgunner::Client' do
352
361
 
353
362
  describe 'delete_bounces method' do
354
363
  it 'deletes the domain bounces resource and returns the response object' do
355
- stub_request(:delete, "#@base_url/#@domain/bounces").to_return(@json_response)
364
+ stub(:delete, "#@base_url/#@domain/bounces")
356
365
 
357
366
  @client.delete_bounces.must_equal(@json_response_object)
358
367
  end
@@ -364,25 +373,29 @@ describe 'Mailgunner::Client' do
364
373
  end
365
374
 
366
375
  it 'fetches the domain stats resource and returns the response object' do
367
- stub_request(:get, "#@base_url/#@domain/stats").to_return(@json_response)
376
+ stub(:get, "#@base_url/#@domain/stats")
368
377
 
369
378
  @client.get_stats.must_equal(@json_response_object)
370
379
  end
371
380
 
372
381
  it 'encodes skip and limit parameters' do
373
- stub_request(:get, "#@base_url/#@domain/stats?skip=1&limit=2")
382
+ stub(:get, "#@base_url/#@domain/stats?skip=1&limit=2")
374
383
 
375
384
  @client.get_stats(skip: 1, limit: 2)
376
385
  end
377
386
 
378
387
  it 'encodes an event parameter with multiple values' do
379
- stub_request(:get, "#@base_url/#@domain/stats?event=opened&event=sent")
388
+ WebMock::Config.instance.query_values_notation = :flat_array
389
+
390
+ stub(:get, "#@base_url/#@domain/stats?event=opened&event=sent")
380
391
 
381
392
  @client.get_stats(event: %w(sent opened))
393
+
394
+ WebMock::Config.instance.query_values_notation = nil
382
395
  end
383
396
 
384
397
  it 'emits a deprecation warning' do
385
- stub_request(:get, "#@base_url/#@domain/stats")
398
+ stub(:get, "#@base_url/#@domain/stats")
386
399
 
387
400
  Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#get_stats is deprecated/))
388
401
 
@@ -392,33 +405,37 @@ describe 'Mailgunner::Client' do
392
405
 
393
406
  describe 'get_total_stats method' do
394
407
  it 'fetches the domain total stats resource and returns the response object' do
395
- stub_request(:get, "#@base_url/#@domain/stats/total?event=delivered").to_return(@json_response)
408
+ stub(:get, "#@base_url/#@domain/stats/total?event=delivered")
396
409
 
397
410
  @client.get_total_stats(event: 'delivered').must_equal(@json_response_object)
398
411
  end
399
412
 
400
413
  it 'encodes optional parameters' do
401
- stub_request(:get, "#@base_url/#@domain/stats/total?event=delivered&resolution=hour")
414
+ stub(:get, "#@base_url/#@domain/stats/total?event=delivered&resolution=hour")
402
415
 
403
416
  @client.get_total_stats(event: 'delivered', resolution: 'hour')
404
417
  end
405
418
 
406
- it 'encodes multiple event values' do
407
- stub_request(:get, "#@base_url/#@domain/stats/total?event=delivered&event=accepted")
419
+ it 'encodes an event parameter with multiple values' do
420
+ WebMock::Config.instance.query_values_notation = :flat_array
421
+
422
+ stub(:get, "#@base_url/#@domain/stats/total?event=delivered&event=accepted")
408
423
 
409
424
  @client.get_total_stats(event: %w(accepted delivered))
425
+
426
+ WebMock::Config.instance.query_values_notation = nil
410
427
  end
411
428
  end
412
429
 
413
430
  describe 'get_events method' do
414
431
  it 'fetches the domain events resource and returns the response object' do
415
- stub_request(:get, "#@base_url/#@domain/events").to_return(@json_response)
432
+ stub(:get, "#@base_url/#@domain/events")
416
433
 
417
434
  @client.get_events.must_equal(@json_response_object)
418
435
  end
419
436
 
420
437
  it 'encodes optional parameters' do
421
- stub_request(:get, "#@base_url/#@domain/events?event=accepted&limit=10")
438
+ stub(:get, "#@base_url/#@domain/events?event=accepted&limit=10")
422
439
 
423
440
  @client.get_events(event: 'accepted', limit: 10)
424
441
  end
@@ -426,13 +443,13 @@ describe 'Mailgunner::Client' do
426
443
 
427
444
  describe 'get_tags method' do
428
445
  it 'fetches the domain tags resource and returns the response object' do
429
- stub_request(:get, "#@base_url/#@domain/tags").to_return(@json_response)
446
+ stub(:get, "#@base_url/#@domain/tags")
430
447
 
431
448
  @client.get_tags.must_equal(@json_response_object)
432
449
  end
433
450
 
434
451
  it 'encodes optional limit parameter' do
435
- stub_request(:get, "#@base_url/#@domain/tags?limit=2")
452
+ stub(:get, "#@base_url/#@domain/tags?limit=2")
436
453
 
437
454
  @client.get_tags(limit: 2)
438
455
  end
@@ -440,7 +457,7 @@ describe 'Mailgunner::Client' do
440
457
 
441
458
  describe 'get_tag method' do
442
459
  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)
460
+ stub(:get, "#@base_url/#@domain/tags/#@id")
444
461
 
445
462
  @client.get_tag(@id).must_equal(@json_response_object)
446
463
  end
@@ -448,7 +465,7 @@ describe 'Mailgunner::Client' do
448
465
 
449
466
  describe 'update_tag method' do
450
467
  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)
468
+ stub(:put, "#@base_url/#@domain/tags/#@id", body: 'description=Tag+description')
452
469
 
453
470
  @client.update_tag(@id, {description: 'Tag description'}).must_equal(@json_response_object)
454
471
  end
@@ -456,7 +473,7 @@ describe 'Mailgunner::Client' do
456
473
 
457
474
  describe 'get_tag_stats method' do
458
475
  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)
476
+ stub(:get, "#@base_url/#@domain/tags/#@id/stats?event=accepted")
460
477
 
461
478
  @client.get_tag_stats(@id, event: 'accepted').must_equal(@json_response_object)
462
479
  end
@@ -464,7 +481,7 @@ describe 'Mailgunner::Client' do
464
481
 
465
482
  describe 'delete_tag method' do
466
483
  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)
484
+ stub(:delete, "#@base_url/#@domain/tags/#@id")
468
485
 
469
486
  @client.delete_tag(@id).must_equal(@json_response_object)
470
487
  end
@@ -472,13 +489,13 @@ describe 'Mailgunner::Client' do
472
489
 
473
490
  describe 'get_routes method' do
474
491
  it 'fetches the routes resource and returns the response object' do
475
- stub_request(:get, "#@base_url/routes").to_return(@json_response)
492
+ stub(:get, "#@base_url/routes")
476
493
 
477
494
  @client.get_routes.must_equal(@json_response_object)
478
495
  end
479
496
 
480
497
  it 'encodes skip and limit parameters' do
481
- stub_request(:get, "#@base_url/routes?skip=1&limit=2")
498
+ stub(:get, "#@base_url/routes?skip=1&limit=2")
482
499
 
483
500
  @client.get_routes(skip: 1, limit: 2)
484
501
  end
@@ -486,7 +503,7 @@ describe 'Mailgunner::Client' do
486
503
 
487
504
  describe 'get_route method' do
488
505
  it 'fetches the route resource with the given id and returns the response object' do
489
- stub_request(:get, "#@base_url/routes/#@id").to_return(@json_response)
506
+ stub(:get, "#@base_url/routes/#@id")
490
507
 
491
508
  @client.get_route(@id).must_equal(@json_response_object)
492
509
  end
@@ -494,7 +511,7 @@ describe 'Mailgunner::Client' do
494
511
 
495
512
  describe 'add_route method' do
496
513
  it 'posts to the routes resource and returns the response object' do
497
- stub_request(:post, "#@base_url/routes").with(body: 'description=Example+route&priority=1').to_return(@json_response)
514
+ stub(:post, "#@base_url/routes", body: 'description=Example+route&priority=1')
498
515
 
499
516
  @client.add_route({description: 'Example route', priority: 1}).must_equal(@json_response_object)
500
517
  end
@@ -502,7 +519,7 @@ describe 'Mailgunner::Client' do
502
519
 
503
520
  describe 'update_route method' do
504
521
  it 'updates the route resource with the given id and returns the response object' do
505
- stub_request(:put, "#@base_url/routes/#@id").with(body: 'priority=10').to_return(@json_response)
522
+ stub(:put, "#@base_url/routes/#@id", body: 'priority=10')
506
523
 
507
524
  @client.update_route(@id, {priority: 10}).must_equal(@json_response_object)
508
525
  end
@@ -510,21 +527,65 @@ describe 'Mailgunner::Client' do
510
527
 
511
528
  describe 'delete_route method' do
512
529
  it 'deletes the route resource with the given id and returns the response object' do
513
- stub_request(:delete, "#@base_url/routes/#@id").to_return(@json_response)
530
+ stub(:delete, "#@base_url/routes/#@id")
514
531
 
515
532
  @client.delete_route(@id).must_equal(@json_response_object)
516
533
  end
517
534
  end
518
535
 
536
+ describe 'get_webhooks method' do
537
+ it 'fetches the domain webhooks resource and returns the response object' do
538
+ stub(:get, "#@base_url/domains/#@domain/webhooks")
539
+
540
+ @client.get_webhooks.must_equal(@json_response_object)
541
+ end
542
+ end
543
+
544
+ describe 'get_webhook method' do
545
+ it 'fetches the domain webhook resource with the given id and returns the response object' do
546
+ stub(:get, "#@base_url/domains/#@domain/webhooks/#@id")
547
+
548
+ @client.get_webhook(@id).must_equal(@json_response_object)
549
+ end
550
+ end
551
+
552
+ describe 'add_webhook method' do
553
+ it 'posts to the domain webhooks resource and returns the response object' do
554
+ attributes = {id: @id, url: 'http://example.com/webhook'}
555
+
556
+ stub(:post, "#@base_url/domains/#@domain/webhooks", body: attributes)
557
+
558
+ @client.add_webhook(attributes).must_equal(@json_response_object)
559
+ end
560
+ end
561
+
562
+ describe 'update_webhook method' do
563
+ it 'updates the domain webhook resource with the given id and returns the response object' do
564
+ attributes = {url: 'http://example.com/webhook'}
565
+
566
+ stub(:put, "#@base_url/domains/#@domain/webhooks/#@id", body: attributes)
567
+
568
+ @client.update_webhook(@id, attributes).must_equal(@json_response_object)
569
+ end
570
+ end
571
+
572
+ describe 'delete_webhook method' do
573
+ it 'deletes the domain webhook resource with the given address and returns the response object' do
574
+ stub(:delete, "#@base_url/domains/#@domain/webhooks/#@id")
575
+
576
+ @client.delete_webhook(@id).must_equal(@json_response_object)
577
+ end
578
+ end
579
+
519
580
  describe 'get_campaigns method' do
520
581
  it 'fetches the domain campaigns resource and returns the response object' do
521
- stub_request(:get, "#@base_url/#@domain/campaigns").to_return(@json_response)
582
+ stub(:get, "#@base_url/#@domain/campaigns")
522
583
 
523
584
  @client.get_campaigns.must_equal(@json_response_object)
524
585
  end
525
586
 
526
587
  it 'encodes skip and limit parameters' do
527
- stub_request(:get, "#@base_url/#@domain/campaigns?skip=1&limit=2")
588
+ stub(:get, "#@base_url/#@domain/campaigns?skip=1&limit=2")
528
589
 
529
590
  @client.get_campaigns(skip: 1, limit: 2)
530
591
  end
@@ -532,7 +593,7 @@ describe 'Mailgunner::Client' do
532
593
 
533
594
  describe 'get_campaign method' do
534
595
  it 'fetches the campaign resource with the given id and returns the response object' do
535
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id").to_return(@json_response)
596
+ stub(:get, "#@base_url/#@domain/campaigns/#@id")
536
597
 
537
598
  @client.get_campaign(@id).must_equal(@json_response_object)
538
599
  end
@@ -540,7 +601,7 @@ describe 'Mailgunner::Client' do
540
601
 
541
602
  describe 'add_campaign method' do
542
603
  it 'posts to the domain campaigns resource and returns the response object' do
543
- stub_request(:post, "#@base_url/#@domain/campaigns").with(body: "id=#@id").to_return(@json_response)
604
+ stub(:post, "#@base_url/#@domain/campaigns", body: "id=#@id")
544
605
 
545
606
  @client.add_campaign({id: @id}).must_equal(@json_response_object)
546
607
  end
@@ -548,7 +609,7 @@ describe 'Mailgunner::Client' do
548
609
 
549
610
  describe 'update_campaign method' do
550
611
  it 'updates the campaign resource and returns the response object' do
551
- stub_request(:put, "#@base_url/#@domain/campaigns/#@id").with(body: 'name=Example+Campaign').to_return(@json_response)
612
+ stub(:put, "#@base_url/#@domain/campaigns/#@id", body: 'name=Example+Campaign')
552
613
 
553
614
  @client.update_campaign(@id, {name: 'Example Campaign'}).must_equal(@json_response_object)
554
615
  end
@@ -556,7 +617,7 @@ describe 'Mailgunner::Client' do
556
617
 
557
618
  describe 'delete_campaign method' do
558
619
  it 'deletes the domain campaign resource with the given id and returns the response object' do
559
- stub_request(:delete, "#@base_url/#@domain/campaigns/#@id").to_return(@json_response)
620
+ stub(:delete, "#@base_url/#@domain/campaigns/#@id")
560
621
 
561
622
  @client.delete_campaign(@id).must_equal(@json_response_object)
562
623
  end
@@ -564,13 +625,13 @@ describe 'Mailgunner::Client' do
564
625
 
565
626
  describe 'get_campaign_events method' do
566
627
  it 'fetches the domain campaign events resource and returns the response object' do
567
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/events").to_return(@json_response)
628
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/events")
568
629
 
569
630
  @client.get_campaign_events(@id).must_equal(@json_response_object)
570
631
  end
571
632
 
572
633
  it 'encodes the optional parameters' do
573
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/events?country=US&limit=100")
634
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/events?country=US&limit=100")
574
635
 
575
636
  @client.get_campaign_events(@id, country: 'US', limit: 100)
576
637
  end
@@ -578,13 +639,13 @@ describe 'Mailgunner::Client' do
578
639
 
579
640
  describe 'get_campaign_stats method' do
580
641
  it 'fetches the domain campaign stats resource and returns the response object' do
581
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/stats").to_return(@json_response)
642
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/stats")
582
643
 
583
644
  @client.get_campaign_stats(@id).must_equal(@json_response_object)
584
645
  end
585
646
 
586
647
  it 'encodes the optional parameters' do
587
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/stats?groupby=dailyhour")
648
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/stats?groupby=dailyhour")
588
649
 
589
650
  @client.get_campaign_stats(@id, groupby: 'dailyhour')
590
651
  end
@@ -592,13 +653,13 @@ describe 'Mailgunner::Client' do
592
653
 
593
654
  describe 'get_campaign_clicks method' do
594
655
  it 'fetches the domain campaign clicks resource and returns the response object' do
595
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/clicks").to_return(@json_response)
656
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/clicks")
596
657
 
597
658
  @client.get_campaign_clicks(@id).must_equal(@json_response_object)
598
659
  end
599
660
 
600
661
  it 'encodes the optional parameters' do
601
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/clicks?groupby=month&limit=100")
662
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/clicks?groupby=month&limit=100")
602
663
 
603
664
  @client.get_campaign_clicks(@id, groupby: 'month', limit: 100)
604
665
  end
@@ -606,13 +667,13 @@ describe 'Mailgunner::Client' do
606
667
 
607
668
  describe 'get_campaign_opens method' do
608
669
  it 'fetches the domain campaign opens resource and returns the response object' do
609
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/opens").to_return(@json_response)
670
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/opens")
610
671
 
611
672
  @client.get_campaign_opens(@id).must_equal(@json_response_object)
612
673
  end
613
674
 
614
675
  it 'encodes the optional parameters' do
615
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/opens?groupby=month&limit=100")
676
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/opens?groupby=month&limit=100")
616
677
 
617
678
  @client.get_campaign_opens(@id, groupby: 'month', limit: 100)
618
679
  end
@@ -620,13 +681,13 @@ describe 'Mailgunner::Client' do
620
681
 
621
682
  describe 'get_campaign_unsubscribes method' do
622
683
  it 'fetches the domain campaign unsubscribes resource and returns the response object' do
623
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes").to_return(@json_response)
684
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes")
624
685
 
625
686
  @client.get_campaign_unsubscribes(@id).must_equal(@json_response_object)
626
687
  end
627
688
 
628
689
  it 'encodes the optional parameters' do
629
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes?groupby=month&limit=100")
690
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes?groupby=month&limit=100")
630
691
 
631
692
  @client.get_campaign_unsubscribes(@id, groupby: 'month', limit: 100)
632
693
  end
@@ -634,13 +695,13 @@ describe 'Mailgunner::Client' do
634
695
 
635
696
  describe 'get_campaign_complaints method' do
636
697
  it 'fetches the domain campaign complaints resource and returns the response object' do
637
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/complaints").to_return(@json_response)
698
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/complaints")
638
699
 
639
700
  @client.get_campaign_complaints(@id).must_equal(@json_response_object)
640
701
  end
641
702
 
642
703
  it 'encodes the optional parameters' do
643
- stub_request(:get, "#@base_url/#@domain/campaigns/#@id/complaints?groupby=month&limit=100")
704
+ stub(:get, "#@base_url/#@domain/campaigns/#@id/complaints?groupby=month&limit=100")
644
705
 
645
706
  @client.get_campaign_complaints(@id, groupby: 'month', limit: 100)
646
707
  end
@@ -648,13 +709,13 @@ describe 'Mailgunner::Client' do
648
709
 
649
710
  describe 'get_lists method' do
650
711
  it 'fetches the lists resource and returns the response object' do
651
- stub_request(:get, "#@base_url/lists").to_return(@json_response)
712
+ stub(:get, "#@base_url/lists")
652
713
 
653
714
  @client.get_lists.must_equal(@json_response_object)
654
715
  end
655
716
 
656
717
  it 'encodes skip and limit parameters' do
657
- stub_request(:get, "#@base_url/lists?skip=1&limit=2")
718
+ stub(:get, "#@base_url/lists?skip=1&limit=2")
658
719
 
659
720
  @client.get_lists(skip: 1, limit: 2)
660
721
  end
@@ -662,7 +723,7 @@ describe 'Mailgunner::Client' do
662
723
 
663
724
  describe 'get_list method' do
664
725
  it 'fetches the list resource with the given address and returns the response object' do
665
- stub_request(:get, "#@base_url/lists/developers%40mailgun.net").to_return(@json_response)
726
+ stub(:get, "#@base_url/lists/developers%40mailgun.net")
666
727
 
667
728
  @client.get_list('developers@mailgun.net').must_equal(@json_response_object)
668
729
  end
@@ -670,7 +731,7 @@ describe 'Mailgunner::Client' do
670
731
 
671
732
  describe 'add_list method' do
672
733
  it 'posts to the lists resource and returns the response object' do
673
- stub_request(:post, "#@base_url/lists").with(body: 'address=developers%40mailgun.net').to_return(@json_response)
734
+ stub(:post, "#@base_url/lists", body: 'address=developers%40mailgun.net')
674
735
 
675
736
  @client.add_list({address: 'developers@mailgun.net'}).must_equal(@json_response_object)
676
737
  end
@@ -678,7 +739,7 @@ describe 'Mailgunner::Client' do
678
739
 
679
740
  describe 'update_list method' do
680
741
  it 'updates the list resource and returns the response object' do
681
- stub_request(:put, "#@base_url/lists/developers%40mailgun.net").with(body: 'name=Example+list').to_return(@json_response)
742
+ stub(:put, "#@base_url/lists/developers%40mailgun.net", body: 'name=Example+list')
682
743
 
683
744
  @client.update_list('developers@mailgun.net', {name: 'Example list'}).must_equal(@json_response_object)
684
745
  end
@@ -686,7 +747,7 @@ describe 'Mailgunner::Client' do
686
747
 
687
748
  describe 'delete_list method' do
688
749
  it 'deletes the list resource with the given address and returns the response object' do
689
- stub_request(:delete, "#@base_url/lists/developers%40mailgun.net").to_return(@json_response)
750
+ stub(:delete, "#@base_url/lists/developers%40mailgun.net")
690
751
 
691
752
  @client.delete_list('developers@mailgun.net').must_equal(@json_response_object)
692
753
  end
@@ -694,13 +755,13 @@ describe 'Mailgunner::Client' do
694
755
 
695
756
  describe 'get_list_members method' do
696
757
  it 'fetches the list members resource and returns the response object' do
697
- stub_request(:get, "#@base_url/lists/developers%40mailgun.net/members").to_return(@json_response)
758
+ stub(:get, "#@base_url/lists/developers%40mailgun.net/members")
698
759
 
699
760
  @client.get_list_members('developers@mailgun.net').must_equal(@json_response_object)
700
761
  end
701
762
 
702
763
  it 'encodes skip and limit parameters' do
703
- stub_request(:get, "#@base_url/lists/developers%40mailgun.net/members?skip=1&limit=2")
764
+ stub(:get, "#@base_url/lists/developers%40mailgun.net/members?skip=1&limit=2")
704
765
 
705
766
  @client.get_list_members('developers@mailgun.net', skip: 1, limit: 2)
706
767
  end
@@ -708,7 +769,7 @@ describe 'Mailgunner::Client' do
708
769
 
709
770
  describe 'get_list_member method' do
710
771
  it 'fetches the list member resource with the given address and returns the response object' do
711
- stub_request(:get, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address").to_return(@json_response)
772
+ stub(:get, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address")
712
773
 
713
774
  @client.get_list_member('developers@mailgun.net', @address).must_equal(@json_response_object)
714
775
  end
@@ -716,7 +777,7 @@ describe 'Mailgunner::Client' do
716
777
 
717
778
  describe 'add_list_member method' do
718
779
  it 'posts to the list members resource and returns the response object' do
719
- stub_request(:post, "#@base_url/lists/developers%40mailgun.net/members").with(body: "address=#@encoded_address").to_return(@json_response)
780
+ stub(:post, "#@base_url/lists/developers%40mailgun.net/members", body: "address=#@encoded_address")
720
781
 
721
782
  @client.add_list_member('developers@mailgun.net', {address: @address}).must_equal(@json_response_object)
722
783
  end
@@ -724,7 +785,7 @@ describe 'Mailgunner::Client' do
724
785
 
725
786
  describe 'update_list_member method' do
726
787
  it 'updates the list member resource with the given address and returns the response object' do
727
- stub_request(:put, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address").with(body: 'subscribed=no').to_return(@json_response)
788
+ stub(:put, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address", body: 'subscribed=no')
728
789
 
729
790
  @client.update_list_member('developers@mailgun.net', @address, {subscribed: 'no'}).must_equal(@json_response_object)
730
791
  end
@@ -732,17 +793,27 @@ describe 'Mailgunner::Client' do
732
793
 
733
794
  describe 'delete_list_member method' do
734
795
  it 'deletes the list member resource with the given address and returns the response object' do
735
- stub_request(:delete, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address").to_return(@json_response)
796
+ stub(:delete, "#@base_url/lists/developers%40mailgun.net/members/#@encoded_address")
736
797
 
737
798
  @client.delete_list_member('developers@mailgun.net', @address).must_equal(@json_response_object)
738
799
  end
739
800
  end
740
801
 
741
- it 'sets the user agent header' do
742
- headers = {'User-Agent' => /\ARuby\/\d+\.\d+\.\d+ Mailgunner\/\d+\.\d+\.\d+\z/}
802
+ it 'raises an exception for authentication errors' do
803
+ stub_request(:any, /api\.mailgun\.net/).to_return(status: 401)
804
+
805
+ proc { @client.get_message(@id) }.must_raise(Mailgunner::AuthenticationError)
806
+ end
807
+
808
+ it 'raises an exception for client errors' do
809
+ stub_request(:any, /api\.mailgun\.net/).to_return(status: 400)
810
+
811
+ proc { @client.get_message(@id) }.must_raise(Mailgunner::ClientError)
812
+ end
743
813
 
744
- stub_request(:get, "#@base_url/domains/#@domain/messages/#@id").with(headers: headers)
814
+ it 'raises an exception for server errors' do
815
+ stub_request(:any, /api\.mailgun\.net/).to_return(status: 500)
745
816
 
746
- @client.get_message(@id)
817
+ proc { @client.get_message(@id) }.must_raise(Mailgunner::ServerError)
747
818
  end
748
819
  end
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.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-03-17 00:00:00.000000000 Z
11
+ date: 2018-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '10.1'
19
+ version: '12'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '10.1'
26
+ version: '12'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: webmock
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.18'
33
+ version: '3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.18'
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mail
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.5'
47
+ version: '2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.5'
54
+ version: '2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: actionmailer
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '4.0'
61
+ version: '5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '4.0'
68
+ version: '5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.0'
75
+ version: '1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.0'
82
+ version: '1'
83
83
  description: Ruby client for the Mailgun API
84
84
  email:
85
85
  - mail@timcraft.com
@@ -91,6 +91,7 @@ files:
91
91
  - README.md
92
92
  - lib/mailgunner.rb
93
93
  - lib/mailgunner/delivery_method.rb
94
+ - lib/mailgunner/errors.rb
94
95
  - lib/mailgunner/railtie.rb
95
96
  - lib/mailgunner/version.rb
96
97
  - mailgunner.gemspec
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  version: '0'
117
118
  requirements: []
118
119
  rubyforge_project:
119
- rubygems_version: 2.4.5.1
120
+ rubygems_version: 2.6.13
120
121
  signing_key:
121
122
  specification_version: 4
122
123
  summary: Ruby client for the Mailgun API