mailgun-ruby 1.3.10 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,9 @@
1
- require 'mailgun/exceptions/exceptions'
2
-
3
1
  module Mailgun
4
2
 
5
3
  # A Mailgun::Domains object is a simple CRUD interface to Mailgun Domains.
6
4
  # Uses Mailgun
7
5
  class Domains
6
+ include ApiVersionChecker
8
7
 
9
8
  # Public: creates a new Mailgun::Domains instance.
10
9
  # Defaults to Mailgun::Client
@@ -12,6 +11,8 @@ module Mailgun
12
11
  @client = client
13
12
  end
14
13
 
14
+ # ==== Core Domains methods ====
15
+
15
16
  # Public: Get Domains
16
17
  #
17
18
  # limit - [Integer] Maximum number of records to return. (100 by default)
@@ -19,37 +20,8 @@ module Mailgun
19
20
  #
20
21
  # Returns [Array] A list of domains (hash)
21
22
  def list(options = {})
22
- warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
23
23
  @client.get('domains', options).to_h['items']
24
24
  end
25
- alias_method :get_domains, :list
26
-
27
- # Public: Get domain information
28
- #
29
- # domain - [String] Domain name to lookup
30
- #
31
- # Returns [Hash] Information on the requested domains.
32
- def info(domain)
33
- warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
34
- fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
35
- @client.get("domains/#{domain}").to_h!
36
- end
37
- alias_method :get, :info
38
- alias_method :get_domain, :info
39
-
40
- # Public: Verify domain, update domain records
41
- # Unknown status - this is not in the current Mailgun API
42
- # Do no rely on this being available in future releases.
43
- #
44
- # domain - [String] Domain name
45
- #
46
- # Returns [Hash] Information on the updated/verified domains
47
- def verify(domain)
48
- warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
49
- fail(ParameterError, 'No domain given to verify on Mailgun', caller) unless domain
50
- @client.put("domains/#{domain}/verify", nil).to_h!
51
- end
52
- alias_method :verify_domain, :verify
53
25
 
54
26
  # Public: Add domain
55
27
  #
@@ -64,27 +36,19 @@ module Mailgun
64
36
  #
65
37
  # Returns [Hash] of created domain
66
38
  def create(domain, options = {})
67
- warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
68
- fail(ParameterError, 'No domain given to add on Mailgun', caller) unless domain
69
39
  options = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge(options)
70
40
  options[:name] = domain
71
41
  @client.post('domains', options).to_h
72
42
  end
73
- alias_method :add, :create
74
- alias_method :add_domain, :create
75
43
 
76
- # Public: Delete Domain
44
+ # Public: Get domain information
77
45
  #
78
- # domain - [String] domain name to delete (ex. domain.com)
46
+ # domain - [String] Domain name to lookup
79
47
  #
