mailgun-ruby 1.3.9 → 1.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e49ed622ba4de1537cb0cce86e10625246d662647775395b90b8474d9a9851b
4
- data.tar.gz: fa6b6dc8b656f7019b99d1d9acda02d83f2ff341ff117872489e016d5bbdacc4
3
+ metadata.gz: 56b457f9a512474de60aebfe220b4cb31bcfcfcc032972ce2c5a1aa0ad1322c2
4
+ data.tar.gz: 916852ea7483fe046b0d4c3c7883c79013b4378af43b2e6e978bf30f4dc9ef16
5
5
  SHA512:
6
- metadata.gz: aaca70334ed6dfd48266275f8cb31b0e6a48897a7ab92c16212aa3d2e767963a80458375b26dcf4e2bcb0307752dce4c70332c8cbc965d983bceb17ddf8b86f3
7
- data.tar.gz: c431cdf136b5cec3af1bbbd282c44ba599882f8b7e0ada6dace5db9a9584e77b7ffff78251e5681ed155233ea948af89900e4b80895ed2d2254673303f9c138c
6
+ metadata.gz: 7d43f29a5a245d06253ae97e44830c9768f494597506ce6ff4e87f28cc9071f12a959d0d3102f2d6f85140e5f373c2eefdd491064f804c12669618feef929594
7
+ data.tar.gz: 3bbd64c03a2bad22f6d0853607e3bc97358ef7c55c35b2e0420c000fe7166422319c4a0f6bc80ddec2c6ad8aa99ba7a0bb5b6cd54e023de3a0491a0774e36143
@@ -15,7 +15,7 @@ jobs:
15
15
  runs-on: ubuntu-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby-version: ['3.1', '3.4']
18
+ ruby-version: [ '2.6', '2.7', '3.0', '3.1', '3.4' ]
19
19
 
20
20
  steps:
21
21
  - uses: actions/checkout@v4
@@ -25,4 +25,4 @@ jobs:
25
25
  ruby-version: ${{ matrix.ruby-version }}
26
26
  bundler-cache: true
27
27
  - name: Run tests
