mailgunner 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) TIMCRAFT <http://timcraft.com>
2
+
3
+ This is an Open Source project licensed under the terms of the LGPLv3 license.
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/lib/mailgunner.rb CHANGED
@@ -32,15 +32,23 @@ module Mailgunner
32
32
  end
33
33
 
34
34
  def validate_address(value)
35
- get('/v2/address/validate', address: value)
35
+ get('/v3/address/validate', address: value)
36
36
  end
37
37
 
38
38
  def parse_addresses(values)
39
- get('/v2/address/parse', addresses: Array(values).join(','))
39
+ get('/v3/address/parse', addresses: Array(values).join(','))
40
+ end
41
+
42
+ def get_message(key)
43
+ get("/v3/domains/#{escape @domain}/messages/#{escape key}")
44
+ end
45
+
46
+ def get_mime_message(key)
47
+ get("/v3/domains/#{escape @domain}/messages/#{escape key}", {}, {'Accept' => 'message/rfc2822'})
40
48
  end
41
49
 
42
50
  def send_message(attributes = {})
43
- post("/v2/#{escape @domain}/messages", attributes)
51
+ post("/v3/#{escape @domain}/messages", attributes)
44
52
  end
45
53
 
46
54
  def send_mime(mail)
@@ -48,209 +56,217 @@ module Mailgunner
48
56
 
49
57
  message = ['message', mail.encoded, {filename: 'message.mime'}]
50
58
 
51
- multipart_post("/v2/#{escape @domain}/messages.mime", [to, message])
59
+ multipart_post("/v3/#{escape @domain}/messages.mime", [to, message])
60
+ end
61
+
62
+ def delete_message(key)
63
+ delete("/v3/domains/#{escape @domain}/messages/#{escape key}")
52
64
  end
53
65
 
54
66
  def get_domains(params = {})
55
- get('/v2/domains', params)
67
+ get('/v3/domains', params)
56
68
  end
57
69
 
58
70
  def get_domain(name)
59
- get("/v2/domains/#{escape name}")
71
+ get("/v3/domains/#{escape name}")
60
72
  end
61
73
 
62
74
  def add_domain(attributes = {})
63
- post('/v2/domains', attributes)
75
+ post('/v3/domains', attributes)
64
76
  end
65
77
 
66
78
  def delete_domain(name)
67
- delete("/v2/domains/#{escape name}")
79
+ delete("/v3/domains/#{escape name}")
68
80
  end
69
81
 
70
82
  def get_credentials
71
- get("/v2/domains/#{escape @domain}/credentials")
83
+ get("/v3/domains/#{escape @domain}/credentials")
72
84
  end
73
85
 
74
86
  def add_credentials(attributes)
75
- post("/v2/domains/#{escape @domain}/credentials", attributes)
87
+ post("/v3/domains/#{escape @domain}/credentials", attributes)
76
88
  end
77
89
 
78
90
  def update_credentials(login, attributes)
79
- put("/v2/domains/#{escape @domain}/credentials/#{escape login}", attributes)
91
+ put("/v3/domains/#{escape @domain}/credentials/#{escape login}", attributes)
80
92
  end
81
93
 
82
94
  def delete_credentials(login)
83
- delete("/v2/domains/#{escape @domain}/credentials/#{escape login}")
95
+ delete("/v3/domains/#{escape @domain}/credentials/#{escape login}")
84
96
  end
85
97
 
86
98
  def get_unsubscribes(params = {})
87
- get("/v2/#{escape @domain}/unsubscribes", params)
99
+ get("/v3/#{escape @domain}/unsubscribes", params)
88
100
  end
89
101
 
90
102
  def get_unsubscribe(address)
91
- get("/v2/#{escape @domain}/unsubscribes/#{escape address}")
103
+ get("/v3/#{escape @domain}/unsubscribes/#{escape address}")
92
104
  end
93
105
 
94
106
  def delete_unsubscribe(address_or_id)
