mailgunner 2.5.0 → 2.6.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
- SHA1:
3
- metadata.gz: d953d49216e0419f517316128a12974aefc63ce7
4
- data.tar.gz: 23857d5d6ddf925bb6d07a5f20c5069afe80d0e2
2
+ SHA256:
3
+ metadata.gz: ffd33ded9bd33ca044bbe54fc8d89a876bb9949fb91c98ef0f677cc0ca82f4f5
4
+ data.tar.gz: 7d4ba505f5b1de914fc360b23f64d14497e40e6ca01ecb4e8421560c0404e36d
5
5
  SHA512:
6
- metadata.gz: 2b4c452b40c78d8d569efdc93ce24d0980616546e69fedde804721331ff47d536f93ceba3341c6f0ff7854a4a7957979e21121ba766980f29d01a876f2a0a5d5
7
- data.tar.gz: 6e531aa0c226284e539f5e5b9128e30ef9c3fcd21da511dbacc95ec2c8c8b6ebe0ec41ef2d60469a2510a5b10355a3a91b17ce3c73a1842d10a79acb1fd441ae
6
+ metadata.gz: bfea517bd1e392add5a730c417a8aa479279503a574b9855e22a37a8bf1da56c8d972900173fbecb1cc39b73cf0c5eb6772a44b3681c3f2566c5ce9ff2aa4559
7
+ data.tar.gz: 739a82133f746ad9117dbd6655dec76324de3b1cf3394c2c35672a44306e9cab643e7b29174f7cd2823a477d82e174cbb68a40cf21c54f4dd007dc0c528c1ac0
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # mailgunner
2
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
+ [![Gem Version](https://badge.fury.io/rb/mailgunner.svg)](https://badge.fury.io/rb/mailgunner) [![Build Status](https://api.travis-ci.org/readysteady/mailgunner.svg?branch=master)](https://travis-ci.org/readysteady/mailgunner)
4
4
 
5
5
 
6
- Ruby client for the [Mailgun API](http://documentation.mailgun.net/api_reference.html).
6
+ Ruby client for the [Mailgun API](https://documentation.mailgun.com/en/latest/api_reference.html).
7
7
 
8
8
 
9
9
  ## Installation
@@ -21,16 +21,19 @@ mailgun = Mailgunner::Client.new({
21
21
  api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'
22
22
  })
23
23
 
24
- response = mailgun.get_stats(limit: 5)
24
+ response = mailgun.get_domains
25
+
26
+ response['items'].each do |item|
27
+ p item.values_at('id', 'name')
28
+ end
25
29
  ```
26
30
 
27
31
 
28
32
  ## Storing the API key
29
33
 
30
- Best practice for storing credentials for external services is to use environment
31
- variables, as described by [12factor.net/config](http://www.12factor.net/config).
32
- Mailgunner::Client defaults to extracting the domain and api_key values it needs
33
- from the MAILGUN_API_KEY and MAILGUN_SMTP_LOGIN environment variables. These will
34
+ Best practice for credentials is to [store them in the environment](https://www.12factor.net/config#store_config_in_the_environment).
35
+ `Mailgunner::Client` defaults to extracting the domain and api_key values it needs
36
+ from the `MAILGUN_API_KEY` and `MAILGUN_SMTP_LOGIN` environment variables—these will
34
37
  exist if you are using Mailgun on Heroku, or you can set them manually.
35
38
 
36
39
 
@@ -42,22 +45,36 @@ the following line to `config/environments/production.rb`:
42
45
 
43
46
  ```ruby
44
47
  config.action_mailer.delivery_method = :mailgun
45
- ````
48
+ ```
46
49
 
47
50
  If for some reason you can't set the required ENV variables, you can configure Mailgunner
48
51
  through ActionMailer settings:
49
52
 
50
53
  ```ruby
51
54
  config.action_mailer.mailgun_settings = {
52
- domain: 'test.com'
55
+ domain: 'test.com',
53
56
  api_key: 'your-api-key'
54
57
  }
55
-
56
58
  ```
57
59
 
58
60
  Outside of Rails you can set `ActionMailer::Base.delivery_method` directly.
59
61
 
60
62
 
63
+ ## Specifying the region
64
+
65
+ Mailgun offers both a US and EU region to send your e-mail from. Mailgunner uses
66
+ the US region by default. If you wish to use the EU region set the `api_host`
67
+ config option like so:
68
+
69
+ ```ruby
70
+ mailgun = Mailgunner::Client.new({
71
+ domain: 'eu.samples.mailgun.org',
72
+ api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0',
73
+ api_host: 'api.eu.mailgun.net'
74
+ })
75
+ ```
76
+
77
+
61
78
  ## Email validation
62
79
 
63
80
  If you only need to use Mailgun's [email address validation service](http://documentation.mailgun.com/api-email-validation.html),
@@ -1,385 +1,16 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'cgi'
4
1
  require 'mailgunner/version'
5
2
  require 'mailgunner/errors'
3
+ require 'mailgunner/client'
4
+ require 'mailgunner/client/domains'
5
+ require 'mailgunner/client/email_validation'
6
+ require 'mailgunner/client/events'
7
+ require 'mailgunner/client/ips'
8
+ require 'mailgunner/client/mailing_lists'
9
+ require 'mailgunner/client/messages'
10
+ require 'mailgunner/client/routes'
11
+ require 'mailgunner/client/stats'
12
+ require 'mailgunner/client/suppressions'
13
+ require 'mailgunner/client/tags'
14
+ require 'mailgunner/client/webhooks'
6
15
  require 'mailgunner/delivery_method' if defined?(Mail)
7
16
  require 'mailgunner/railtie' if defined?(Rails)
8
-
9
- module Mailgunner
10
- class Client
11
- attr_accessor :domain, :api_key, :http
12
-
13
- def initialize(options = {})
14
- @domain = if options.key?(:domain)
15
- options.fetch(:domain)
16
- elsif ENV.key?('MAILGUN_SMTP_LOGIN')
17
- ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last
18
- else
19
- NoDomainProvided
20
- end
21
-
22
- @api_key = options.fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') }
23
-
24
- @http = Net::HTTP.new('api.mailgun.net', Net::HTTP.https_default_port)
25
-
26
- @http.use_ssl = true
27
- end
28
-
29
- def validate_address(value)
30
- get('/v3/address/validate', address: value)
31
- end
32
-
33
- def parse_addresses(values)
34
- get('/v3/address/parse', addresses: Array(values).join(','))
35
- end
36
-
37
- def get_message(key)
38
- get("/v3/domains/#{escape @domain}/messages/#{escape key}")
39
- end
40
-
41
- def get_mime_message(key)
42
- get("/v3/domains/#{escape @domain}/messages/#{escape key}", {}, {'Accept' => 'message/rfc2822'})
43
- end
44
-
45
- def send_message(attributes = {})
46
- post("/v3/#{escape @domain}/messages", attributes)
47
- end
48
-
49
- def send_mime(mail)
50
- to = ['to', Array(mail.destinations).join(',')]
51
-
52
- message = ['message', mail.encoded, {filename: 'message.mime'}]
53
-
54
- multipart_post("/v3/#{escape @domain}/messages.mime", [to, message])
55
- end
56
-
57
- def delete_message(key)
58
- delete("/v3/domains/#{escape @domain}/messages/#{escape key}")
59
- end
60
-
61
- def get_domains(params = {})
62
- get('/v3/domains', params)
63
- end
64
-
65
- def get_domain(name)
66
- get("/v3/domains/#{escape name}")
67
- end
68
-
69
- def add_domain(attributes = {})
70
- post('/v3/domains', attributes)
71
- end
72
-
73
- def delete_domain(name)
74
- delete("/v3/domains/#{escape name}")
75
- end
76
-
77
- def get_credentials
78
- get("/v3/domains/#{escape @domain}/credentials")
79
- end
80
-
81
- def add_credentials(attributes)
82
- post("/v3/domains/#{escape @domain}/credentials", attributes)
83
- end
84
-
85
- def update_credentials(login, attributes)
86
- put("/v3/domains/#{escape @domain}/credentials/#{escape login}", attributes)
87
- end
88
-
89
- def delete_credentials(login)
90
- delete("/v3/domains/#{escape @domain}/credentials/#{escape login}")
91
- end
92
-
93
- def get_connection_settings
94
- get("/v3/domains/#{escape @domain}/connection")
95
- end
96
-
97
- def update_connection_settings(attributes)
98
- put("/v3/domains/#{escape @domain}/connection", attributes)
99
- end
100
-
101
- def get_unsubscribes(params = {})
102
- get("/v3/#{escape @domain}/unsubscribes", params)
103
- end
104
-
105
- def get_unsubscribe(address)
106
- get("/v3/#{escape @domain}/unsubscribes/#{escape address}")
107
- end
108
-
109
- def delete_unsubscribe(address_or_id)
110
- delete("/v3/#{escape @domain}/unsubscribes/#{escape address_or_id}")
111
- end
112
-
113
- def add_unsubscribe(attributes = {})
114
- post("/v3/#{escape @domain}/unsubscribes", attributes)
115
- end
116
-
117
- def get_complaints(params = {})
118
- get("/v3/#{escape @domain}/complaints", params)
119
- end
120
-
121
- def get_complaint(address)
122
- get("/v3/#{escape @domain}/complaints/#{escape address}")
123
- end
124
-
125
- def add_complaint(attributes = {})
126
- post("/v3/#{escape @domain}/complaints", attributes)
127
- end
128
-
129
- def delete_complaint(address)
130
- delete("/v3/#{escape @domain}/complaints/#{escape address}")
131
- end
132
-
133
- def get_bounces(params = {})
134
- get("/v3/#{escape @domain}/bounces", params)
135
- end
136
-
137
- def get_bounce(address)
138
- get("/v3/#{escape @domain}/bounces/#{escape address}")
139
- end
140
-
141
- def add_bounce(attributes = {})
142
- post("/v3/#{escape @domain}/bounces", attributes)
143
- end
144
-
145
- def delete_bounce(address)
146
- delete("/v3/#{escape @domain}/bounces/#{escape address}")
147
- end
148
-
149
- def delete_bounces
150
- delete("/v3/#{escape @domain}/bounces")
151
- end
152
-
153
- def get_stats(params = {})
154
- Kernel.warn 'Mailgunner::Client#get_stats is deprecated'
155
-
156
- get("/v3/#{escape @domain}/stats", params)
157
- end
158
-
159
- def get_total_stats(params = {})
160
- get("/v3/#{escape @domain}/stats/total", params)
161
- end
162
-
163
- def get_events(params = {})
164
- get("/v3/#{escape @domain}/events", params)
165
- end
166
-
167
- def get_tags(params = {})
168
- get("/v3/#{escape @domain}/tags", params)
169
- end
170
-
171
- def get_tag(id)
172
- get("/v3/#{escape @domain}/tags/#{escape id}")
173
- end
174
-
175
- def update_tag(id, attributes)
176
- put("/v3/#{escape @domain}/tags/#{escape id}", attributes)
177
- end
178
-
179
- def get_tag_stats(id, params)
180
- get("/v3/#{escape @domain}/tags/#{escape id}/stats", params)
181
- end
182
-
183
- def delete_tag(id)
184
- delete("/v3/#{escape @domain}/tags/#{escape id}")
185
- end
186
-
187
- def get_routes(params = {})
188
- get('/v3/routes', params)
189
- end
190
-
191
- def get_route(id)
192
- get("/v3/routes/#{escape id}")
193
- end
194
-
195
- def add_route(attributes = {})
196
- post('/v3/routes', attributes)
197
- end
198
-
199
- def update_route(id, attributes = {})
200
- put("/v3/routes/#{escape id}", attributes)
201
- end
202
-
203
- def delete_route(id)
204
- delete("/v3/routes/#{escape id}")
205
- end
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
-
227
- def get_campaigns(params = {})
228
- get("/v3/#{escape @domain}/campaigns", params)
229
- end
230
-
231
- def get_campaign(id)
232
- get("/v3/#{escape @domain}/campaigns/#{escape id}")
233
- end
234
-
235
- def add_campaign(attributes = {})
236
- post("/v3/#{escape @domain}/campaigns", attributes)
237
- end
238
-
239
- def update_campaign(id, attributes = {})
240
- put("/v3/#{escape @domain}/campaigns/#{escape id}", attributes)
241
- end
242
-
243
- def delete_campaign(id)
244
- delete("/v3/#{escape @domain}/campaigns/#{escape id}")
245
- end
246
-
247
- def get_campaign_events(campaign_id, params = {})
248
- get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/events", params)
249
- end
250
-
251
- def get_campaign_stats(campaign_id, params = {})
252
- get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/stats", params)
253
- end
254
-
255
- def get_campaign_clicks(campaign_id, params = {})
256
- get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/clicks", params)
257
- end
258
-
259
- def get_campaign_opens(campaign_id, params = {})
260
- get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/opens", params)
261
- end
262
-
263
- def get_campaign_unsubscribes(campaign_id, params = {})
264
- get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/unsubscribes", params)
265
- end
266
-
267
- def get_campaign_complaints(campaign_id, params = {})
268
- get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/complaints", params)
269
- end
270
-
271
- def get_lists(params = {})
272
- get('/v3/lists', params)
273
- end
274
-
275
- def get_list(address)
276
- get("/v3/lists/#{escape address}")
277
- end
278
-
279
- def add_list(attributes = {})
280
- post('/v3/lists', attributes)
281
- end
282
-
283
- def update_list(address, attributes = {})
284
- put("/v3/lists/#{escape address}", attributes)
285
- end
286
-
287
- def delete_list(address)
288
- delete("/v3/lists/#{escape address}")
289
- end
290
-
291
- def get_list_members(list_address, params = {})
292
- get("/v3/lists/#{escape list_address}/members", params)
293
- end
294
-
295
- def get_list_member(list_address, member_address)
296
- get("/v3/lists/#{escape list_address}/members/#{escape member_address}")
297
- end
298
-
299
- def add_list_member(list_address, member_attributes)
300
- post("/v3/lists/#{escape list_address}/members", member_attributes)
301
- end
302
-
303
- def update_list_member(list_address, member_address, member_attributes)
304
- put("/v3/lists/#{escape list_address}/members/#{escape member_address}", member_attributes)
305
- end
306
-
307
- def delete_list_member(list_address, member_address)
308
- delete("/v3/lists/#{escape list_address}/members/#{escape member_address}")
309
- end
310
-
311
- private
312
-
313
- def get(path, params = {}, headers = {})
314
- request = Net::HTTP::Get.new(request_uri(path, params))
315
-
316
- headers.each { |k, v| request[k] = v }
317
-
318
- transmit(request)
319
- end
320
-
321
- def post(path, attributes = {})
322
- transmit(Net::HTTP::Post.new(path)) { |message| message.set_form_data(attributes) }
323
- end
324
-
325
- def multipart_post(path, data)
326
- transmit(Net::HTTP::Post.new(path)) { |message| message.set_form(data, 'multipart/form-data') }
327
- end
328
-
329
- def put(path, attributes = {})
330
- transmit(Net::HTTP::Put.new(path)) { |message| message.set_form_data(attributes) }
331
- end
332
-
333
- def delete(path)
334
- transmit(Net::HTTP::Delete.new(path))
335
- end
336
-
337
- USER_AGENT = "Ruby/#{RUBY_VERSION} Mailgunner/#{VERSION}"
338
-
339
- def transmit(message)
340
- message.basic_auth('api', @api_key)
341
- message['User-Agent'] = USER_AGENT
342
-
343
- yield message if block_given?
344
-
345
- parse(@http.request(message))
346
- end
347
-
348
- def parse(response)
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}"
358
- else
359
- raise Error, "HTTP #{response.code}"
360
- end
361
- end
362
-
363
- def parse_success(response)
364
- return JSON.parse(response.body) if json?(response)
365
-
366
- response.body
367
- end
368
-
369
- def json?(response)
370
- content_type = response['Content-Type']
371
-
372
- content_type && content_type.split(';').first == 'application/json'
373
- end
374
-
375
- def request_uri(path, params)
376
- return path if params.empty?
377
-
378
- path + '?' + params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
379
- end
380
-
381
- def escape(component)
382
- CGI.escape(component.to_s)
383
- end
384
- end
385
- end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'cgi'
5
+
6
+ module Mailgunner
7
+ class Client
8
+ attr_accessor :domain, :api_key, :http
9
+
10
+ def initialize(options = {})
11
+ @domain = options.fetch(:domain) { default_domain }
12
+
13
+ @api_key = options.fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') }
14
+
15
+ @api_host = options.fetch(:api_host) { 'api.mailgun.net' }
16
+
17
+ @http = Net::HTTP.new(@api_host, Net::HTTP.https_default_port)
18
+
19
+ @http.use_ssl = true
20
+ end
21
+
22
+ private
23
+
24
+ def default_domain
25
+ return NoDomainProvided unless ENV.key?('MAILGUN_SMTP_LOGIN')
26
+
27
+ ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last
28
+ end
29
+
30
+ def get(path, params = {}, headers = {})
31
+ request = Net::HTTP::Get.new(request_uri(path, params))
32
+
33
+ headers.each { |k, v| request[k] = v }
34
+
35
+ transmit(request)
36
+ end
37
+
38
+ def post(path, attributes = {})
39
+ transmit(Net::HTTP::Post.new(path)) { |message| message.set_form_data(attributes) }
40
+ end
41
+
42
+ def multipart_post(path, data)
43
+ transmit(Net::HTTP::Post.new(path)) { |message| message.set_form(data, 'multipart/form-data') }
44
+ end
45
+
46
+ def put(path, attributes = {})
47
+ transmit(Net::HTTP::Put.new(path)) { |message| message.set_form_data(attributes) }
48
+ end
49
+
50
+ def delete(path)
51
+ transmit(Net::HTTP::Delete.new(path))
52
+ end
53
+
54
+ USER_AGENT = "Ruby/#{RUBY_VERSION} Mailgunner/#{VERSION}"
55
+
56
+ def transmit(message)
57
+ message.basic_auth('api', @api_key)
58
+ message['User-Agent'] = USER_AGENT
59
+
60
+ yield message if block_given?
61
+
62
+ parse(@http.request(message))
63
+ end
64
+
65
+ def parse(response)
66
+ case response
67
+ when Net::HTTPSuccess
68
+ parse_success(response)
69
+ when Net::HTTPUnauthorized
70
+ raise AuthenticationError, "HTTP #{response.code}"
71
+ when Net::HTTPClientError
72
+ raise ClientError, "HTTP #{response.code}"
73
+ when Net::HTTPServerError
74
+ raise ServerError, "HTTP #{response.code}"
75
+ else
76
+ raise Error, "HTTP #{response.code}"
77
+ end
78
+ end
79
+
80
+ def parse_success(response)
81
+ return JSON.parse(response.body) if json?(response)
82
+
83
+ response.body
84
+ end
85
+
86
+ def json?(response)
87
+ content_type = response['Content-Type']
88
+
89
+ content_type && content_type.split(';').first == 'application/json'
90
+ end
91
+
92
+ def request_uri(path, params)
93
+ return path if params.empty?
94
+
95
+ path + '?' + params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
96
+ end
97
+
98
+ def escape(component)
99
+ CGI.escape(component.to_s)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_domains(params = {})
6
+ get('/v3/domains', params)
7
+ end
8
+
9
+ def get_domain(name)
10
+ get("/v3/domains/#{escape name}")
11
+ end
12
+
13
+ def add_domain(attributes = {})
14
+ post('/v3/domains', attributes)
15
+ end
16
+
17
+ def delete_domain(name)
18
+ delete("/v3/domains/#{escape name}")
19
+ end
20
+
21
+ def get_credentials
22
+ get("/v3/domains/#{escape @domain}/credentials")
23
+ end
24
+
25
+ def add_credentials(attributes)
26
+ post("/v3/domains/#{escape @domain}/credentials", attributes)
27
+ end
28
+
29
+ def update_credentials(login, attributes)
30
+ put("/v3/domains/#{escape @domain}/credentials/#{escape login}", attributes)
31
+ end
32
+
33
+ def delete_credentials(login)
34
+ delete("/v3/domains/#{escape @domain}/credentials/#{escape login}")
35
+ end
36
+
37
+ def get_connection_settings
38
+ get("/v3/domains/#{escape @domain}/connection")
39
+ end
40
+
41
+ def update_connection_settings(attributes)
42
+ put("/v3/domains/#{escape @domain}/connection", attributes)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def validate_address(value)
6
+ get('/v3/address/validate', address: value)
7
+ end
8
+
9
+ def parse_addresses(values)
10
+ get('/v3/address/parse', addresses: Array(values).join(','))
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_events(params = {})
6
+ get("/v3/#{escape @domain}/events", params)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_all_ips(params = {})
6
+ get('/v3/ips', params)
7
+ end
8
+
9
+ def get_ip(address)
10
+ get("/v3/ips/#{escape address}")
11
+ end
12
+
13
+ def get_ips
14
+ get("/v3/domains/#{escape @domain}/ips")
15
+ end
16
+
17
+ def add_ip(address)
18
+ post("/v3/domains/#{escape @domain}/ips", ip: address)
19
+ end
20
+
21
+ def delete_ip(address)
22
+ delete("/v3/domains/#{escape @domain}/ips/#{escape address}")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_lists(params = {})
6
+ get('/v3/lists', params)
7
+ end
8
+
9
+ def get_list(address)
10
+ get("/v3/lists/#{escape address}")
11
+ end
12
+
13
+ def add_list(attributes = {})
14
+ post('/v3/lists', attributes)
15
+ end
16
+
17
+ def update_list(address, attributes = {})
18
+ put("/v3/lists/#{escape address}", attributes)
19
+ end
20
+
21
+ def delete_list(address)
22
+ delete("/v3/lists/#{escape address}")
23
+ end
24
+
25
+ def get_list_members(list_address, params = {})
26
+ get("/v3/lists/#{escape list_address}/members", params)
27
+ end
28
+
29
+ def get_list_member(list_address, member_address)
30
+ get("/v3/lists/#{escape list_address}/members/#{escape member_address}")
31
+ end
32
+
33
+ def add_list_member(list_address, member_attributes)
34
+ post("/v3/lists/#{escape list_address}/members", member_attributes)
35
+ end
36
+
37
+ def update_list_member(list_address, member_address, member_attributes)
38
+ put("/v3/lists/#{escape list_address}/members/#{escape member_address}", member_attributes)
39
+ end
40
+
41
+ def delete_list_member(list_address, member_address)
42
+ delete("/v3/lists/#{escape list_address}/members/#{escape member_address}")
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_message(key)
6
+ get("/v3/domains/#{escape @domain}/messages/#{escape key}")
7
+ end
8
+
9
+ def get_mime_message(key)
10
+ get("/v3/domains/#{escape @domain}/messages/#{escape key}", {}, {'Accept' => 'message/rfc2822'})
11
+ end
12
+
13
+ def send_message(attributes = {})
14
+ post("/v3/#{escape @domain}/messages", attributes)
15
+ end
16
+
17
+ def send_mime(mail)
18
+ to = ['to', Array(mail.destinations).join(',')]
19
+
20
+ message = ['message', mail.encoded, {filename: 'message.mime'}]
21
+
22
+ multipart_post("/v3/#{escape @domain}/messages.mime", [to, message])
23
+ end
24
+
25
+ def delete_message(key)
26
+ delete("/v3/domains/#{escape @domain}/messages/#{escape key}")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_routes(params = {})
6
+ get('/v3/routes', params)
7
+ end
8
+
9
+ def get_route(id)
10
+ get("/v3/routes/#{escape id}")
11
+ end
12
+
13
+ def add_route(attributes = {})
14
+ post('/v3/routes', attributes)
15
+ end
16
+
17
+ def update_route(id, attributes = {})
18
+ put("/v3/routes/#{escape id}", attributes)
19
+ end
20
+
21
+ def delete_route(id)
22
+ delete("/v3/routes/#{escape id}")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_stats(params = {})
6
+ Kernel.warn 'Mailgunner::Client#get_stats is deprecated'
7
+
8
+ get("/v3/#{escape @domain}/stats", params)
9
+ end
10
+
11
+ def get_total_stats(params = {})
12
+ get("/v3/#{escape @domain}/stats/total", params)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_bounces(params = {})
6
+ get("/v3/#{escape @domain}/bounces", params)
7
+ end
8
+
9
+ def get_bounce(address)
10
+ get("/v3/#{escape @domain}/bounces/#{escape address}")
11
+ end
12
+
13
+ def add_bounce(attributes = {})
14
+ post("/v3/#{escape @domain}/bounces", attributes)
15
+ end
16
+
17
+ def delete_bounce(address)
18
+ delete("/v3/#{escape @domain}/bounces/#{escape address}")
19
+ end
20
+
21
+ def delete_bounces
22
+ delete("/v3/#{escape @domain}/bounces")
23
+ end
24
+
25
+ def get_unsubscribes(params = {})
26
+ get("/v3/#{escape @domain}/unsubscribes", params)
27
+ end
28
+
29
+ def get_unsubscribe(address)
30
+ get("/v3/#{escape @domain}/unsubscribes/#{escape address}")
31
+ end
32
+
33
+ def delete_unsubscribe(address_or_id)
34
+ delete("/v3/#{escape @domain}/unsubscribes/#{escape address_or_id}")
35
+ end
36
+
37
+ def add_unsubscribe(attributes = {})
38
+ post("/v3/#{escape @domain}/unsubscribes", attributes)
39
+ end
40
+
41
+ def get_complaints(params = {})
42
+ get("/v3/#{escape @domain}/complaints", params)
43
+ end
44
+
45
+ def get_complaint(address)
46
+ get("/v3/#{escape @domain}/complaints/#{escape address}")
47
+ end
48
+
49
+ def add_complaint(attributes = {})
50
+ post("/v3/#{escape @domain}/complaints", attributes)
51
+ end
52
+
53
+ def delete_complaint(address)
54
+ delete("/v3/#{escape @domain}/complaints/#{escape address}")
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_tags(params = {})
6
+ get("/v3/#{escape @domain}/tags", params)
7
+ end
8
+
9
+ def get_tag(id)
10
+ get("/v3/#{escape @domain}/tags/#{escape id}")
11
+ end
12
+
13
+ def update_tag(id, attributes)
14
+ put("/v3/#{escape @domain}/tags/#{escape id}", attributes)
15
+ end
16
+
17
+ def get_tag_stats(id, params)
18
+ get("/v3/#{escape @domain}/tags/#{escape id}/stats", params)
19
+ end
20
+
21
+ def delete_tag(id)
22
+ delete("/v3/#{escape @domain}/tags/#{escape id}")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailgunner
4
+ class Client
5
+ def get_webhooks
6
+ get("/v3/domains/#{escape @domain}/webhooks")
7
+ end
8
+
9
+ def get_webhook(id)
10
+ get("/v3/domains/#{escape @domain}/webhooks/#{escape id}")
11
+ end
12
+
13
+ def add_webhook(attributes = {})
14
+ post("/v3/domains/#{escape @domain}/webhooks", attributes)
15
+ end
16
+
17
+ def update_webhook(id, attributes = {})
18
+ put("/v3/domains/#{escape @domain}/webhooks/#{escape id}", attributes)
19
+ end
20
+
21
+ def delete_webhook(id)
22
+ delete("/v3/domains/#{escape @domain}/webhooks/#{escape id}")
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Mailgunner
2
- VERSION = '2.5.0'
2
+ VERSION = '2.6.0'
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Tim Craft']
9
9
  s.email = ['mail@timcraft.com']
10
- s.homepage = 'http://github.com/timcraft/mailgunner'
10
+ s.homepage = 'http://github.com/readysteady/mailgunner'
11
11
  s.description = 'Ruby client for the Mailgun API'
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)
@@ -18,4 +18,10 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency('actionmailer', '~> 5')
19
19
  s.add_development_dependency('mocha', '~> 1')
20
20
  s.require_path = 'lib'
21
+ s.metadata = {
22
+ 'homepage' => 'https://github.com/readysteady/mailgunner',
23
+ 'source_code_uri' => 'https://github.com/readysteady/mailgunner',
24
+ 'bug_tracker_uri' => 'https://github.com/readysteady/mailgunner/issues',
25
+ 'changelog_uri' => 'https://github.com/readysteady/mailgunner/blob/master/CHANGES.md'
26
+ }
21
27
  end
@@ -41,11 +41,23 @@ describe 'Mailgunner::Client' do
41
41
  end
42
42
 
43
43
  describe 'http method' do
44
- it 'returns a net http object that uses ssl' do
44
+ it 'returns a net http object' do
45
45
  @client.http.must_be_instance_of(Net::HTTP)
46
+ end
47
+ end
46
48
 
49
+ describe 'http object' do
50
+ it 'uses ssl' do
47
51
  @client.http.use_ssl?.must_equal(true)
48
52
  end
53
+
54
+ it 'uses the address from the api_host option' do
55
+ api_host = 'api.eu.mailgun.net'
56
+
57
+ @client = Mailgunner::Client.new(api_key: @api_key, api_host: api_host)
58
+
59
+ @client.http.address.must_equal(api_host)
60
+ end
49
61
  end
50
62
 
51
63
  describe 'domain method' do
@@ -577,133 +589,49 @@ describe 'Mailgunner::Client' do
577
589
  end
578
590
  end
579
591
 
580
- describe 'get_campaigns method' do
581
- it 'fetches the domain campaigns resource and returns the response object' do
582
- stub(:get, "#@base_url/#@domain/campaigns")
592
+ describe 'get_all_ips method' do
593
+ it 'fetches the ips resource and returns the response object' do
594
+ stub(:get, "#@base_url/ips")
583
595
 
584
- @client.get_campaigns.must_equal(@json_response_object)
585
- end
586
-
587
- it 'encodes skip and limit parameters' do
588
- stub(:get, "#@base_url/#@domain/campaigns?skip=1&limit=2")
589
-
590
- @client.get_campaigns(skip: 1, limit: 2)
596
+ @client.get_all_ips.must_equal(@json_response_object)
591
597
  end
592
598
  end
593
599
 
594
- describe 'get_campaign method' do
595
- it 'fetches the campaign resource with the given id and returns the response object' do
596
- stub(:get, "#@base_url/#@domain/campaigns/#@id")
597
-
598
- @client.get_campaign(@id).must_equal(@json_response_object)
599
- end
600
- end
600
+ describe 'get_ip method' do
601
+ it 'fetches the ip resource with the given address and returns the response object' do
602
+ address = '127.0.0.1'
601
603
 
602
- describe 'add_campaign method' do
603
- it 'posts to the domain campaigns resource and returns the response object' do
604
- stub(:post, "#@base_url/#@domain/campaigns", body: "id=#@id")
604
+ stub(:get, "#@base_url/ips/#{address}")
605
605
 
606
- @client.add_campaign({id: @id}).must_equal(@json_response_object)
606
+ @client.get_ip(address).must_equal(@json_response_object)
607
607
  end
608
608
  end
609
609
 
610
- describe 'update_campaign method' do
611
- it 'updates the campaign resource and returns the response object' do
612
- stub(:put, "#@base_url/#@domain/campaigns/#@id", body: 'name=Example+Campaign')
610
+ describe 'get_ips method' do
611
+ it 'fetches the domain ips resource and returns the response object' do
612
+ stub(:get, "#@base_url/domains/#@domain/ips")
613
613
 
614
- @client.update_campaign(@id, {name: 'Example Campaign'}).must_equal(@json_response_object)
614
+ @client.get_ips.must_equal(@json_response_object)
615
615
  end
616
616
  end
617
617
 
618
- describe 'delete_campaign method' do
619
- it 'deletes the domain campaign resource with the given id and returns the response object' do
620
- stub(:delete, "#@base_url/#@domain/campaigns/#@id")
618
+ describe 'add_ip method' do
619
+ it 'posts to the domain ips resource and returns the response object' do
620
+ address = '127.0.0.1'
621
621
 
622
- @client.delete_campaign(@id).must_equal(@json_response_object)
623
- end
624
- end
625
-
626
- describe 'get_campaign_events method' do
627
- it 'fetches the domain campaign events resource and returns the response object' do
628
- stub(:get, "#@base_url/#@domain/campaigns/#@id/events")
629
-
630
- @client.get_campaign_events(@id).must_equal(@json_response_object)
631
- end
632
-
633
- it 'encodes the optional parameters' do
634
- stub(:get, "#@base_url/#@domain/campaigns/#@id/events?country=US&limit=100")
622
+ stub(:post, "#@base_url/domains/#@domain/ips", body: {ip: address})
635
623
 
636
- @client.get_campaign_events(@id, country: 'US', limit: 100)
624
+ @client.add_ip(address).must_equal(@json_response_object)
637
625
  end
638
626
  end
639
627
 
640
- describe 'get_campaign_stats method' do
641
- it 'fetches the domain campaign stats resource and returns the response object' do
642
- stub(:get, "#@base_url/#@domain/campaigns/#@id/stats")
643
-
644
- @client.get_campaign_stats(@id).must_equal(@json_response_object)
645
- end
646
-
647
- it 'encodes the optional parameters' do
648
- stub(:get, "#@base_url/#@domain/campaigns/#@id/stats?groupby=dailyhour")
649
-
650
- @client.get_campaign_stats(@id, groupby: 'dailyhour')
651
- end
652
- end
653
-
654
- describe 'get_campaign_clicks method' do
655
- it 'fetches the domain campaign clicks resource and returns the response object' do
656
- stub(:get, "#@base_url/#@domain/campaigns/#@id/clicks")
657
-
658
- @client.get_campaign_clicks(@id).must_equal(@json_response_object)
659
- end
660
-
661
- it 'encodes the optional parameters' do
662
- stub(:get, "#@base_url/#@domain/campaigns/#@id/clicks?groupby=month&limit=100")
663
-
664
- @client.get_campaign_clicks(@id, groupby: 'month', limit: 100)
665
- end
666
- end
667
-
668
- describe 'get_campaign_opens method' do
669
- it 'fetches the domain campaign opens resource and returns the response object' do
670
- stub(:get, "#@base_url/#@domain/campaigns/#@id/opens")
671
-
672
- @client.get_campaign_opens(@id).must_equal(@json_response_object)
673
- end
674
-
675
- it 'encodes the optional parameters' do
676
- stub(:get, "#@base_url/#@domain/campaigns/#@id/opens?groupby=month&limit=100")
677
-
678
- @client.get_campaign_opens(@id, groupby: 'month', limit: 100)
679
- end
680
- end
681
-
682
- describe 'get_campaign_unsubscribes method' do
683
- it 'fetches the domain campaign unsubscribes resource and returns the response object' do
684
- stub(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes")
685
-
686
- @client.get_campaign_unsubscribes(@id).must_equal(@json_response_object)
687
- end
688
-
689
- it 'encodes the optional parameters' do
690
- stub(:get, "#@base_url/#@domain/campaigns/#@id/unsubscribes?groupby=month&limit=100")
691
-
692
- @client.get_campaign_unsubscribes(@id, groupby: 'month', limit: 100)
693
- end
694
- end
695
-
696
- describe 'get_campaign_complaints method' do
697
- it 'fetches the domain campaign complaints resource and returns the response object' do
698
- stub(:get, "#@base_url/#@domain/campaigns/#@id/complaints")
699
-
700
- @client.get_campaign_complaints(@id).must_equal(@json_response_object)
701
- end
628
+ describe 'delete_ip method' do
629
+ it 'deletes the domain ip resource with the given address and returns the response object' do
630
+ address = '127.0.0.1'
702
631
 
703
- it 'encodes the optional parameters' do
704
- stub(:get, "#@base_url/#@domain/campaigns/#@id/complaints?groupby=month&limit=100")
632
+ stub(:delete, "#@base_url/domains/#@domain/ips/#{address}")
705
633
 
706
- @client.get_campaign_complaints(@id, groupby: 'month', limit: 100)
634
+ @client.delete_ip(address).must_equal(@json_response_object)
707
635
  end
708
636
  end
709
637
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.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: 2018-01-05 00:00:00.000000000 Z
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -90,6 +90,18 @@ files:
90
90
  - LICENSE.txt
91
91
  - README.md
92
92
  - lib/mailgunner.rb
93
+ - lib/mailgunner/client.rb
94
+ - lib/mailgunner/client/domains.rb
95
+ - lib/mailgunner/client/email_validation.rb
96
+ - lib/mailgunner/client/events.rb
97
+ - lib/mailgunner/client/ips.rb
98
+ - lib/mailgunner/client/mailing_lists.rb
99
+ - lib/mailgunner/client/messages.rb
100
+ - lib/mailgunner/client/routes.rb
101
+ - lib/mailgunner/client/stats.rb
102
+ - lib/mailgunner/client/suppressions.rb
103
+ - lib/mailgunner/client/tags.rb
104
+ - lib/mailgunner/client/webhooks.rb
93
105
  - lib/mailgunner/delivery_method.rb
94
106
  - lib/mailgunner/errors.rb
95
107
  - lib/mailgunner/railtie.rb
@@ -97,10 +109,14 @@ files:
97
109
  - mailgunner.gemspec
98
110
  - spec/mailgunner_delivery_method_spec.rb
99
111
  - spec/mailgunner_spec.rb
100
- homepage: http://github.com/timcraft/mailgunner
112
+ homepage: http://github.com/readysteady/mailgunner
101
113
  licenses:
102
114
  - LGPL-3.0
103
- metadata: {}
115
+ metadata:
116
+ homepage: https://github.com/readysteady/mailgunner
117
+ source_code_uri: https://github.com/readysteady/mailgunner
118
+ bug_tracker_uri: https://github.com/readysteady/mailgunner/issues
119
+ changelog_uri: https://github.com/readysteady/mailgunner/blob/master/CHANGES.md
104
120
  post_install_message:
105
121
  rdoc_options: []
106
122
  require_paths:
@@ -117,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
133
  version: '0'
118
134
  requirements: []
119
135
  rubyforge_project:
120
- rubygems_version: 2.6.13
136
+ rubygems_version: 2.7.6
121
137
  signing_key:
122
138
  specification_version: 4
123
139
  summary: Ruby client for the Mailgun API