mailgunner 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,26 @@
1
- A Ruby wrapper for the [Mailgun API](http://documentation.mailgun.net/api_reference.html)
2
- =========================================================================================
1
+ mailgunner
2
+ ==========
3
3
 
4
4
 
5
- Quick Start
5
+ A Ruby wrapper for the [Mailgun API](http://documentation.mailgun.net/api_reference.html).
6
+
7
+
8
+ Installation
9
+ ------------
10
+
11
+ $ gem install mailgunner
12
+
13
+
14
+ Quick start
6
15
  -----------
7
16
 
8
17
  ```ruby
9
18
  require 'mailgunner'
10
19
 
11
- mailgun = Mailgunner::Client.new(domain: 'samples.mailgun.org', api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0')
20
+ mailgun = Mailgunner::Client.new({
21
+ domain: 'samples.mailgun.org',
22
+ api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'
23
+ })
12
24
 
13
25
  response = mailgun.get_stats(limit: 5)
14
26
 
@@ -20,20 +32,7 @@ end
20
32
  ```
21
33
 
22
34
 
23
- Alternative JSON Implementations
24
- --------------------------------
25
-
26
- Mailgunner::Client defaults to using the "json" library which is available
27
- in the Ruby 1.9 standard library, and as a gem for Ruby 1.8. You can specify
28
- an alternative implementation using the json option when constructing a client
29
- object. For example, to use [multi_json](https://rubygems.org/gems/multi_json):
30
-
31
- ```ruby
32
- mailgun = Mailgunner::Client.new(:json => MultiJson)
33
- ```
34
-
35
-
36
- Environment Variables
35
+ Environment variables
37
36
  ---------------------
38
37
 
39
38
  Best practice for storing credentials for external services is to use environment
@@ -42,4 +41,3 @@ variables, as described by [12factor.net/config](http://www.12factor.net/config)
42
41
  Mailgunner::Client defaults to extracting the domain and api_key values it needs
43
42
  from the MAILGUN_API_KEY and MAILGUN_SMTP_LOGIN environment variables. These will
44
43
  exist if you are using Mailgun on Heroku, or you can set them manually.
45
-
data/lib/mailgunner.rb CHANGED
@@ -5,20 +5,38 @@ require 'uri'
5
5
 
6
6
  module Mailgunner
7
7
  class Client
8
- attr_accessor :domain, :api_key, :json, :http
8
+ attr_accessor :domain, :api_key, :http
9
9
 
10
10
  def initialize(options = {})
11
11
  @domain = options.fetch(:domain) { ENV.fetch('MAILGUN_SMTP_LOGIN').split('@').last }
12
12
 
13
13
  @api_key = options.fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') }
14
14
 
15
- @json = options.fetch(:json) { JSON }
15
+ if options.has_key?(:json)
16
+ Kernel.warn 'Mailgunner::Client :json option is deprecated'
17
+
18
+ @json = options[:json]
19
+ else
20
+ @json = JSON
21
+ end
16
22
 
17
23
  @http = Net::HTTP.new('api.mailgun.net', Net::HTTP.https_default_port)
18
24
 
19
25
  @http.use_ssl = true
20
26
  end
21
27
 
28
+ def json
29
+ Kernel.warn 'Mailgunner::Client#json is deprecated'
30
+
31
+ @json
32
+ end
33
+
34
+ def json=(json)
35
+ Kernel.warn 'Mailgunner::Client#json= is deprecated'
36
+
37
+ @json = json
38
+ end
39
+
22
40
  def send_message(attributes = {})
23
41
  post("/v2/#{escape @domain}/messages", attributes)
24
42
  end
@@ -112,18 +130,26 @@ module Mailgunner
112
130
  end
113
131
 
114
132
  def get_mailboxes(params = {})
133
+ Kernel.warn 'Mailgunner::Client#get_mailboxes is deprecated'
134
+
115
135
  get("/v2/#{escape @domain}/mailboxes", params)
116
136
  end
117
137
 
118
138
  def add_mailbox(attributes = {})
139
+ Kernel.warn 'Mailgunner::Client#add_mailbox is deprecated'
140
+
119
141
  post("/v2/#{escape @domain}/mailboxes", attributes)
120
142
  end
121
143
 
122
144
  def update_mailbox(name, attributes = {})
145
+ Kernel.warn 'Mailgunner::Client#update_mailbox is deprecated'
146
+
123
147
  put("/v2/#{escape @domain}/mailboxes/#{escape name}", attributes)
124
148
  end
125
149
 
126
150
  def delete_mailbox(name)
151
+ Kernel.warn 'Mailgunner::Client#delete_mailbox is deprecated'
152
+
127
153
  delete("/v2/#{escape @domain}/mailboxes/#{escape name}")
128
154
  end
129
155
 
@@ -294,7 +320,7 @@ module Mailgunner
294
320
  end
295
321
 
296
322
  def object
297
- @object ||= @json.load(body)
323
+ @object ||= @json.parse(body)
298
324
  end
299
325
  end
300
326
  end
data/mailgunner.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mailgunner'
3
- s.version = '1.0.0'
3
+ s.version = '1.1.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.summary = 'See description'
10
10
  s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md mailgunner.gemspec)
11
11
  s.add_development_dependency('rake', '>= 0.9.3')
12
- s.add_development_dependency('mocha', '~> 0.10.3')
12
+ s.add_development_dependency('mocha', '~> 0.13.2')
13
+ s.add_development_dependency('faux', '~> 1.1.0')
13
14
  s.require_path = 'lib'
14
15
  end
@@ -1,6 +1,8 @@
1
1
  require 'minitest/autorun'
2
+ require 'mocha/setup'
2
3
  require 'mailgunner'
3
- require 'mocha'
4
+ require 'faux'
5
+ require 'json'
4
6
 
5
7
  class Net::HTTPGenericRequest
6
8
  def inspect
@@ -63,18 +65,6 @@ describe 'Mailgunner::Client' do
63
65
  end
64
66
  end
65
67
 
66
- describe 'json method' do
67
- it 'returns the value passed to the constructor' do
68
- json = stub
69
-
70
- Mailgunner::Client.new(json: json).json.must_equal(json)
71
- end
72
-
73
- it 'defaults to the standard library json implementation' do
74
- @client.json.must_equal(JSON)
75
- end
76
- end
77
-
78
68
  describe 'send_message method' do
79
69
  it 'posts to the domain messages resource and returns a response object' do
80
70
  expect(Net::HTTP::Post, "/v2/#@domain/messages")
@@ -348,7 +338,11 @@ describe 'Mailgunner::Client' do
348
338
  end
349
339
 
350
340
  describe 'get_mailboxes method' do
351
- it 'fetches the domain mailboxes resource and returns a response object' do
341
+ before do
342
+ Kernel.stubs(:warn)
343
+ end
344
+
345
+ it 'emits a deprecation warning and fetches the domain mailboxes resource and returns a response object' do
352
346
  expect(Net::HTTP::Get, "/v2/#@domain/mailboxes")
353
347
 
354
348
  @client.get_mailboxes.must_be_instance_of(Mailgunner::Response)
@@ -359,9 +353,21 @@ describe 'Mailgunner::Client' do
359
353
 
360
354
  @client.get_mailboxes(skip: 1, limit: 2)
361
355
  end
356
+
357
+ it 'emits a deprecation warning' do
358
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#get_mailboxes is deprecated/))
359
+
360
+ @client.http.stubs(:request)
361
+
362
+ @client.get_mailboxes
363
+ end
362
364
  end
363
365
 
364
366
  describe 'add_mailbox method' do
367
+ before do
368
+ Kernel.stubs(:warn)
369
+ end
370
+
365
371
  it 'posts to the domain mailboxes resource and returns a response object' do
366
372
  expect(Net::HTTP::Post, "/v2/#@domain/mailboxes")
367
373
 
@@ -373,9 +379,21 @@ describe 'Mailgunner::Client' do
373
379
 
374
380
  @client.add_mailbox({mailbox: 'user'})
375
381
  end
382
+
383
+ it 'emits a deprecation warning' do
384
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#add_mailbox is deprecated/))
385
+
386
+ @client.http.stubs(:request)
387
+
388
+ @client.add_mailbox({})
389
+ end
376
390
  end
377
391
 
378
392
  describe 'update_mailbox method' do
393
+ before do
394
+ Kernel.stubs(:warn)
395
+ end
396
+
379
397
  it 'updates the mailbox resource and returns a response object' do
380
398
  expect(Net::HTTP::Put, "/v2/#@domain/mailboxes/user")
381
399
 
@@ -387,14 +405,34 @@ describe 'Mailgunner::Client' do
387
405
 
388
406
  @client.update_mailbox('user', {password: 'secret'})
389
407
  end
408
+
409
+ it 'emits a deprecation warning' do
410
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#update_mailbox is deprecated/))
411
+
412
+ @client.http.stubs(:request)
413
+
414
+ @client.update_mailbox('user', {})
415
+ end
390
416
  end
391
417
 
392
418
  describe 'delete_mailbox method' do
419
+ before do
420
+ Kernel.stubs(:warn)
421
+ end
422
+
393
423
  it 'deletes the domain mailbox resource with the given address and returns a response object' do
394
424
  expect(Net::HTTP::Delete, "/v2/#@domain/mailboxes/user")
395
425
 
396
426
  @client.delete_mailbox('user').must_be_instance_of(Mailgunner::Response)
397
427
  end
428
+
429
+ it 'emits a deprecation warning' do
430
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#delete_mailbox is deprecated/))
431
+
432
+ @client.http.stubs(:request)
433
+
434
+ @client.delete_mailbox('user')
435
+ end
398
436
  end
399
437
 
400
438
  describe 'get_campaigns method' do
@@ -662,6 +700,41 @@ describe 'Mailgunner::Client' do
662
700
  @client.get_list_stats('developers@mailgun.net').must_be_instance_of(Mailgunner::Response)
663
701
  end
664
702
  end
703
+
704
+ describe 'json method' do
705
+ it 'emits a deprecation warning and returns the standard library json module' do
706
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#json is deprecated/))
707
+
708
+ Mailgunner::Client.new.json.must_equal(JSON)
709
+ end
710
+ end
711
+
712
+ describe 'json equals method' do
713
+ it 'emits a deprecation warning' do
714
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#json= is deprecated/))
715
+
716
+ Mailgunner::Client.new.json = nil
717
+ end
718
+ end
719
+
720
+ describe 'when initialized with a different json implementation' do
721
+ it 'emits a deprecation warning' do
722
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client :json option is deprecated/))
723
+
724
+ Mailgunner::Client.new(domain: @domain, api_key: @api_key, json: stub)
725
+ end
726
+
727
+ describe 'json method' do
728
+ it 'emits a deprecation warning and returns the value passed to the constructor' do
729
+ json = stub
730
+
731
+ Kernel.expects(:warn).once
732
+ Kernel.expects(:warn).with(regexp_matches(/Mailgunner::Client#json is deprecated/))
733
+
734
+ Mailgunner::Client.new(json: json).json.must_equal(json)
735
+ end
736
+ end
737
+ end
665
738
  end
666
739
 
667
740
  describe 'Mailgunner::Response' do
@@ -744,9 +817,9 @@ end
744
817
 
745
818
  describe 'Mailgunner::Response initialized with an alternative json implementation' do
746
819
  before do
747
- @json = mock()
820
+ @json = faux(JSON)
748
821
 
749
- @http_response = mock()
822
+ @http_response = stub
750
823
 
751
824
  @response = Mailgunner::Response.new(@http_response, :json => @json)
752
825
  end
@@ -755,7 +828,7 @@ describe 'Mailgunner::Response initialized with an alternative json implementati
755
828
  it 'uses the alternative json implementation to parse the response body' do
756
829
  @http_response.stubs(:body).returns(response_body = '{"foo":"bar"}')
757
830
 
758
- @json.expects(:load).with(response_body)
831
+ @json.expects(:parse).with(response_body)
759
832
 
760
833
  @response.object
761
834
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.10.3
37
+ version: 0.13.2
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,23 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.10.3
45
+ version: 0.13.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: faux
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
46
62
  description: A Ruby wrapper for the Mailgun API
47
63
  email:
48
64
  - mail@timcraft.com
@@ -74,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
90
  version: '0'
75
91
  requirements: []
76
92
  rubyforge_project:
77
- rubygems_version: 1.8.24
93
+ rubygems_version: 1.8.25
78
94
  signing_key:
79
95
  specification_version: 3
80
96
  summary: See description