95
- delete("/v2/#{escape @domain}/unsubscribes/#{escape address_or_id}")
107
+ delete("/v3/#{escape @domain}/unsubscribes/#{escape address_or_id}")
96
108
  end
97
109
 
98
110
  def add_unsubscribe(attributes = {})
99
- post("/v2/#{escape @domain}/unsubscribes", attributes)
111
+ post("/v3/#{escape @domain}/unsubscribes", attributes)
100
112
  end
101
113
 
102
114
  def get_complaints(params = {})
103
- get("/v2/#{escape @domain}/complaints", params)
115
+ get("/v3/#{escape @domain}/complaints", params)
104
116
  end
105
117
 
106
118
  def get_complaint(address)
107
- get("/v2/#{escape @domain}/complaints/#{escape address}")
119
+ get("/v3/#{escape @domain}/complaints/#{escape address}")
108
120
  end
109
121
 
110
122
  def add_complaint(attributes = {})
111
- post("/v2/#{escape @domain}/complaints", attributes)
123
+ post("/v3/#{escape @domain}/complaints", attributes)
112
124
  end
113
125
 
114
126
  def delete_complaint(address)
115
- delete("/v2/#{escape @domain}/complaints/#{escape address}")
127
+ delete("/v3/#{escape @domain}/complaints/#{escape address}")
116
128
  end
117
129
 
118
130
  def get_bounces(params = {})
119
- get("/v2/#{escape @domain}/bounces", params)
131
+ get("/v3/#{escape @domain}/bounces", params)
120
132
  end
121
133
 
122
134
  def get_bounce(address)
123
- get("/v2/#{escape @domain}/bounces/#{escape address}")
135
+ get("/v3/#{escape @domain}/bounces/#{escape address}")
124
136
  end
125
137
 
126
138
  def add_bounce(attributes = {})
127
- post("/v2/#{escape @domain}/bounces", attributes)
139
+ post("/v3/#{escape @domain}/bounces", attributes)
128
140
  end
129
141
 
130
142
  def delete_bounce(address)
131
- delete("/v2/#{escape @domain}/bounces/#{escape address}")
143
+ delete("/v3/#{escape @domain}/bounces/#{escape address}")
132
144
  end
133
145
 
134
146
  def get_stats(params = {})
135
- get("/v2/#{escape @domain}/stats", params)
147
+ get("/v3/#{escape @domain}/stats", params)
136
148
  end
137
149
 
138
150
  def get_events(params = {})
139
- get("/v2/#{escape @domain}/events", params)
151
+ get("/v3/#{escape @domain}/events", params)
140
152
  end
141
153
 
142
154
  def get_routes(params = {})
143
- get('/v2/routes', params)
155
+ get('/v3/routes', params)
144
156
  end
145
157
 
146
158
  def get_route(id)
147
- get("/v2/routes/#{escape id}")
159
+ get("/v3/routes/#{escape id}")
148
160
  end
149
161
 
150
162
  def add_route(attributes = {})
151
- post('/v2/routes', attributes)
163
+ post('/v3/routes', attributes)
152
164
  end
153
165
 
154
166
  def update_route(id, attributes = {})
155
- put("/v2/routes/#{escape id}", attributes)
167
+ put("/v3/routes/#{escape id}", attributes)
156
168
  end
157
169
 
158
170
  def delete_route(id)
159
- delete("/v2/routes/#{escape id}")
171
+ delete("/v3/routes/#{escape id}")
160
172
  end
161
173
 
162
174
  def get_campaigns(params = {})
163
- get("/v2/#{escape @domain}/campaigns", params)
175
+ get("/v3/#{escape @domain}/campaigns", params)
164
176
  end
165
177
 
166
178
  def get_campaign(id)
167
- get("/v2/#{escape @domain}/campaigns/#{escape id}")
179
+ get("/v3/#{escape @domain}/campaigns/#{escape id}")
168
180
  end
169
181
 
170
182
  def add_campaign(attributes = {})
171
- post("/v2/#{escape @domain}/campaigns", attributes)
183
+ post("/v3/#{escape @domain}/campaigns", attributes)
172
184
  end
