mailgunner 2.5.0 → 3.2.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: 0c41e367b2b2934d3507be230520c72cb62feb57b03c91f1cb6c593578c88956
4
+ data.tar.gz: 4a08ca142232d72e11208051711f3a8f9abd437f0e29c99104d3a5d9c8745995
5
5
  SHA512:
6
- metadata.gz: 2b4c452b40c78d8d569efdc93ce24d0980616546e69fedde804721331ff47d536f93ceba3341c6f0ff7854a4a7957979e21121ba766980f29d01a876f2a0a5d5
7
- data.tar.gz: 6e531aa0c226284e539f5e5b9128e30ef9c3fcd21da511dbacc95ec2c8c8b6ebe0ec41ef2d60469a2510a5b10355a3a91b17ce3c73a1842d10a79acb1fd441ae
6
+ metadata.gz: e16b51a2710153ce19414399bc2fa5cb147a9c2eba7b1daed4e9b4768727ce0a091f1ed6874055640d71f41ff8c5225d77fddcf781b7d136954d193d31adeae2
7
+ data.tar.gz: e93e0cf4f5f2ef7879a6fe1bfd62fc8c5280e84e60a707c4c489b21ce3c09e06b37a9b1269a85827037575e9ef18e85f4915a89e2080ee03b130c6f52630b31f
@@ -0,0 +1,214 @@
1
+ # 3.2.0
2
+
3
+ * Added update_web_prefix method
4
+
5
+ * Added update_dkim_selector method
6
+
7
+ * Added update_dkim_authority method
8
+
9
+ * Added verify_domain method (#23)
10
+
11
+ # 3.1.1
12
+
13
+ * Fixed missing keyword argument in Mailgunner::Client#get_whitelists method
14
+
15
+ * Fixed last argument as keyword parameters deprecation warning on Ruby 2.7
16
+
17
+ # 3.1.0
18
+
19
+ * Allow delivery method settings to be modified before delivery (#22)
20
+
21
+ # 3.0.0
22
+
23
+ * Changed required_ruby_version to >= 2.5.0
24
+
25
+ * Added Mailgunner::Config class
26
+
27
+ You can now configure options globally. For example:
28
+
29
+ Mailgunner.configure do |config|
30
+ config.api_host = 'api.eu.mailgun.net'
31
+ end
32
+
33
+ This may or may not be a breaking change, depending on how you are currently initializing client objects.
34
+
35
+ * Added Mailgunner::Struct class
36
+
37
+ Return values are now instances of the Mailgunner::Struct class. You can access nested keys in various ways:
38
+
39
+ response.items
40
+ response['items']
41
+ response[:items]
42
+ response.to_h.dig('items')
43
+
44
+ This may or may not be a breaking change, depending on how you are currently using return values.
45
+
46
+ * Added parsing of error messages in response bodies
47
+
48
+ * Removed Mailgunner::Client#get_stats method
49
+
50
+ * Removed Mailgunner::Client#parse_addresses method
51
+
52
+ * Changed Mailgunner::Client#validate_address to v4 endpoint
53
+
54
+ * Changed Mailgunner::Client#get_lists method to new endpoint
55
+
56
+ * Changed Mailgunner::Client#get_list_members method to new endpoint
57
+
58
+ * Added Mailgunner::Client#get_bulk_validations method
59
+
60
+ * Added Mailgunner::Client#create_bulk_validation method
61
+
62
+ * Added Mailgunner::Client#get_bulk_validation method
63
+
64
+ * Added Mailgunner::Client#cancel_bulk_validation method
65
+
66
+ * Added Mailgunner::Client#get_whitelists method
67
+
68
+ * Added Mailgunner::Client#get_whitelist method
69
+
70
+ * Added Mailgunner::Client#add_whitelist method
71
+
72
+ * Added Mailgunner::Client#delete_whitelist method
73
+
74
+ * Added Mailgunner::Client#get_tracking_settings method
75
+
76
+ * Added Mailgunner::Client#update_open_tracking_settings method
77
+
78
+ * Added Mailgunner::Client#update_click_tracking_settings method
79
+
80
+ * Added Mailgunner::Client#update_unsubscribe_tracking_settings method
81
+
82
+ # 2.6.0
83
+
84
+ * Added `api_host` option for EU region (thanks @drummerroma and @markoudev)
85
+
86
+ * Added Mailgunner::Client#get_all_ips method
87
+
88
+ * Added Mailgunner::Client#get_ip method
89
+
90
+ * Added Mailgunner::Client#get_ips method
91
+
92
+ * Added Mailgunner::Client#add_ip method
93
+
94
+ * Added Mailgunner::Client#delete_ip method
95
+
96
+ * Removed legacy campaign methods
97
+
98
+ # 2.5.0
99
+
100
+ * Fixed compatibility with mail v2.6.6+ (#13)
101
+
102
+ * Added Mailgunner::Client#get_webhooks method
103
+
104
+ * Added Mailgunner::Client#get_webhook method
105
+
106
+ * Added Mailgunner::Client#add_webhook method
107
+
108
+ * Added Mailgunner::Client#update_webhook method
109
+
110
+ * Added Mailgunner::Client#delete_webhook method
111
+
112
+ * Added Mailgun::AuthenticationError exception class
113
+
114
+ * Added Mailgun::ClientError exception class
115
+
116
+ * Added Mailgun::ServerError exception class
117
+
118
+ # 2.4.0
119
+
120
+ * Fixed Rails load order issue when specifying mailgun_settings (#10)
121
+
122
+ * Added Mailgunner::Client#get_connection_settings method
123
+
124
+ * Added Mailgunner::Client#update_connection_settings method
125
+
126
+ * Added Mailgunner::Client#get_tags method
127
+
128
+ * Added Mailgunner::Client#get_tag method
129
+
130
+ * Added Mailgunner::Client#update_tag method
131
+
132
+ * Added Mailgunner::Client#get_tag_stats method
133
+
134
+ * Added Mailgunner::Client#delete_tag method
135
+
136
+ * Added Mailgunner::Client#delete_bounces method
137
+
138
+ # 2.3.0
139
+
140
+ * Added Mailgunner::Client#get_total_stats method
141
+
142
+ * Deprecated Mailgunner::Client#get_stats method
143
+
144
+ * Removed Mailgunner::Client#get_list_stats method
145
+
146
+ # 2.2.2
147
+
148
+ * Fixed cc and bcc recipients not included in multipart sends (#9)
149
+
150
+ # 2.2.1
151
+
152
+ * Fixed Rails load order issue (#8)
153
+
154
+ # 2.2.0
155
+
156
+ * Added Mailgunner::Client#get_message method
157
+
158
+ * Added Mailgunner::Client#get_mime_message method
159
+
160
+ * Added Mailgunner::Client#delete_message method
161
+
162
+ * Updated API version prefix from v2 to v3
163
+
164
+ # 2.1.0
165
+
166
+ * Mailgunner::DeliveryMethod can now be used with Mail directly
167
+
168
+ * An exception is now raised when calling domain methods if the domain is not provided
169
+
170
+ * The api_key option can now be specified in ActionMailer::Base.mailgun_settings
171
+
172
+ # 2.0.0
173
+
174
+ * Removed deprecated :json option
175
+
176
+ * Removed Mailgunner::Response class in favour of using exceptions to signal errors
177
+
178
+ * Added Mailgunner::Client#delete_domain method
179
+
180
+ * Added Mailgunner::Client methods for managing SMTP credentials
181
+
182
+ # 1.3.0
183
+
184
+ * Added [ActionMailer](https://rubygems.org/gems/actionmailer) integration
185
+
186
+ * Added Mailgunner::Client#send_mime method for sending [mail](https://rubygems.org/gems/mail) objects in MIME format
187
+
188
+ * Fixed default behaviour to allow for nil domain
189
+
190
+ * Removed deprecated Mailgunner::Client#get_log method
191
+
192
+ * Removed deprecated mailbox methods
193
+
194
+ * Removed deprecated json accessor methods
195
+
196
+ # 1.2.0
197
+
198
+ * Added methods for the new [Email Validation endpoint](http://documentation.mailgun.com/api-email-validation.html)
199
+
200
+ * Added Mailgunner::Client#get_events method for the new [Events API endpoint](http://documentation.mailgun.com/api-events.html)
201
+
202
+ * Deprecated the Mailgunner::Client#get_log method (use Mailgunner::Client#get_events instead)
203
+
204
+ # 1.1.0
205
+
206
+ * Fixed use of insecure JSON.load
207
+
208
+ * Deprecated the mailbox methods (legacy Mailgun feature)
209
+
210
+ * Deprecated the :json option and associated accessor methods
211
+
212
+ # 1.0.0
213
+
214
+ * First version!
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2018 TIMCRAFT
1
+ Copyright (c) 2012-2020 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.
data/README.md CHANGED
@@ -1,9 +1,10 @@
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)
4
+ ![Build Status](https://github.com/readysteady/mailgunner/workflows/Test/badge.svg)
4
5
 
5
6
 
6
- Ruby client for the [Mailgun API](http://documentation.mailgun.net/api_reference.html).
7
+ Ruby client for the [Mailgun API](https://documentation.mailgun.com/en/latest/api_reference.html).
7
8
 
8
9
 
9
10
  ## Installation
@@ -11,26 +12,29 @@ Ruby client for the [Mailgun API](http://documentation.mailgun.net/api_reference
11
12
  $ gem install mailgunner
12
13
 
13
14
 
14
- ## Quick start
15
+ ## Usage
15
16
 
16
17
  ```ruby
17
18
  require 'mailgunner'
18
19
 
19
- mailgun = Mailgunner::Client.new({
20
- domain: 'samples.mailgun.org',
21
- api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'
22
- })
20
+ Mailgunner.configure do |config|
21
+ config.domain = 'samples.mailgun.org'
22
+ config.api_key = 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'
23
+ end
23
24
 
24
- response = mailgun.get_stats(limit: 5)
25
+ mailgun = Mailgunner::Client.new
26
+
27
+ mailgun.get_domains.items.each do |item|
28
+ puts "#{item.id} #{item.name}"
29
+ end
25
30
  ```
26
31
 
27
32
 
28
33
  ## Storing the API key
29
34
 
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
35
+ Best practice for credentials is to [store them in the environment](https://www.12factor.net/config#store_config_in_the_environment).
36
+ `Mailgunner::Client` defaults to extracting the domain and api_key values it needs
37
+ from the `MAILGUN_API_KEY` and `MAILGUN_SMTP_LOGIN` environment variables—these will
34
38
  exist if you are using Mailgun on Heroku, or you can set them manually.
35
39
 
36
40
 
@@ -42,33 +46,29 @@ the following line to `config/environments/production.rb`:
42
46
 
43
47
  ```ruby
44
48
  config.action_mailer.delivery_method = :mailgun
45
- ````
49
+ ```
46
50
 
47
51
  If for some reason you can't set the required ENV variables, you can configure Mailgunner
48
52
  through ActionMailer settings:
49
53
 
50
54
  ```ruby
51
55
  config.action_mailer.mailgun_settings = {
52
- domain: 'test.com'
56
+ domain: 'test.com',
53
57
  api_key: 'your-api-key'
54
58
  }
55
-
56
59
  ```
57
60
 
58
61
  Outside of Rails you can set `ActionMailer::Base.delivery_method` directly.
59
62
 
60
63
 
61
- ## Email validation
64
+ ## Specifying the region
62
65
 
63
- If you only need to use Mailgun's [email address validation service](http://documentation.mailgun.com/api-email-validation.html),
64
- you can instead use your Mailgun public key to authenticate like this:
66
+ Mailgun offers both a US and EU region to send your email from. Mailgunner uses
67
+ the US region by default. If you wish to use the EU region set the `api_host`
68
+ config option like so:
65
69
 
66
70
  ```ruby
67
- require 'mailgunner'
68
-
69
- public_key = 'pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7'
70
-
71
- mailgun = Mailgunner::Client.new(api_key: public_key)
72
-
73
- response = mailgun.validate_address('john@gmail.com')
71
+ Mailgunner.configure do |config|
72
+ config.api_host = 'api.eu.mailgun.net'
73
+ end
74
74
  ```
@@ -1,385 +1,29 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'cgi'
4
1
  require 'mailgunner/version'
5
2
  require 'mailgunner/errors'
3
+ require 'mailgunner/params'
4
+ require 'mailgunner/config'
5
+ require 'mailgunner/struct'
6
+ require 'mailgunner/client'
7
+ require 'mailgunner/client/domains'
8
+ require 'mailgunner/client/email_validation'
9
+ require 'mailgunner/client/events'
10
+ require 'mailgunner/client/ips'
11
+ require 'mailgunner/client/mailing_lists'
12
+ require 'mailgunner/client/messages'
13
+ require 'mailgunner/client/routes'
14
+ require 'mailgunner/client/stats'
15
+ require 'mailgunner/client/suppressions'
16
+ require 'mailgunner/client/tags'
17
+ require 'mailgunner/client/webhooks'
6
18
  require 'mailgunner/delivery_method' if defined?(Mail)
7
19
  require 'mailgunner/railtie' if defined?(Rails)
8
20
 
9
21
  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
22
+ def self.config
23
+ @config ||= Config.new
24
+ end
380
25
 
381
- def escape(component)
382
- CGI.escape(component.to_s)
383
- end
26
+ def self.configure
27
+ yield config
384
28
  end
385
29
  end