28
- run: bundle exec rake
28
+ run: bundle exec rake spec:all
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.4.0] - 2025-09-22
6
+
7
+ - Domains - Add missing endpoints and refactor existing ones in (https://github.com/mailgun/mailgun-ruby/pull/365)
8
+
9
+ ## [1.3.10] - 2025-08-28
10
+
11
+ - Switch to mini_mime for memory savings in (https://github.com/mailgun/mailgun-ruby/pull/363)
12
+ - Add backwards compatibility for previous ruby versions in (https://github.com/mailgun/mailgun-ruby/pull/364)
13
+
14
+ ## [1.3.9] - 2025-07-28
15
+
16
+ - Fix messages.mime broken in (https://github.com/mailgun/mailgun-ruby/pull/361)
17
+ - Fix BatchMessage modifies stored test deliveries in (https://github.com/mailgun/mailgun-ruby/pull/362)
18
+
5
19
  ## [1.3.8] - 2025-07-23
6
20
 
7
21
  - Respond with error message for 400 Bad Request
data/Gemfile CHANGED
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in mailgun.gemspec
4
4
  gemspec
5
5
 
6
- gem 'mime-types'
6
+ gem 'mini_mime'
7
7
  gem 'json', '~> 2.1', platform: :mri_19
data/README.md CHANGED
@@ -19,7 +19,7 @@ gem install mailgun-ruby
19
19
  Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'mailgun-ruby', '~>1.3.9'
22
+ gem 'mailgun-ruby', '~>1.4.0'
23
23
  ```
24
24
 
25
25
  Usage
@@ -1,10 +1,12 @@
1
1
  require 'mailgun/exceptions/exceptions'
2
+ require 'mailgun/helpers/api_version_checker'
2
3
 
3
4
  module Mailgun
4
5
 
5
6
  # A Mailgun::Domains object is a simple CRUD interface to Mailgun Domains.
6
7
  # Uses Mailgun
7
8
  class Domains
9
+ include ApiVersionChecker
8
10
 
9
11
  # Public: creates a new Mailgun::Domains instance.
10
12
  # Defaults to Mailgun::Client
@@ -12,6 +14,8 @@ module Mailgun
12
14
  @client = client
13
15
  end
14
16
 
17
+ # ==== Core Domains methods ====
18
+
15
19
  # Public: Get Domains
16
20
  #
17
21
  # limit - [Integer] Maximum number of records to return. (100 by default)
@@ -19,37 +23,13 @@ module Mailgun
19
23
  #
20
24
  # Returns [Array] A list of domains (hash)
21
25
  def list(options = {})
22
- warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
23
26
  @client.get('domains', options).to_h['items']
24
27
  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
28
 
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!
29
+ def get_domains
30
+ warn('The `get_domains` method will be deprecated in future versions of Mailgun. Please use `list` instead.')
31
+ list
51
32
  end
52
- alias_method :verify_domain, :verify
53
33
 
54
34
  # Public: Add domain
55
35
  #
@@ -64,27 +44,39 @@ module Mailgun
64
44
  #
65
45
  # Returns [Hash] of created domain
66
46
  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
47
  options = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge(options)
70
48
  options[:name] = domain
71
49
  @client.post('domains', options).to_h
72
50
  end
73
- alias_method :add, :create
74
- alias_method :add_domain, :create
75
51
 
76
- # Public: Delete Domain
52
+ def add(domain, options = {})
53
+ warn('The `add` method will be deprecated in future versions of Mailgun. Please use `create` instead.')
54
+ create(domain, options)
55
+ end
56
+
57
+ def add_domain(domain, options = {})
58
+ warn('The `add_domain` method will be deprecated in future versions of Mailgun. Please use `create` instead.')
59
+ create(domain, options)
60
+ end
61
+
62
+ # Public: Get domain information
77
63
  #
78
- # domain - [String] domain name to delete (ex. domain.com)
64
+ # domain - [String] Domain name to lookup
79
65
  #
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'
66
+ # Returns [Hash] Information on the requested domains.
67
+ def get(domain)
68
+ @client.get("domains/#{domain}").to_h!
69
+ end
70
+
71
+ def info(domain)
72
+ warn('The `info` method will be deprecated in future versions of Mailgun. Please use `get` instead.')
73
+ get(domain)
74
+ end
75
+
76
+ def get_domain(domain)
77
+ warn('The `get_domain` method will be deprecated in future versions of Mailgun. Please use `get` instead.')
78
+ get(domain)
85
79
  end
86
- alias_method :delete, :remove
87
- alias_method :delete_domain, :remove
88
80
 
89
81
  # Public: Update domain
90
82
  #
@@ -100,115 +92,173 @@ module Mailgun
100
92
  #
101
93
  # Returns [Hash] of updated domain
102
94
  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
95
  @client.put("domains/#{domain}", options).to_h
106
96
  end
107
97
 
108
- # Public: Creates a new set of SMTP credentials for the defined domain.
98
+
99
+ # Public: Verify domain, update domain records
100
+ # Unknown status - this is not in the current Mailgun API
101
+ # Do no rely on this being available in future releases.
109
102
  #
110
- # domain - [String] Name of the domain (ex. domain.com)
103
+ # domain - [String] Domain name
104
+ #
105
+ # Returns [Hash] Information on the updated/verified domains
106
+ def verify(domain)
107
+ @client.put("domains/#{domain}/verify", nil).to_h!
108
+ end
109
+
110
+ def verify_domain(domain)
111
+ warn('The `verify_domain` method will be deprecated in future versions of Mailgun. Please use `verify` instead.')
112
+ verify(domain)
113
+ end
114
+
115
+ # Public: Delete Domain
116
+ #
117
+ # domain - [String] domain name to delete (ex. domain.com)
118
+ #
119
+ # Returns [Boolean] if successful or not
120
+ def remove(domain)
121
+ @client.delete("domains/#{domain}").to_h['message'] == 'Domain has been deleted'
122
+ end
123
+
124
+ def delete(domain)
125
+ warn('The `delete` method will be deprecated in future versions of Mailgun. Please use `remove` instead.')
126
+ remove(domain)
127
+ end
128
+
129
+ def delete_domain(domain)
130
+ warn('The `delete_domain` method will be deprecated in future versions of Mailgun. Please use `remove` instead.')
131
+ remove(domain)
132
+ end
133
+
134
+ # ==== End of Core Domains methods ====
135
+
136
+ # ==== Domain::Keys methods ====
137
+
138
+ # Public: List keys for all domains
139
+ #
140
+
111
141
  # 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)
142
+ # page - [String] Encoded paging information, provided via 'next', 'previous' links
143
+ # limit - [Integer] Limits the number of items returned in a request
144
+ # signing_domain - [String] Filter by signing domain
145
+ # selector - [String] Filter by selector
114
146
  #
115
147
  # 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
148
+ def list_domain_keys(options = {})
149
+ @client.get("dkim/keys", options).to_h
120
150
  end
121
151
 
122
- # Public: Updates the specified SMTP credentials.
152
+ # Public: Create a domain key
123
153
  #
124
- # domain - [String] Name of the domain (ex. domain.com)
125
- # login - [String] The user name (ex. bob.bar)
126
154
  # options - [Hash] of
127
- # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
155
+ # signing_domain - [String] Name of the domain (ex. domain.com)
156
+ # selector - [String] Selector to be used for the new domain key
157
+ # bits - [Integer] Key size, can be 1024 or 2048
158
+ # pem - [String] Private key PEM
128
159
  #
129
160
  # 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
161
+ def create_domain_key(options = {})
162
+ @client.post("dkim/keys", options).to_h
135
163
  end
136
164
 
137
- # Public: Deletes the defined SMTP credentials.
165
+ # Public: Delete a domain key.
166
+ #
167
+ # options - [Hash] of
168
+ # signing_domain - [Integer] Name of the domain (ex. domain.com)
169
+ # selector - [String] Name of the selector
170
+ #
171
+ # Returns [Hash] with message key
172
+ def delete_domain_key(options = {})
173
+ @client.delete("dkim/keys", options).to_h
174
+ end
175
+
176
+ # Public: Activate a domain key for a specified authority and selector.
177
+ #
178
+ # domain - [String] Name of the domain (ex. domain.com)
179
+ # selector - [String] The selector you want to activate for the domain key
180
+ #
181
+ # Returns [Hash] with message key and autority + selector data
182
+ def activate_domain_key(domain, selector)
183
+ @client.put("domains/#{domain}/keys/#{selector}/activate", {}).to_h
184
+ end
185
+
186
+ # Public: Lists the domain keys for a specified signing domain / authority
138
187
  #
139
188
  # domain - [String] Name of the domain (ex. domain.com)
140
- # login - [String] The user name (ex. bob.bar)
141
189
  #
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
190
+ # Returns [Hash] with domain keys data
191
+ def get_domain_keys(domain)
192
+ @client.get("domains/#{domain}/keys").to_h
148
193
  end
149
194
 
150
- # Public: Returns delivery connection settings for the defined domain.
195
+ # Public: Deactivate a domain key for a specified authority and selector
196
+ #
197
+ # domain - [String] Name of the domain (ex. domain.com)
198
+ # selector - [String] The selector you want to activate for the domain key
199
+ #
200
+ # Returns [Hash] with message key and autority + selector data
201
+ def deactivate_domain_key(domain, selector)
202
+ @client.put("domains/#{domain}/keys/#{selector}/deactivate", {}).to_h
203
+ end
204
+
205
+ # Public: Change the DKIM authority for a domain.
151
206
  #
152
207
  # domain - [String] Name of the domain (ex. domain.com)
208
+ # options - [Hash] of
209
+ # self - [Boolean] true - the domain will be the DKIM authority for itself even
210
+ # if the root domain is registered on the same mailgun account
153
211
  #
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
212
+ # Returns [Hash] Information on the DKIM authority
213
+ def update_domain_dkim_authority(domain, options = {})
214
+ @client.put("domains/#{domain}/dkim_authority", options).to_h
159
215
  end
160
216
 
161
- # Public: Updates the specified delivery connection settings for the defined domain.d
217
+ # Public: Update the DKIM selector for a domains
162
218
  #
163
219
  # domain - [String] Name of the domain (ex. domain.com)
164
220
  # 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
221
+ # dkim_selector - [String] change the DKIM selector for a domain.
168
222
  #
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
223
+ # Returns [Hash] with message key
224
+ def update_domain_dkim_selector(domain, options = {})
225
+ @client.put("domains/#{domain}/dkim_selector", options).to_h
174
226
  end
175
227
 
228
+ # ==== End of Domain::Keys methods ====
229
+
230
+ # ==== Domain::Tracking methods ====
231
+
176
232
  # Public: Returns tracking settings for the defined domain.
177
233
  #
178
234
  # domain - [String] Name of the domain (ex. domain.com)
179
235
  #
180
236
  # Returns [Hash] Information on the tracking settings
181
237
  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
238
  @client.get("domains/#{domain}/tracking").to_h
185
239
  end
186
240
 
187
- # Public: Updates the open tracking settings for a domain.
241
+ # Public: Updates the click tracking settings for a domain.
188
242
  #
189
243
  # domain - [String] Name of the domain (ex. domain.com)
190
244
  # 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.
245
+ # active - [Boolean] yes or no. If set to yes, links will be overwritten and pointed to our servers so we can track clicks.
193
246
  #
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
247
+ # Returns [Hash] Information on the tracking click settings
248
+ def update_domain_tracking_click_settings(domain, options = {})
249
+ @client.put("domains/#{domain}/tracking/click", options).to_h
199
250
  end
200
251
 
201
- # Public: Updates the click tracking settings for a domain.
252
+ # Public: Updates the open tracking settings for a domain.
202
253
  #
203
254
  # domain - [String] Name of the domain (ex. domain.com)
204
255
  # 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.
256
+ # active - [Boolean] yes or no. If set to yes, a tracking pixel will be inserted below your HTML content.
257
+ # place_at_the_top - [Boolean] yes or no. If set to yes, tracking pixel will be moved to top of your HTML content.
206
258
  #
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
259
+ # Returns [Hash] Information on the tracking open settings
260
+ def update_domain_tracking_open_settings(domain, options = {})
261
+ @client.put("domains/#{domain}/tracking/open", options).to_h
212
262
  end
213
263
 
214
264
  # Public: Updates unsubscribe tracking settings for a domain.
@@ -221,114 +271,106 @@ module Mailgun
221
271
  #
222
272
  # Returns [Hash] Information on the tracking unsubscribe settings
223
273
  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
274
  @client.put("domains/#{domain}/tracking/unsubscribe", options).to_h
227
275
  end
228
276
 
229
- # Public: Change the DKIM authority for a domain.
277
+ # Public: Tracking Certificate: Get certificate and status
230
278
  #
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
279
+ # domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
235
280
  #
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
281
+ # Returns [Hash] Status of certificate. Either 'expired' 'processing' 'active' or 'error'
282
+ def get_domain_tracking_certificate(domain)
283
+ @client.get("x509/#{domain}/status").to_h
241
284
  end
242
285
 
243
- # Public: Update the DKIM selector for a domains
286
+ # Tracking Certificate: Regenerate expired certificate
244
287
  #
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.
288
+ # domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
248
289
  #
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
290
+ # Returns [Hash] A message indicating the status of the request.
291
+ def regenerate_domain_tracking_certificate(domain, options = {})
292
+ @client.put("x509/#{domain}", options).to_h
254
293
  end
255
294
 
256
- # Public: Update the CNAME used for tracking opens and clicks
295
+ # Public: Tracking Certificate: Generate
257
296
  #
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.
297
+ # domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
261
298
  #
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
299
+ # Returns [Hash] A message indicating the status of the request.
300
+ def generate_domain_tracking_certificate(domain, options = {})
301
+ @client.post("x509/#{domain}", options).to_h
267
302
  end
268
303
 
269
- # Public: Lists the domain keys for a specified signing domain / authority
304
+ # ==== End of Domain::Tracking methods ====
305
+
306
+
307
+ # ==== Domain::DKIM_Security methods ====
308
+
309
+ # Public: Tracking Certificate: Generate
270
310
  #
271
- # domain - [String] Name of the domain (ex. domain.com)
311
+ # domain - [String] The Domain name
312
+ # rotation_enabled - [Boolean] If true, enables DKIM Auto-Rotation. If false, disables it
272
313
  #
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
314
+ # options - [Hash] of
315
+ # rotation_interval - [String] The interval at which to rotate keys. Example, '5d' for five days
316
+ #
317
+ # Returns [Hash] domain object
318
+ def dkim_rotation(domain, rotation_enabled, options = {})
319
+ options = { rotation_enabled: rotation_enabled }.merge(options)
320
+ @client.put("dkim_management/domains/#{domain}/rotation", options)
278
321
  end
279
322
 
280
- # Public: Activate a domain key for a specified authority and selector.
323
+ # Public: Rotate Automatic Sender Security DKIM key for a domain
281
324
  #
282
- # domain - [String] Name of the domain (ex. domain.com)
283
- # selector - [String] The selector you want to activate for the domain key
325
+ # domain - [String] The Domain name
284
326
  #
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
327
+ # Returns [Hash] Response message
328
+ def dkim_rotate(domain)
329
+ @client.post("dkim_management/domains/#{domain}/rotate", {})
291
330
  end
292
331
 
293
- # Public: Deactivate a domain key for a specified authority and selector
332
+ # ==== End of Domain::DKIM_Security methods ====
333
+
334
+ # ==== Credentials methods ====
335
+
336
+ # Public: Creates a new set of SMTP credentials for the defined domain.
294
337
  #
295
- # domain - [String] Name of the domain (ex. domain.com)
296
- # selector - [String] The selector you want to activate for the domain key
338
+ # domain - [String] Name of the domain (ex. domain.com)
339
+ # options - [Hash] of
340
+ # login - [String] The user name (ex. bob.bar)
341
+ # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
297
342
  #
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
343
+ # Returns [Hash] with message key
344
+ def create_smtp_credentials(domain, options = {})
345
+ @client.post("domains/#{domain}/credentials", options).to_h
304
346
  end
305
347
 
306
- # Public: Create a domain key
348
+ # Public: Updates the specified SMTP credentials.
307
349
  #
350
+ # domain - [String] Name of the domain (ex. domain.com)
351
+ # login - [String] The user name (ex. bob.bar)
308
352
  # 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
353
+ # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
313
354
  #
314
355
  # 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
356
+ def update_smtp_credentials(domain, login, options = {})
357
+ @client.put("domains/#{domain}/credentials/#{login}", options).to_h
318
358
  end
319
359
 
320
- # Public: Delete a domain key.
360
+ # Public: Deletes the defined SMTP credentials.
321
361
  #
322
- # options - [Hash] of
323
- # signing_domain - [Integer] Name of the domain (ex. domain.com)
324
- # selector - [String] Name of the selector
362
+ # domain - [String] Name of the domain (ex. domain.com)
363
+ # login - [String] The user name (ex. bob.bar)
325
364
  #
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
365
+ # Returns [Hash] with message and spec keys
366
+ def delete_smtp_credentials(domain, login)
367
+ @client.delete("domains/#{domain}/credentials/#{login}").to_h
330
368
  end
331
369
 
370
+ # ==== End of Credentials methods ====
371
+
372
+ # ==== Reporting::Stat methods ====
373
+
332
374
  # Public: Returns total stats for a given domains
333
375
  #
334
376
  # domain - [String] Name of the domain (ex. domain.com)
@@ -341,9 +383,63 @@ module Mailgun
341
383
  #
342
384
  # Returns [Array] A list of domains (hash)
343
385
  def get_domain_stats(domain, options = {})
344
- warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
345
386
  fail(ParameterError, 'No domain given to list stats on Mailgun', caller) unless domain
346
387
  @client.get("#{domain}/stats/total", options).to_h
347
388
  end
389
+
390
+ # ==== End of Reporting::Stats methods ====
391
+
392
+ # ==== Deprecated methods ====
393
+
394
+ # Public: Returns delivery connection settings for the defined domain.
395
+ #
396
+ # domain - [String] Name of the domain (ex. domain.com)
397
+ #
398
+ # Returns [Hash] Information on the delivery connection settings
399
+ def get_domain_connection_settings(domain)
400
+ @client.get("domains/#{domain}/connection").to_h
401
+ end
402
+
403
+ # Public: Updates the specified delivery connection settings for the defined domain.d
404
+ #
405
+ # domain - [String] Name of the domain (ex. domain.com)
406
+ # options - [Hash] of
407
+ # require_tls - [Boolean] true or false. If true - requires the message only be sent over a TLS connection
408
+ # skip_verification - [Boolean] true or false. If true - the certificate and hostname will not be verified
409
+ # when trying to establish a TLS connection
410
+ #
411
+ # Returns [Hash] Information on the delivery connection settings
412
+ def update_domain_connection_settings(domain, options = {})
413
+ @client.put("domains/#{domain}/connection", options).to_h
414
+ end
415
+
416
+ # Public: Update the CNAME used for tracking opens and clicks
417
+ #
418
+ # domain - [String] Name of the domain (ex. domain.com)
419
+ # options - [Hash] of
420
+ # web_prefix - [String] change the tracking CNAME for a domain.
421
+ #
422
+ # Returns [Hash] with message key
423
+ def update_domain_web_prefix(domain, options = {})
424
+ @client.put("domains/#{domain}/web_prefix", options).to_h
425
+ end
426
+
427
+ # ==== End of Deprecated methods ====
428
+
429
+
430
+
431
+
432
+ enforces_api_version 'v1', :list_domain_keys, :create_domain_key, :delete_domain_key, :dkim_rotation,
433
+ :dkim_rotate
434
+ enforces_api_version 'v2', :get_domain_tracking_certificate, :regenerate_domain_tracking_certificate,
435
+ :generate_domain_tracking_certificate
436
+ enforces_api_version 'v3', :remove, :create_smtp_credentials, :update_smtp_credentials,
437
+ :delete_smtp_credentials, :get_domain_connection_settings,
438
+ :update_domain_connection_settings, :get_domain_tracking_settings,
439
+ :update_domain_tracking_open_settings, :update_domain_tracking_click_settings,
440
+ :update_domain_tracking_unsubscribe_settings, :update_domain_dkim_authority,
441
+ :update_domain_dkim_selector, :update_domain_web_prefix, :get_domain_stats
442
+ enforces_api_version 'v4', :get_domain_keys, :activate_domain_key, :deactivate_domain_key,
443
+ :list, :info, :verify, :create, :update
348
444
  end
349
445
  end
@@ -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,4 +1,4 @@
1
- require 'mime/types'
1
+ require 'mini_mime'
2
2
  require 'time'
3
3
  require 'faraday/multipart'
4
4
 
@@ -472,8 +472,8 @@ module Mailgun
472
472
  ) unless attachment.respond_to?(:read)
473
473
 
474
474
  if attachment.respond_to?(:path) && !attachment.respond_to?(:content_type)
475
- mime_types = MIME::Types.type_for(attachment.path)
476
- content_type = mime_types.empty? ? 'application/octet-stream' : mime_types[0].content_type
475
+ mime_types = MiniMime.lookup_by_filename(attachment.path)
476
+ content_type = mime_types.nil? ? 'application/octet-stream' : mime_types.content_type
477
477
  attachment.instance_eval "def content_type; '#{content_type}'; end"
478
478
  end
479
479
 
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.3.9'
3
+ VERSION = '1.4.0'
4
4
  end
data/mailgun.gemspec CHANGED
@@ -25,18 +25,18 @@ Gem::Specification.new do |spec|
25
25
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.required_ruby_version = '>= 2.2.2'
28
+ spec.required_ruby_version = '>= 2.6.10'
29
29
 
30
30
  spec.add_development_dependency 'bundler', '>= 1.16.2'
31
31
  spec.add_development_dependency 'rspec', '~> 3.13.0'
32
- spec.add_development_dependency 'rspec-its', '~> 2.0.0'
32
+ spec.add_development_dependency 'rspec-its', '~> 1.3.1'
33
33
  spec.add_development_dependency 'rake', '~> 12.3.2'
34
34
  spec.add_development_dependency 'webmock', '~> 3.7'
35
35
  spec.add_development_dependency 'pry', '~> 0.15.2'
36
36
  spec.add_development_dependency 'vcr', '~> 3.0.3'
37
37
  spec.add_development_dependency 'simplecov', '~> 0.16.1'
38
38
  spec.add_development_dependency 'rails'
39
- spec.add_dependency 'mime-types'
39
+ spec.add_dependency 'mini_mime'
40
40
  spec.add_dependency 'faraday', "~> 2.1"
41
41
  spec.add_dependency 'faraday-multipart', '~> 1.1.0'
42
42
 
@@ -2,17 +2,13 @@ require 'spec_helper'
2
2
  require 'mailgun'
3
3
  require 'mailgun/exceptions/exceptions'
4
4
 
5
- vcr_opts = { :cassette_name => "instance" }
6
-
7
- describe 'Mailgun instantiation', vcr: vcr_opts do
5
+ describe 'Mailgun instantiation', vcr: { :cassette_name => "instance" } do
8
6
  it 'instantiates an HttpClient object' do
9
7
  expect {@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)}.not_to raise_error
10
8
  end
11
9
  end
12
10
 
13
- vcr_opts = { :cassette_name => "exceptions" }
14
-
15
- describe 'Client exceptions', vcr: vcr_opts do
11
+ describe 'Client exceptions', vcr: { :cassette_name => "exceptions" } do
16
12
  before(:all) do
17
13
  @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
18
14
  @domain = TESTDOMAIN || 'DOMAIN.TEST'
@@ -27,16 +23,15 @@ describe 'Client exceptions', vcr: vcr_opts do
27
23
  :text => 'INTEGRATION TESTING'
28
24
  })
29
25
  rescue Mailgun::CommunicationError => err
30
- expect(err.message).to eq('the server responded with status 404: Domain not found: not-our-doma.in')
26
+ expect(err.message).to include('404')
27
+ expect(err.message).to include('Domain not found: not-our-doma.in')
31
28
  else
32
29
  fail
33
30
  end
34
31
  end
35
32
  end
36
33
 
37
- vcr_opts = { :cassette_name => "exceptions-invalid-api-key" }
38
-
39
- describe 'Client exceptions', vcr: vcr_opts do
34
+ describe 'Client exceptions', vcr: { :cassette_name => "exceptions-invalid-api-key" } do
40
35
  before(:all) do
41
36
  @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
42
37
  @domain = TESTDOMAIN || 'DOMAIN.TEST'
@@ -51,16 +46,15 @@ describe 'Client exceptions', vcr: vcr_opts do
51
46
  :text => 'INTEGRATION TESTING'
52
47
  })
53
48
  rescue Mailgun::Unauthorized => err
54
- expect(err.message).to eq('the server responded with status 401 - Invalid Domain or API key')
49
+ expect(err.message).to include('401')
50
+ expect(err.message).to include('Invalid Domain or API key')
55
51
  else
56
52
  fail
57
53
  end
58
54
  end
59
55
  end
60
56
 
61
- vcr_opts = { :cassette_name => "exceptions-invalid-data" }
62
-
63
- describe 'Client exceptions', vcr: vcr_opts do
57
+ describe 'Client exceptions', vcr: { :cassette_name => "exceptions-invalid-data" } do
64
58
  before(:all) do
65
59
  @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
66
60
  @domain = TESTDOMAIN || 'DOMAIN.TEST'
@@ -75,16 +69,15 @@ describe 'Client exceptions', vcr: vcr_opts do
75
69
  :text => 'INTEGRATION TESTING'
76
70
  })
77
71
  rescue Mailgun::BadRequest => err
78
- expect(err.message).to eq('the server responded with status 400: to parameter is not a valid address. please check documentation')
72
+ expect(err.message).to include('400')
73
+ expect(err.message).to include('to parameter is not a valid address. please check documentation')
79
74
  else
80
75
  fail
81
76
  end
82
77
  end
83
78
  end
84
79
 
85
- vcr_opts = { :cassette_name => "exceptions-not-allowed" }
86
-
87
- describe 'Client exceptions', vcr: vcr_opts do
80
+ describe 'Client exceptions', vcr: { :cassette_name => "exceptions-not-allowed" } do
88
81
  before(:all) do
89
82
  @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
90
83
  @domain = TESTDOMAIN || 'DOMAIN.TEST'
@@ -106,9 +99,7 @@ describe 'Client exceptions', vcr: vcr_opts do
106
99
  end
107
100
  end
108
101
 
109
- vcr_opts = { :cassette_name => "send_message" }
110
-
111
- describe 'The method send_message()', vcr: vcr_opts do
102
+ describe 'The method send_message()', vcr: { :cassette_name => "send_message" } do
112
103
  before(:all) do
113
104
  @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
114
105
  @domain = TESTDOMAIN || 'DOMAIN.TEST'
@@ -998,6 +998,51 @@ http_interactions:
998
998
  '
999
999
  http_version:
1000
1000
  recorded_at: Wed, 26 Feb 2025 21:54:43 GMT
1001
+ - request:
1002
+ method: delete
1003
+ uri: https://api.mailgun.net/v1/dkim/keys?params=%7B:signing_domain=%3E%22integration-test.domain.invalid%22,%20:selector=%3E%22test%22%7D
1004
+ body:
1005
+ encoding: US-ASCII
1006
+ string: ''
1007
+ headers:
1008
+ User-Agent:
1009
+ - mailgun-sdk-ruby/1.3.10
1010
+ Accept:
1011
+ - "*/*"
1012
+ Authorization:
1013
+ - Basic YXBpOg==
1014
+ Accept-Encoding:
1015
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
1016
+ response:
1017
+ status:
1018
+ code: 200
1019
+ message: OK
1020
+ headers:
1021
+ Access-Control-Allow-Credentials:
1022
+ - 'true'
1023
+ Access-Control-Allow-Origin:
1024
+ - "*"
1025
+ Cache-Control:
1026
+ - no-store
1027
+ Content-Length:
1028
+ - '39'
1029
+ Content-Type:
1030
+ - application/json
1031
+ Date:
1032
+ - Thu, 28 Aug 2025 12:45:35 GMT
1033
+ Strict-Transport-Security:
1034
+ - max-age=63072000; includeSubDomains
1035
+ Www-Authenticate:
1036
+ - Basic realm="MG API"
1037
+ X-Xss-Protection:
1038
+ - 1; mode=block
1039
+ body:
1040
+ encoding: UTF-8
1041
+ string: '{"message":"success"}
1042
+
1043
+ '
1044
+ http_version:
1045
+ recorded_at: Thu, 28 Aug 2025 12:45:35 GMT
1001
1046
  - request:
1002
1047
  method: delete
1003
1048
  uri: https://api.mailgun.net/v1/dkim/keys?params=%7Bsigning_domain:%20%22integration-test.domain.invalid%22,%20selector:%20%22test%22%7D
@@ -1006,11 +1051,11 @@ http_interactions:
1006
1051
  string: ''
1007
1052
  headers:
1008
1053
  User-Agent:
1009
- - mailgun-sdk-ruby/1.3.2
1054
+ - mailgun-sdk-ruby/1.3.10
1010
1055
  Accept:
1011
1056
  - "*/*"
1012
1057
  Authorization:
1013
- - Basic xxx
1058
+ - Basic YXBpOg==
1014
1059
  Accept-Encoding:
1015
1060
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
1016
1061
  response:
@@ -1025,15 +1070,15 @@ http_interactions:
1025
1070
  Cache-Control:
1026
1071
  - no-store
1027
1072
  Content-Length:
1028
- - '58'
1073
+ - '39'
1029
1074
  Content-Type:
1030
- - application/json; charset=utf-8
1075
+ - application/json
1031
1076
  Date:
1032
- - Wed, 26 Feb 2025 21:57:39 GMT
1077
+ - Thu, 28 Aug 2025 14:47:08 GMT
1033
1078
  Strict-Transport-Security:
1034
1079
  - max-age=63072000; includeSubDomains
1035
- X-Mailgun-Key-Id:
1036
- - c02fd0ba-d8dbad66
1080
+ Www-Authenticate:
1081
+ - Basic realm="MG API"
1037
1082
  X-Xss-Protection:
1038
1083
  - 1; mode=block
1039
1084
  body:
@@ -1042,5 +1087,5 @@ http_interactions:
1042
1087
 
1043
1088
  '
1044
1089
  http_version:
1045
- recorded_at: Wed, 26 Feb 2025 21:57:39 GMT
1090
+ recorded_at: Thu, 28 Aug 2025 14:47:08 GMT
1046
1091
  recorded_with: VCR 3.0.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailgun
8
8
  - Travis Swientek
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-28 00:00:00.000000000 Z
11
+ date: 2025-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.0
47
+ version: 1.3.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.0
54
+ version: 1.3.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: mime-types
140
+ name: mini_mime
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -217,6 +217,7 @@ files:
217
217
  - lib/mailgun/domains/domains.rb
218
218
  - lib/mailgun/events/events.rb
219
219
  - lib/mailgun/exceptions/exceptions.rb
220
+ - lib/mailgun/helpers/api_version_checker.rb
220
221
  - lib/mailgun/lists/opt_in_handler.rb
221
222
  - lib/mailgun/logs/logs.rb
222
223
  - lib/mailgun/messages/batch_message.rb
@@ -310,7 +311,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
310
311
  requirements:
311
312
  - - ">="
312
313
  - !ruby/object:Gem::Version
313
- version: 2.2.2
314
+ version: 2.6.10
314
315
  required_rubygems_version: !ruby/object:Gem::Requirement
315
316
  requirements:
316
317
  - - ">="