173
185
 
174
186
  def update_campaign(id, attributes = {})
175
- put("/v2/#{escape @domain}/campaigns/#{escape id}", attributes)
187
+ put("/v3/#{escape @domain}/campaigns/#{escape id}", attributes)
176
188
  end
177
189
 
178
190
  def delete_campaign(id)
179
- delete("/v2/#{escape @domain}/campaigns/#{escape id}")
191
+ delete("/v3/#{escape @domain}/campaigns/#{escape id}")
180
192
  end
181
193
 
182
194
  def get_campaign_events(campaign_id, params = {})
183
- get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/events", params)
195
+ get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/events", params)
184
196
  end
185
197
 
186
198
  def get_campaign_stats(campaign_id, params = {})
187
- get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/stats", params)
199
+ get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/stats", params)
188
200
  end
189
201
 
190
202
  def get_campaign_clicks(campaign_id, params = {})
191
- get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/clicks", params)
203
+ get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/clicks", params)
192
204
  end
193
205
 
194
206
  def get_campaign_opens(campaign_id, params = {})
195
- get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/opens", params)
207
+ get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/opens", params)
196
208
  end
197
209
 
198
210
  def get_campaign_unsubscribes(campaign_id, params = {})
199
- get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/unsubscribes", params)
211
+ get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/unsubscribes", params)
200
212
  end
201
213
 
202
214
  def get_campaign_complaints(campaign_id, params = {})
203
- get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/complaints", params)
215
+ get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/complaints", params)
204
216
  end
205
217
 
206
218
  def get_lists(params = {})
207
- get('/v2/lists', params)
219
+ get('/v3/lists', params)
208
220
  end
209
221
 
210
222
  def get_list(address)
211
- get("/v2/lists/#{escape address}")
223
+ get("/v3/lists/#{escape address}")
212
224
  end
213
225
 
214
226
  def add_list(attributes = {})
215
- post('/v2/lists', attributes)
227
+ post('/v3/lists', attributes)
216
228
  end
217
229
 
218
230
  def update_list(address, attributes = {})
219
- put("/v2/lists/#{escape address}", attributes)
231
+ put("/v3/lists/#{escape address}", attributes)
220
232
  end
221
233
 
222
234
  def delete_list(address)
223
- delete("/v2/lists/#{escape address}")
235
+ delete("/v3/lists/#{escape address}")
224
236
  end
225
237
 
226
238
  def get_list_members(list_address, params = {})
227
- get("/v2/lists/#{escape list_address}/members", params)
239
+ get("/v3/lists/#{escape list_address}/members", params)
228
240
  end
229
241
 
230
242
  def get_list_member(list_address, member_address)
231
- get("/v2/lists/#{escape list_address}/members/#{escape member_address}")
243
+ get("/v3/lists/#{escape list_address}/members/#{escape member_address}")
232
244
  end
233
245
 
234
246
  def add_list_member(list_address, member_attributes)
235
- post("/v2/lists/#{escape list_address}/members", member_attributes)
247
+ post("/v3/lists/#{escape list_address}/members", member_attributes)
236
248
  end
237
249
 
238
250
  def update_list_member(list_address, member_address, member_attributes)
239
- put("/v2/lists/#{escape list_address}/members/#{escape member_address}", member_attributes)
251
+ put("/v3/lists/#{escape list_address}/members/#{escape member_address}", member_attributes)
240
252
  end
241
253
 
242
254
  def delete_list_member(list_address, member_address)
243
- delete("/v2/lists/#{escape list_address}/members/#{escape member_address}")
255
+ delete("/v3/lists/#{escape list_address}/members/#{escape member_address}")
244
256
  end
245
257
 
246
258
  def get_list_stats(list_address)
247
- get("/v2/lists/#{escape list_address}/stats")
259
+ get("/v3/lists/#{escape list_address}/stats")
248
260
  end
249
261
 
250
262
  private
251
263
 