80
- # Returns [Boolean] if successful or not
81
- def remove(domain)
82
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
83
- fail(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
84
- @client.delete("domains/#{domain}").to_h['message'] == 'Domain has been deleted'
48
+ # Returns [Hash] Information on the requested domains.
49
+ def get(domain)
50
+ @client.get("domains/#{domain}").to_h!
85
51
  end
86
- alias_method :delete, :remove
87
- alias_method :delete_domain, :remove
88
52
 
89
53
  # Public: Update domain
90
54
  #
@@ -100,115 +64,156 @@ module Mailgun
100
64
  #
101
65
  # Returns [Hash] of updated domain
102
66
  def update(domain, options = {})
103
- warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
104
- fail(ParameterError, 'No domain given to update on Mailgun', caller) unless domain
105
67
  @client.put("domains/#{domain}", options).to_h
106
68
  end
107
69
 
108
- # Public: Creates a new set of SMTP credentials for the defined domain.
70
+
71
+ # Public: Verify domain
109
72
  #
110
- # domain - [String] Name of the domain (ex. domain.com)
73
+ # domain - [String] Domain name
74
+ #
75
+ # Returns [Hash] Information on the updated/verified domains
76
+ def verify(domain)
77
+ @client.put("domains/#{domain}/verify", nil).to_h!
78
+ end
79
+
80
+ # Public: Delete Domain
81
+ #
82
+ # domain - [String] domain name to delete (ex. domain.com)
83
+ #
84
+ # Returns [Boolean] if successful or not
85
+ def remove(domain)
86
+ @client.delete("domains/#{domain}").to_h['message'] == 'Domain has been deleted'
87
+ end
88
+
89
+ # ==== End of Core Domains methods ====
90
+
91
+ # ==== Domain::Keys methods ====
92
+
93
+ # Public: List keys for all domains
94
+ #
95
+
111
96
  # options - [Hash] of
112
- # login - [String] The user name (ex. bob.bar)
113
- # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
97
+ # page - [String] Encoded paging information, provided via 'next', 'previous' links
98
+ # limit - [Integer] Limits the number of items returned in a request
99
+ # signing_domain - [String] Filter by signing domain
100
+ # selector - [String] Filter by selector
114
101
  #
115
102
  # Returns [Hash] with message key
116
- def create_smtp_credentials(domain, options = {})
117
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
118
- fail(ParameterError, 'No domain given to create credentials on Mailgun', caller) unless domain
119
- @client.post("domains/#{domain}/credentials", options).to_h
103
+ def list_domain_keys(options = {})
104
+ @client.get("dkim/keys", options).to_h
120
105
  end
121
106
 
122
- # Public: Updates the specified SMTP credentials.
107
+ # Public: Create a domain key
123
108
  #
124
- # domain - [String] Name of the domain (ex. domain.com)
125
- # login - [String] The user name (ex. bob.bar)
126
109
  # options - [Hash] of
127
- # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
110
+ # signing_domain - [String] Name of the domain (ex. domain.com)
111
+ # selector - [String] Selector to be used for the new domain key
112
+ # bits - [Integer] Key size, can be 1024 or 2048
113
+ # pem - [String] Private key PEM
128
114
  #
129
115
  # Returns [Hash] with message key
130
- def update_smtp_credentials(domain, login, options = {})
131
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
132
- fail(ParameterError, 'No domain given to update credentials on Mailgun', caller) unless domain
133
- fail(ParameterError, 'No login given to update credentials on Mailgun', caller) unless login
134
- @client.put("domains/#{domain}/credentials/#{login}", options).to_h
116
+ def create_domain_key(options = {})
117
+ @client.post("dkim/keys", options).to_h
135
118
  end
136
119
 
137
- # Public: Deletes the defined SMTP credentials.
120
+ # Public: Delete a domain key.
121
+ #
122
+ # options - [Hash] of
123
+ # signing_domain - [Integer] Name of the domain (ex. domain.com)
124
+ # selector - [String] Name of the selector
125
+ #
126
+ # Returns [Hash] with message key
127
+ def delete_domain_key(options = {})
128
+ @client.delete("dkim/keys", options).to_h
129
+ end
130
+
131
+ # Public: Activate a domain key for a specified authority and selector.
132
+ #
133
+ # domain - [String] Name of the domain (ex. domain.com)
134
+ # selector - [String] The selector you want to activate for the domain key
135
+ #
136
+ # Returns [Hash] with message key and autority + selector data
137
+ def activate_domain_key(domain, selector)
138
+ @client.put("domains/#{domain}/keys/#{selector}/activate", {}).to_h
139
+ end
140
+
141
+ # Public: Lists the domain keys for a specified signing domain / authority
138
142
  #
139
143
  # domain - [String] Name of the domain (ex. domain.com)
140
- # login - [String] The user name (ex. bob.bar)
141
144
  #
142
- # Returns [Hash] with message and spec keys
143
- def delete_smtp_credentials(domain, login)
144
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
145
- fail(ParameterError, 'No domain given to delete credentials on Mailgun', caller) unless domain
146
- fail(ParameterError, 'No login given to delete credentials on Mailgun', caller) unless login
147
- @client.delete("domains/#{domain}/credentials/#{login}").to_h
145
+ # Returns [Hash] with domain keys data
146
+ def get_domain_keys(domain)
147
+ @client.get("domains/#{domain}/keys").to_h
148
+ end
149
+
150
+ # Public: Deactivate a domain key for a specified authority and selector
151
+ #
152
+ # domain - [String] Name of the domain (ex. domain.com)
153
+ # selector - [String] The selector you want to activate for the domain key
154
+ #
155
+ # Returns [Hash] with message key and autority + selector data
156
+ def deactivate_domain_key(domain, selector)
157
+ @client.put("domains/#{domain}/keys/#{selector}/deactivate", {}).to_h
148
158
  end
149
159
 
150
- # Public: Returns delivery connection settings for the defined domain.
160
+ # Public: Change the DKIM authority for a domain.
151
161
  #
152
162
  # domain - [String] Name of the domain (ex. domain.com)
163
+ # options - [Hash] of
164
+ # self - [Boolean] true - the domain will be the DKIM authority for itself even
165
+ # if the root domain is registered on the same mailgun account
153
166
  #
154
- # Returns [Hash] Information on the delivery connection settings
155
- def get_domain_connection_settings(domain)
156
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
157
- fail(ParameterError, 'No domain given to retrieve connections on Mailgun', caller) unless domain
158
- @client.get("domains/#{domain}/connection").to_h
167
+ # Returns [Hash] Information on the DKIM authority
168
+ def update_domain_dkim_authority(domain, options = {})
169
+ @client.put("domains/#{domain}/dkim_authority", options).to_h
159
170
  end
160
171
 
161
- # Public: Updates the specified delivery connection settings for the defined domain.d
172
+ # Public: Update the DKIM selector for a domains
162
173
  #
163
174
  # domain - [String] Name of the domain (ex. domain.com)
164
175
  # options - [Hash] of
165
- # require_tls - [Boolean] true or false. If true - requires the message only be sent over a TLS connection
166
- # skip_verification - [Boolean] true or false. If true - the certificate and hostname will not be verified
167
- # when trying to establish a TLS connection
168
- #
169
- # Returns [Hash] Information on the delivery connection settings
170
- def update_domain_connection_settings(domain, options = {})
171
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
172
- fail(ParameterError, 'No domain given to update connections on Mailgun', caller) unless domain
173
- @client.put("domains/#{domain}/connection", options).to_h
176
+ # dkim_selector - [String] change the DKIM selector for a domain.
177
+ #
178
+ # Returns [Hash] with message key
179
+ def update_domain_dkim_selector(domain, options = {})
180
+ @client.put("domains/#{domain}/dkim_selector", options).to_h
174
181
  end
175
182
 
183
+ # ==== End of Domain::Keys methods ====
184
+
185
+ # ==== Domain::Tracking methods ====
186
+
176
187
  # Public: Returns tracking settings for the defined domain.
177
188
  #
178
189
  # domain - [String] Name of the domain (ex. domain.com)
179
190
  #
180
191
  # Returns [Hash] Information on the tracking settings
181
192
  def get_domain_tracking_settings(domain)
182
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
183
- fail(ParameterError, 'No domain given to retrieve tracking settings on Mailgun', caller) unless domain
184
193
  @client.get("domains/#{domain}/tracking").to_h
185
194
  end
186
195
 
187
- # Public: Updates the open tracking settings for a domain.
196
+ # Public: Updates the click tracking settings for a domain.
188
197
  #
189
198
  # domain - [String] Name of the domain (ex. domain.com)
190
199
  # options - [Hash] of
191
- # active - [Boolean] yes or no. If set to yes, a tracking pixel will be inserted below your HTML content.
192
- # place_at_the_top - [Boolean] yes or no. If set to yes, tracking pixel will be moved to top of your HTML content.
200
+ # active - [Boolean] yes or no. If set to yes, links will be overwritten and pointed to our servers so we can track clicks.
193
201
  #
194
- # Returns [Hash] Information on the tracking open settings
195
- def update_domain_tracking_open_settings(domain, options = {})
196
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
197
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
198
- @client.put("domains/#{domain}/tracking/open", options).to_h
202
+ # Returns [Hash] Information on the tracking click settings
203
+ def update_domain_tracking_click_settings(domain, options = {})
204
+ @client.put("domains/#{domain}/tracking/click", options).to_h
199
205
  end
200
206
 
201
- # Public: Updates the click tracking settings for a domain.
207
+ # Public: Updates the open tracking settings for a domain.
202
208
  #
203
209
  # domain - [String] Name of the domain (ex. domain.com)
204
210
  # options - [Hash] of
205
- # active - [Boolean] yes or no. If set to yes, links will be overwritten and pointed to our servers so we can track clicks.
211
+ # active - [Boolean] yes or no. If set to yes, a tracking pixel will be inserted below your HTML content.
212
+ # place_at_the_top - [Boolean] yes or no. If set to yes, tracking pixel will be moved to top of your HTML content.
206
213
  #
207
- # Returns [Hash] Information on the tracking click settings
208
- def update_domain_tracking_click_settings(domain, options = {})
209
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
210
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
211
- @client.put("domains/#{domain}/tracking/click", options).to_h
214
+ # Returns [Hash] Information on the tracking open settings
215
+ def update_domain_tracking_open_settings(domain, options = {})
216
+ @client.put("domains/#{domain}/tracking/open", options).to_h
212
217
  end
213
218
 
214
219
  # Public: Updates unsubscribe tracking settings for a domain.
@@ -221,114 +226,106 @@ module Mailgun
221
226
  #
222
227
  # Returns [Hash] Information on the tracking unsubscribe settings
223
228
  def update_domain_tracking_unsubscribe_settings(domain, options = {})
224
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
225
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
226
229
  @client.put("domains/#{domain}/tracking/unsubscribe", options).to_h
227
230
  end
228
231
 
229
- # Public: Change the DKIM authority for a domain.
232
+ # Public: Tracking Certificate: Get certificate and status
230
233
  #
231
- # domain - [String] Name of the domain (ex. domain.com)
232
- # options - [Hash] of
233
- # self - [Boolean] true - the domain will be the DKIM authority for itself even
234
- # if the root domain is registered on the same mailgun account
234
+ # domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
235
235
  #
236
- # Returns [Hash] Information on the DKIM authority
237
- def update_domain_dkim_authority(domain, options = {})
238
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
239
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
240
- @client.put("domains/#{domain}/dkim_authority", options).to_h
236
+ # Returns [Hash] Status of certificate. Either 'expired' 'processing' 'active' or 'error'
237
+ def get_domain_tracking_certificate(domain)
238
+ @client.get("x509/#{domain}/status").to_h
241
239
  end
242
240
 
243
- # Public: Update the DKIM selector for a domains
241
+ # Tracking Certificate: Regenerate expired certificate
244
242
  #
245
- # domain - [String] Name of the domain (ex. domain.com)
246
- # options - [Hash] of
247
- # dkim_selector - [String] change the DKIM selector for a domain.
243
+ # domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
248
244
  #
249
- # Returns [Hash] with message key
250
- def update_domain_dkim_selector(domain, options = {})
251
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
252
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
253
- @client.put("domains/#{domain}/dkim_selector", options).to_h
245
+ # Returns [Hash] A message indicating the status of the request.
246
+ def regenerate_domain_tracking_certificate(domain, options = {})
247
+ @client.put("x509/#{domain}", options).to_h
254
248
  end
255
249
 
256
- # Public: Update the CNAME used for tracking opens and clicks
250
+ # Public: Tracking Certificate: Generate
257
251
  #
258
- # domain - [String] Name of the domain (ex. domain.com)
259
- # options - [Hash] of
260
- # web_prefix - [String] change the tracking CNAME for a domain.
252
+ # domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
261
253
  #
262
- # Returns [Hash] with message key
263
- def update_domain_web_prefix(domain, options = {})
264
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
265
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
266
- @client.put("domains/#{domain}/web_prefix", options).to_h
254
+ # Returns [Hash] A message indicating the status of the request.
255
+ def generate_domain_tracking_certificate(domain, options = {})
256
+ @client.post("x509/#{domain}", options).to_h
267
257
  end
268
258
 
269
- # Public: Lists the domain keys for a specified signing domain / authority
259
+ # ==== End of Domain::Tracking methods ====
260
+
261
+
262
+ # ==== Domain::DKIM_Security methods ====
263
+
264
+ # Public: Tracking Certificate: Generate
270
265
  #
271
- # domain - [String] Name of the domain (ex. domain.com)
266
+ # domain - [String] The Domain name
267
+ # rotation_enabled - [Boolean] If true, enables DKIM Auto-Rotation. If false, disables it
272
268
  #
273
- # Returns [Hash] with domain keys data
274
- def get_domain_keys(domain)
275
- fail(ParameterError, 'Client api version must be v4', caller) unless @client.api_version == 'v4'
276
- fail(ParameterError, 'No domain given to retrieve keys on Mailgun', caller) unless domain
277
- @client.get("domains/#{domain}/keys").to_h
269
+ # options - [Hash] of
270
+ # rotation_interval - [String] The interval at which to rotate keys. Example, '5d' for five days
271
+ #
272
+ # Returns [Hash] domain object
273
+ def dkim_rotation(domain, rotation_enabled, options = {})
274
+ options = { rotation_enabled: rotation_enabled }.merge(options)
275
+ @client.put("dkim_management/domains/#{domain}/rotation", options)
278
276
  end
279
277
 
280
- # Public: Activate a domain key for a specified authority and selector.
278
+ # Public: Rotate Automatic Sender Security DKIM key for a domain
281
279
  #
282
- # domain - [String] Name of the domain (ex. domain.com)
283
- # selector - [String] The selector you want to activate for the domain key
280
+ # domain - [String] The Domain name
284
281
  #
285
- # Returns [Hash] with message key and autority + selector data
286
- def activate_domain_key(domain, selector)
287
- fail(ParameterError, 'Client api version must be v4', caller) unless @client.api_version == 'v4'
288
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
289
- fail(ParameterError, 'No selector given to activate key on Mailgun', caller) unless selector
290
- @client.put("domains/#{domain}/keys/#{selector}/activate", {}).to_h
282
+ # Returns [Hash] Response message
283
+ def dkim_rotate(domain)
284
+ @client.post("dkim_management/domains/#{domain}/rotate", {})
291
285
  end
292
286
 
293
- # Public: Deactivate a domain key for a specified authority and selector
287
+ # ==== End of Domain::DKIM_Security methods ====
288
+
289
+ # ==== Credentials methods ====
290
+
291
+ # Public: Creates a new set of SMTP credentials for the defined domain.
294
292
  #
295
- # domain - [String] Name of the domain (ex. domain.com)
296
- # selector - [String] The selector you want to activate for the domain key
293
+ # domain - [String] Name of the domain (ex. domain.com)
294
+ # options - [Hash] of
295
+ # login - [String] The user name (ex. bob.bar)
296
+ # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
297
297
  #
298
- # Returns [Hash] with message key and autority + selector data
299
- def deactivate_domain_key(domain, selector)
300
- fail(ParameterError, 'Client api version must be v4', caller) unless @client.api_version == 'v4'
301
- fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
302
- fail(ParameterError, 'No selector given to activate key on Mailgun', caller) unless selector
303
- @client.put("domains/#{domain}/keys/#{selector}/deactivate", {}).to_h
298
+ # Returns [Hash] with message key
299
+ def create_smtp_credentials(domain, options = {})
300
+ @client.post("domains/#{domain}/credentials", options).to_h
304
301
  end
305
302
 
306
- # Public: Create a domain key
303
+ # Public: Updates the specified SMTP credentials.
307
304
  #
305
+ # domain - [String] Name of the domain (ex. domain.com)
306
+ # login - [String] The user name (ex. bob.bar)
308
307
  # options - [Hash] of
309
- # signing_domain - [String] Name of the domain (ex. domain.com)
310
- # selector - [String] Selector to be used for the new domain key
311
- # bits - [Integer] Key size, can be 1024 or 2048
312
- # pem - [String] Private key PEM
308
+ # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
313
309
  #
314
310
  # Returns [Hash] with message key
315
- def create_domain_key(options = {})
316
- fail(ParameterError, 'Client api version must be v1', caller) unless @client.api_version == 'v1'
317
- @client.post("dkim/keys", options).to_h
311
+ def update_smtp_credentials(domain, login, options = {})
312
+ @client.put("domains/#{domain}/credentials/#{login}", options).to_h
318
313
  end
319
314
 
320
- # Public: Delete a domain key.
315
+ # Public: Deletes the defined SMTP credentials.
321
316
  #
322
- # options - [Hash] of
323
- # signing_domain - [Integer] Name of the domain (ex. domain.com)
324
- # selector - [String] Name of the selector
317
+ # domain - [String] Name of the domain (ex. domain.com)
318
+ # login - [String] The user name (ex. bob.bar)
325
319
  #
326
- # Returns [Hash] with message key
327
- def delete_domain_key(options = {})
328
- fail(ParameterError, 'Client api version must be v1', caller) unless @client.api_version == 'v1'
329
- @client.delete("dkim/keys", options).to_h
320
+ # Returns [Hash] with message and spec keys
321
+ def delete_smtp_credentials(domain, login)
322
+ @client.delete("domains/#{domain}/credentials/#{login}").to_h
330
323
  end
331
324
 
325
+ # ==== End of Credentials methods ====
326
+
327
+ # ==== Reporting::Stat methods ====
328
+
332
329
  # Public: Returns total stats for a given domains
333
330
  #
334
331
  # domain - [String] Name of the domain (ex. domain.com)
@@ -341,9 +338,23 @@ module Mailgun
341
338
  #
342
339
  # Returns [Array] A list of domains (hash)
343
340
  def get_domain_stats(domain, options = {})
344
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
345
341
  fail(ParameterError, 'No domain given to list stats on Mailgun', caller) unless domain
346
342
  @client.get("#{domain}/stats/total", options).to_h
347
343
  end
344
+
345
+ # ==== End of Reporting::Stats methods ====
346
+
347
+
348
+ enforces_api_version 'v1', :list_domain_keys, :create_domain_key, :delete_domain_key, :dkim_rotation,
349
+ :dkim_rotate
350
+ enforces_api_version 'v2', :get_domain_tracking_certificate, :regenerate_domain_tracking_certificate,
351
+ :generate_domain_tracking_certificate
352
+ enforces_api_version 'v3', :remove, :create_smtp_credentials, :update_smtp_credentials,
353
+ :delete_smtp_credentials, :get_domain_tracking_settings,
354
+ :update_domain_tracking_open_settings, :update_domain_tracking_click_settings,
355
+ :update_domain_tracking_unsubscribe_settings, :update_domain_dkim_authority,
356
+ :update_domain_dkim_selector, :get_domain_stats
357
+ enforces_api_version 'v4', :get_domain_keys, :activate_domain_key, :deactivate_domain_key,
358
+ :list, :verify, :create, :update
348
359
  end
349
360
  end
@@ -1,5 +1,3 @@
1
- require 'mailgun/exceptions/exceptions'
2
-
3
1
  module Mailgun
4
2
 
5
3
  # A Mailgun::Events object makes it really simple to consume
@@ -1,4 +1,6 @@
1
1
  module Mailgun
2
+ module Exceptions
3
+ end
2
4
 
3
5
  # Public: A basic class for mananging errors.
4
6
  # Inherits from StandardError (previously RuntimeError) as not all errors are
@@ -0,0 +1,41 @@
1
+ module Mailgun
2
+ module ApiVersionChecker
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def requires_api_version(version, *method_names)
9
+ method_names.each do |method_name|
10
+ original_method = instance_method(method_name)
11
+
12
+ define_method(method_name) do |*args, &block|
13
+ warn_unless_api_version(version)
14
+ original_method.bind(self).call(*args, &block)
15
+ end
16
+ end
17
+ end
18
+
19
+ def enforces_api_version(version, *method_names)
20
+ method_names.each do |method_name|
21
+ original_method = instance_method(method_name)
22
+
23
+ define_method(method_name) do |*args, &block|
24
+ require_api_version(version)
25
+ original_method.bind(self).call(*args, &block)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def warn_unless_api_version(expected_version)
34
+ warn("WARN: Client api version must be #{expected_version}") unless @client.api_version == expected_version
35
+ end
36
+
37
+ def require_api_version(expected_version)
38
+ fail(ParameterError, "Client api version must be #{expected_version}", caller) unless @client.api_version == expected_version
39
+ end
40
+ end
41
+ end
@@ -1,6 +1,3 @@
1
- require 'uri'
2
- require 'openssl'
3
-
4
1
  module Mailgun
5
2
 
6
3
  # Public: Provides methods for creating and handling opt-in URLs,
@@ -1,5 +1,3 @@
1
- require 'mailgun/exceptions/exceptions'
2
-
3
1
  module Mailgun
4
2
  # A Mailgun::Logs object is a simple interface to Mailgun Logs.
5
3
  # Uses Mailgun
@@ -1,5 +1,3 @@
1
- require 'mailgun/messages/message_builder'
2
-
3
1
  module Mailgun
4
2
 
5
3
  # A Mailgun::BatchMessage object is used to create a valid payload
@@ -1,7 +1,3 @@
1
- require 'mini_mime'
2
- require 'time'
3
- require 'faraday/multipart'
4
-
5
1
  module Mailgun
6
2
 
7
3
  # A Mailgun::MessageBuilder object is used to create a valid payload
@@ -1,5 +1,3 @@
1
- require 'mailgun/exceptions/exceptions'
2
-
3
1
  module Mailgun
4
2
  # A Mailgun::Metrics object is a simple interface to Mailgun Metrics.
5
3
  # Uses Mailgun
@@ -1,5 +1,3 @@
1
- require 'mailgun/exceptions/exceptions'
2
-
3
1
  module Mailgun
4
2
 
5
3
  # A Mailgun::Subaccounts object is a simple CRUD interface to Mailgun Subaccounts.
@@ -1,7 +1,3 @@
1
- require 'uri'
2
-
3
- require 'mailgun/exceptions/exceptions'
4
-
5
1
  module Mailgun
6
2
 
7
3
  # The Mailgun::Suppressions object makes it easy to manage "suppressions"
@@ -45,7 +41,7 @@ module Mailgun
45
41
  end
46
42
 
47
43
  def get_bounce(address)
48
- @client.get("#{@domain}/bounces/#{escape_address(address)}", nil)
44
+ @client.get("#{@domain}/bounces/#{escape_address(address)}")
49
45
  end
50
46
 
51
47
  def create_bounce(params = {})
@@ -187,7 +183,7 @@ module Mailgun
187
183
  end
188
184
 
189
185
  def get_complaint(address)
190
- @client.get("#{@domain}/complaints/#{escape_address(address)}", nil)
186
+ @client.get("#{@domain}/complaints/#{escape_address(address)}")
191
187
  end
192
188
 
193
189
  def create_complaint(params = {})