252
- def get(path, params = {})
253
- transmit(Net::HTTP::Get.new(request_uri(path, params)))
264
+ def get(path, params = {}, headers = {})
265
+ request = Net::HTTP::Get.new(request_uri(path, params))
266
+
267
+ headers.each { |k, v| request[k] = v }
268
+
269
+ transmit(request)
254
270
  end
255
271
 
256
272
  def post(path, attributes = {})
data/mailgunner.gemspec CHANGED
@@ -1,13 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mailgunner'
3
- s.version = '2.1.0'
3
+ s.version = '2.2.0'
4
+ s.license = 'LGPL-3.0'
4
5
  s.platform = Gem::Platform::RUBY
5
6
  s.authors = ['Tim Craft']
6
7
  s.email = ['mail@timcraft.com']
7
8
  s.homepage = 'http://github.com/timcraft/mailgunner'
8
9
  s.description = 'A Ruby wrapper for the Mailgun API'
9
10
  s.summary = 'See description'
10
- s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md mailgunner.gemspec)
11
+ s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md mailgunner.gemspec)
11
12
  s.required_ruby_version = '>= 1.9.3'
12
13
  s.add_development_dependency('rake', '~> 10.1')
13
14
  s.add_development_dependency('webmock', '~> 1.18')
@@ -18,7 +18,7 @@ describe 'Mailgunner::DeliveryMethod' do
18
18
 
19
19
  @domain = 'samples.mailgun.org'
20
20
 
21
- @base_url = "https://api:#@api_key@api.mailgun.net/v2"
21
+ @base_url = "https://api:#@api_key@api.mailgun.net/v3"
22
22
 
23
23
  @address = 'user@example.com'
24
24
 
@@ -30,7 +30,7 @@ describe 'Mailgunner::DeliveryMethod' do
30
30
  it 'delivers the mail to mailgun in mime format' do
31
31
  stub_request(:post, "#@base_url/#@domain/messages.mime")
32
32
 
33
- ExampleMailer.registration_confirmation(email: @address).deliver
33
+ ExampleMailer.registration_confirmation(email: @address).deliver_now
34
34
  end
35
35
 
36
36
  it 'raises an exception if the api returns an error' do
@@ -40,7 +40,7 @@ describe 'Mailgunner::DeliveryMethod' do
40
40
  body: '{"message": "Invalid API key"}'
41
41
  })
42
42
 
43
- exception = proc { ExampleMailer.registration_confirmation(email: @address).deliver }.must_raise(Mailgunner::Error)
43
+ exception = proc { ExampleMailer.registration_confirmation(email: @address).deliver_now }.must_raise(Mailgunner::Error)
44
44
 
45
45
  exception.message.must_include('Invalid API key')
46
46
  end
@@ -10,7 +10,7 @@ describe 'Mailgunner::Client' do
10
10
 
11
11
  @api_key = 'xxx'
12
12
 
13
- @base_url = "https://api:#{@api_key}@api.mailgun.net/v2"
13
+ @base_url = "https://api:#{@api_key}@api.mailgun.net/v3"
14
14
 
15
15
  @json_response = {headers: {'Content-Type' => 'application/json;charset=utf-8'}, body: '{"key":"value"}'}
16
16
 
@@ -77,6 +77,27 @@ describe 'Mailgunner::Client' do
77
77
  end
78
78
  end
79
79
 
80
+ describe 'get_message method' do
81
+ it 'fetches the domain message resource with the given key and returns the response object' do
82
+ key = 'WyIzMmkey'
83
+
84
+ stub_request(:get, "#@base_url/domains/#@domain/messages/#{key}").to_return(@json_response)
85
+
86
+ @client.get_message(key).must_equal(@json_response_object)
87
+ end
88
+ end
89
+
90
+ describe 'get_mime_message method' do
91
+ it 'fetches the domain message resource with the given key and returns the response object' do
92
+ key = 'WyIzMmkey'
93
+
94
+ stub_request(:get, "#@base_url/domains/#@domain/messages/#{key}").
95
+ with(headers: {'Accept' => 'message/rfc2822'}).to_return(@json_response)
96
+
97
+ @client.get_mime_message(key).must_equal(@json_response_object)
98
+ end
99
+ end
100
+
80
101
  describe 'send_message method' do
81
102
  it 'posts to the domain messages resource and returns the response object' do
82
103
  stub_request(:post, "#@base_url/#@domain/messages").to_return(@json_response)
@@ -119,6 +140,16 @@ describe 'Mailgunner::Client' do
119
140
  end
120
141
  end
121
142
 
143
+ describe 'delete_message method' do
144
+ it 'deletes the domain message resource with the given key and returns the response object' do
145
+ key = 'WyIzMmkey'
146
+
147
+ stub_request(:delete, "#@base_url/domains/#@domain/messages/#{key}").to_return(@json_response)
148
+
149
+ @client.delete_message(key)
150
+ end
151
+ end
152
+
122
153
  describe 'get_domains method' do
123
154
  it 'fetches the domains resource and returns the response object' do
124
155
  stub_request(:get, "#@base_url/domains").to_return(@json_response)
metadata CHANGED
@@ -1,69 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Tim Craft
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
12
+ date: 2015-04-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '10.1'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '10.1'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: webmock
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - "~>"
35
+ - - ~>
32
36
  - !ruby/object:Gem::Version
33
37
  version: '1.18'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - "~>"
43
+ - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: '1.18'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: mail
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - "~>"
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '2.5'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - "~>"
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '2.5'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: actionmailer
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - "~>"
67
+ - - ~>
60
68
  - !ruby/object:Gem::Version
61
69
  version: '4.0'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - "~>"
75
+ - - ~>
67
76
  - !ruby/object:Gem::Version
68
77
  version: '4.0'
69
78
  description: A Ruby wrapper for the Mailgun API
@@ -73,33 +82,36 @@ executables: []
73
82
  extensions: []
74
83
  extra_rdoc_files: []
75
84
  files:
76
- - README.md
77
- - lib/mailgunner.rb
78
85
  - lib/mailgunner/delivery_method.rb
79
- - mailgunner.gemspec
86
+ - lib/mailgunner.rb
80
87
  - spec/mailgunner_delivery_method_spec.rb
81
88
  - spec/mailgunner_spec.rb
89
+ - LICENSE.txt
90
+ - README.md
91
+ - mailgunner.gemspec
82
92
  homepage: http://github.com/timcraft/mailgunner
83
- licenses: []
84
- metadata: {}
93
+ licenses:
94
+ - LGPL-3.0
85
95
  post_install_message:
86
96
  rdoc_options: []
87
97
  require_paths:
88
98
  - lib
89
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
90
101
  requirements:
91
- - - ">="
102
+ - - ! '>='
92
103
  - !ruby/object:Gem::Version
93
104
  version: 1.9.3
94
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
95
107
  requirements:
96
- - - ">="
108
+ - - ! '>='
97
109
  - !ruby/object:Gem::Version
98
110
  version: '0'
99
111
  requirements: []
100
112
  rubyforge_project:
101
- rubygems_version: 2.2.2
113
+ rubygems_version: 1.8.23.2
102
114
  signing_key:
103
- specification_version: 4
115
+ specification_version: 3
104
116
  summary: See description
105
117
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: c1e24be43e9330f9378bbd977baabea868042090
4
- data.tar.gz: 812d150cb717e63be9e99b66c2c695981d711a7f
5
- SHA512:
6
- metadata.gz: 00d1306a5501800bfdc87ec29c9244dd232cd126c87ce7c35a5773100336be0afc4d3cf2c166bfc2b31189e59c71d280328be005b24c83ebda8c2163db2d4ee0
7
- data.tar.gz: 06664445a8ece38b1dee4bc92850867ac1a098f2aa212ce6be0341ba962dec6838e9d04783157325f7a7838d04cefbe02a7d31def684c3da6a2e52e69c43630a