mailgun-ruby 1.2.12 → 1.2.14

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
2
  SHA256:
3
- metadata.gz: cf800982a326bb3cd2417126fc5a9de3de7ca0c4cf2c9387541244f3ee6d362d
4
- data.tar.gz: f3515a9207e04c66d69afcaee25ee7aa746ee58f58ea4a48d2511363c1bc6005
3
+ metadata.gz: 3905ad8ab1dae85ea3b87b10d2ac01700de085adab73d9e02373f4d54e70451d
4
+ data.tar.gz: e5794e301066318205a9ffb6de455d73642d3162b1ad75900cefed7aa95db798
5
5
  SHA512:
6
- metadata.gz: a65a2e514f1865825d8c4d7673fd2060e4dd3902402c0500e9dcf213052fff6fb7222379bd155430f30d6abf0300361228ec3cb1db53d2998b2718fb27ffb46a
7
- data.tar.gz: 2f3988bcd4ecd490305543d3719b37f1531f796558879604263810d02d0bca068647634d8d9141f90711d1d9c4f3038ff29b385bdbe0df0537ac80bc451a05e1
6
+ metadata.gz: af8ed54564c2f13b818aa7da6a550b9000b4148ee437b108d01219d80b610580fde3a1973dd831db3ffd8b0dbe934d9288b479a335a5521e3f275815a9f30c8e
7
+ data.tar.gz: 5d11d20420e6333e9e71104fc529d80f19ed689cb300bc5b19ec4c2b855e9c92e24e59d7de83122d2bcdc910a0ec60f783ea277e011e8d375bb1e471be30802e
@@ -10,3 +10,4 @@
10
10
  MAILGUN_APIKEY : '<MAILGUN_APIKEY>'
11
11
  MAILGUN_PUB_APIKEY : '<MAILGUN_PUBLIC_APIKEY>'
12
12
  MAILGUN_TESTDOMAIN : '<MAILGUN_SANDBOX_DOMAIN>'
13
+
data/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [1.2.14] - 2024-02-13
8
+
9
+ ### Added
10
+
11
+ - Tags CRUD support (https://github.com/mailgun/mailgun-ruby/pull/316)
12
+ - Additional Domain Endpoints (https://github.com/mailgun/mailgun-ruby/pull/314)
13
+ - Webhooks Update Method (https://github.com/mailgun/mailgun-ruby/pull/305)
14
+ - Add support for AMP HTML (https://github.com/mailgun/mailgun-ruby/pull/304)
15
+ - Add support for AMP HTML (https://github.com/mailgun/mailgun-ruby/pull/304)
16
+
17
+ ### Fixed
18
+
19
+ - Typos in docs, specs (- Add support for AMP HTML (https://github.com/mailgun/mailgun-ruby/pull/304)).
20
+
21
+ ## [1.2.13] - 2023-11-25
22
+
23
+ ### Added
24
+
25
+ - Subaccounts API support (https://github.com/mailgun/mailgun-ruby/pull/310).
26
+
7
27
  ## [1.2.12] - 2023-10-22
8
28
 
9
29
  ### Added
@@ -13,4 +33,4 @@ All notable changes to this project will be documented in this file.
13
33
  ### Fixed
14
34
 
15
35
  - transform_for_mailgun block iteration issue (https://github.com/mailgun/mailgun-ruby/pull/298).
16
- - Typos in several files (https://github.com/mailgun/mailgun-ruby/pull/297).
36
+ - Typos in several files (https://github.com/mailgun/mailgun-ruby/pull/297).
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.2.12'
22
+ gem 'mailgun-ruby', '~>1.2.14'
23
23
  ```
24
24
 
25
25
  Usage
@@ -188,8 +188,11 @@ This SDK includes the following components:
188
188
  - [Domains](docs/Domains.md)
189
189
  - [Webhooks](docs/Webhooks.md)
190
190
  - [Events](docs/Events.md)
191
+ - [Snippets](docs/Snippets.md)
192
+ - [Subaccounts](docs/Subaccounts.md)
191
193
  - [Suppressions](docs/Suppressions.md)
192
194
  - [Templates](docs/Templates.md)
195
+ - [EmailValidation](docs/EmailValidation.md)
193
196
 
194
197
  Message Builder allows you to quickly create the array of parameters, required
195
198
  to send a message, by calling a methods for each parameter.
data/docs/Domains.md CHANGED
@@ -53,5 +53,5 @@ See the [Suppressions](/docs/Suppressions.md) for usage samples and
53
53
 
54
54
  More Documentation
55
55
  ------------------
56
- See the official [Mailgun Domain Docs](https://documentation.mailgun.com/api-domains.html)
56
+ See the official [Mailgun Domain Docs](https://documentation.mailgun.com/en/latest/api-domains.html)
57
57
  for more information
@@ -0,0 +1,34 @@
1
+ Mailgun - Email Validation
2
+ ====================
3
+
4
+ This is the Mailgun Ruby *Email Validation* utilities.
5
+
6
+ The below assumes you've already installed the Mailgun Ruby SDK in to your
7
+ project. If not, go back to the master README for instructions.
8
+
9
+ Usage - Email Validation
10
+ -----------------------
11
+
12
+ ```ruby
13
+ # First, instantiate the Mailgun Address. It pulls api key for Client from Mailgun.api_key variable.
14
+ email_validator = Mailgun::Address.new
15
+
16
+ # Given an arbitrary address, validates address based off defined checks.
17
+ # Response Example:
18
+ # {
19
+ # "address": "existingemail@realdomain.com",
20
+ # "is_disposable_address": false,
21
+ # "is_role_address": false,
22
+ # "reason": [],
23
+ # "result": "deliverable",
24
+ # "risk": "low"
25
+ # }
26
+ email_validator.validate('email@example.com')
27
+
28
+
29
+ ```
30
+
31
+ More Documentation
32
+ ------------------
33
+ See the official [Mailgun Email Validation Docs](https://documentation.mailgun.com/en/latest/api-email-validation.html)
34
+ for more information
data/docs/Events.md CHANGED
@@ -42,5 +42,5 @@ last time you called "next".
42
42
 
43
43
  More Documentation
44
44
  ------------------
45
- See the official [Mailgun Docs](http://documentation.mailgun.com/api-sending.html)
45
+ See the official [Mailgun Docs](https://documentation.mailgun.com/en/latest/api-events.html)
46
46
  for more information.
@@ -104,5 +104,5 @@ message_ids = mb_obj.finalize
104
104
 
105
105
  More Documentation
106
106
  ------------------
107
- See the official [Mailgun Docs](http://documentation.mailgun.com/api-sending.html)
107
+ See the official [Mailgun Docs](https://documentation.mailgun.com/en/latest/api-sending.html)
108
108
  for more information.
data/docs/Messages.md CHANGED
@@ -103,5 +103,5 @@ message_ids = mb_obj.finalize
103
103
 
104
104
  More Documentation
105
105
  ------------------
106
- See the official [Mailgun Docs](https://documentation.mailgun.com/api-sending.html)
106
+ See the official [Mailgun Docs](https://documentation.mailgun.com/en/latest/api-sending.html)
107
107
  for more information.
data/docs/OptInHandler.md CHANGED
@@ -100,4 +100,4 @@ Available Functions
100
100
 
101
101
  More Documentation
102
102
  ------------------
103
- See the official [Mailgun Docs](https://documentation.mailgun.com/en/latest/api-sending.html) for more information.
103
+ See the official [Mailgun Docs](https://documentation.mailgun.com/) for more information.
data/docs/Snippets.md CHANGED
@@ -513,7 +513,7 @@ Be sure to visit the Mailgun official
513
513
  information about our API.
514
514
 
515
515
  If you find a bug, please submit the issue in Github directly.
516
- [Mailgun-Ruby Issues](https://github.com/mailgun/Mailgun-PHP/issues)
516
+ [Mailgun-Ruby Issues](https://github.com/mailgun/mailgun-ruby/issues)
517
517
 
518
518
  As always, if you need additional assistance, drop us a note at
519
519
  [support@mailgun.com](mailto:support@mailgun.com).
@@ -0,0 +1,68 @@
1
+ Mailgun - [Subaccounts](https://help.mailgun.com/hc/en-us/articles/16380043681435-Subaccounts)
2
+ ====================
3
+
4
+ Rails
5
+ -----
6
+
7
+ The library can be initialized with a Rails initializer containing similar:
8
+ ```ruby
9
+ Mailgun.configure do |config|
10
+ config.api_key = 'your-secret-api-key'
11
+ end
12
+ ```
13
+ Or have the initializer read your environment setting if you prefer.
14
+
15
+ ```ruby
16
+ Mailgun.api_key = 'your-secret-api-key'
17
+ ```
18
+
19
+ ```ruby
20
+ mb_obj = Mailgun::Subaccounts.new
21
+
22
+ # Get subaccounts list
23
+ mb_obj.get_subaccounts(limit: 10, skip: 0, sort: 'ask', enabled: true)
24
+ => {"subaccounts"=>[{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}, {"id"=>"YYY", "name"=>"test.subaccount2", "status"=>"open"}], "total"=>2}
25
+
26
+ # Get subaccount information
27
+ mb_obj.info(subaccount_id)
28
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}
29
+
30
+ # Add Subaccount
31
+ mb_obj.create(name)
32
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}}
33
+
34
+ # Disable
35
+ mb_obj.disable(subaccount_id)
36
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"disabled"}}
37
+
38
+ # Enable
39
+ mb_obj.enable(subaccount_id)
40
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}}
41
+ ```
42
+
43
+ Primary accounts can make API calls on behalf of their subaccounts.
44
+ ```ruby
45
+ # First, instantiate the Mailgun Client with your API key
46
+ mg_client = Mailgun::Client.new 'your-api-key'
47
+ mg_client.set_subaccount('SUBACCOUNT_ID')
48
+
49
+ # Define your message parameters
50
+ message_params = { from: 'bob@SUBACCOUNT_DOMAIN',
51
+ to: 'sally@example.com',
52
+ subject: 'The Ruby SDK is awesome!',
53
+ text: 'It is really easy to send a message!'
54
+ }
55
+
56
+ # Send your message through the client
57
+ # Note: This will not actually hit the API, and will return a generic OK response.
58
+ mg_client.send_message('SUBACCOUNT_DOMAIN', message_params)
59
+
60
+ # Reset subaccount for primary usage
61
+ mg_client.reset_subaccount
62
+ ```
63
+
64
+
65
+ More Documentation
66
+ ------------------
67
+ See the official [Mailgun Docs](https://documentation.mailgun.com/en/latest/subaccounts.html#subaccounts)
68
+ for more information.
data/docs/Suppressions.md CHANGED
@@ -38,6 +38,16 @@ supp_client.list_complaints
38
38
 
39
39
  ----
40
40
 
41
+ To get the next or previous suppressions page:
42
+
43
+ ```ruby
44
+ supp_client.list_bounces # returns first *limit* records + next, previous pages urls
45
+ supp_client.next # returns next *limit* records
46
+ supp_client.prev # returns previous *limit* records
47
+ ```
48
+
49
+ ----
50
+
41
51
  To batch-add a set of bounces:
42
52
 
43
53
  ```ruby
data/docs/Webhooks.md CHANGED
@@ -36,5 +36,5 @@ hook.remove_all 'my.perfect.domain'
36
36
 
37
37
  More Documentation
38
38
  ------------------
39
- See the official [Mailgun Domain Docs](https://documentation.mailgun.com/api-webhooks.html)
39
+ See the official [Mailgun Domain Docs](https://documentation.mailgun.com/en/latest/api-webhooks.html)
40
40
  for more information
@@ -0,0 +1,34 @@
1
+ Mailgun - Email Validation
2
+ ====================
3
+
4
+ This is the Mailgun Ruby *Email Validation* utilities.
5
+
6
+ The below assumes you've already installed the Mailgun Ruby SDK in to your
7
+ project. If not, go back to the master README for instructions.
8
+
9
+ Usage - Email Validation
10
+ -----------------------
11
+
12
+ ```ruby
13
+ # First, instantiate the Mailgun Address. It pulls api key for Client from Mailgun.api_key variable.
14
+ email_validator = Mailgun::Address.new
15
+
16
+ # Given an arbitrary address, validates address based off defined checks.
17
+ # Response Example:
18
+ # {
19
+ # "address": "existingemail@realdomain.com",
20
+ # "is_disposable_address": false,
21
+ # "is_role_address": false,
22
+ # "reason": [],
23
+ # "result": "deliverable",
24
+ # "risk": "low"
25
+ # }
26
+ email_validator.validate('email@example.com')
27
+
28
+
29
+ ```
30
+
31
+ More Documentation
32
+ ------------------
33
+ See the official [Mailgun Email Validation Docs](https://documentation.mailgun.com/en/latest/api-email-validation.html)
34
+ for more information
@@ -9,6 +9,7 @@ module Mailgun
9
9
  #
10
10
  # See the Github documentation for full examples.
11
11
  class Client
12
+ SUBACCOUNT_HEADER = 'X-Mailgun-On-Behalf-Of'.freeze
12
13
 
13
14
  def initialize(api_key = Mailgun.api_key,
14
15
  api_host = Mailgun.api_host || 'api.mailgun.net',
@@ -29,6 +30,7 @@ module Mailgun
29
30
  RestClient.proxy = proxy_url
30
31
  @http_client = RestClient::Resource.new(endpoint, rest_client_params)
31
32
  @test_mode = test_mode
33
+ @api_version = api_version
32
34
  end
33
35
 
34
36
  # Enable test mode
@@ -50,6 +52,16 @@ module Mailgun
50
52
  @http_client.options[:password] = api_key
51
53
  end
52
54
 
55
+ # Add subaccount id to headers
56
+ def set_subaccount(subaccount_id)
57
+ @http_client.options[:headers] = { SUBACCOUNT_HEADER => subaccount_id }
58
+ end
59
+
60
+ # Reset subaccount for primary usage
61
+ def reset_subaccount
62
+ @http_client.options[:headers].delete(SUBACCOUNT_HEADER)
63
+ end
64
+
53
65
  # Client is in test mode?
54
66
  #
55
67
  # @return [Boolean] Is the client set in test mode?
@@ -57,6 +69,11 @@ module Mailgun
57
69
  @test_mode
58
70
  end
59
71
 
72
+ # @return [String] client api version
73
+ def api_version
74
+ @api_version
75
+ end
76
+
60
77
  # Provides a store of all the emails sent in test mode so you can check them.
61
78
  #
62
79
  # @return [Hash]
@@ -157,8 +174,12 @@ module Mailgun
157
174
  # @param [String] resource_path This is the API resource you wish to interact
158
175
  # with. Be sure to include your domain, where necessary.
159
176
  # @return [Mailgun::Response] A Mailgun::Response object.
160
- def delete(resource_path)
161
- response = @http_client[resource_path].delete
177
+ def delete(resource_path, params = nil)
178
+ if params
179
+ response = @http_client[resource_path].delete(params: params)
180
+ else
181
+ response = @http_client[resource_path].delete
182
+ end
162
183
  Response.new(response)
163
184
  rescue => err
164
185
  raise communication_error err
@@ -95,8 +95,236 @@ module Mailgun
95
95
  #
96
96
  # Returns [Hash] of updated domain
97
97
  def update(domain, options = {})
98
- fail(ParameterError, 'No domain given to add on Mailgun', caller) unless domain
98
+ fail(ParameterError, 'No domain given to update on Mailgun', caller) unless domain
99
99
  @client.put("domains/#{domain}", options).to_h
100
100
  end
101
+
102
+ # Public: Creates a new set of SMTP credentials for the defined domain.
103
+ #
104
+ # domain - [String] Name of the domain (ex. domain.com)
105
+ # options - [Hash] of
106
+ # login - [String] The user name (ex. bob.bar)
107
+ # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
108
+ #
109
+ # Returns [Hash] with message key
110
+ def create_smtp_credentials(domain, options = {})
111
+ fail(ParameterError, 'No domain given to create credentials on Mailgun', caller) unless domain
112
+ @client.post("domains/#{domain}/credentials", options).to_h
113
+ end
114
+
115
+ # Public: Updates the specified SMTP credentials.
116
+ #
117
+ # domain - [String] Name of the domain (ex. domain.com)
118
+ # login - [String] The user name (ex. bob.bar)
119
+ # options - [Hash] of
120
+ # password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
121
+ #
122
+ # Returns [Hash] with message key
123
+ def update_smtp_credentials(domain, login, options = {})
124
+ fail(ParameterError, 'No domain given to update credentials on Mailgun', caller) unless domain
125
+ fail(ParameterError, 'No login given to update credentials on Mailgun', caller) unless login
126
+ @client.put("domains/#{domain}/credentials/#{login}", options).to_h
127
+ end
128
+
129
+ # Public: Deletes the defined SMTP credentials.
130
+ #
131
+ # domain - [String] Name of the domain (ex. domain.com)
132
+ # login - [String] The user name (ex. bob.bar)
133
+ #
134
+ # Returns [Hash] with message and spec keys
135
+ def delete_smtp_credentials(domain, login)
136
+ fail(ParameterError, 'No domain given to delete credentials on Mailgun', caller) unless domain
137
+ fail(ParameterError, 'No login given to delete credentials on Mailgun', caller) unless login
138
+ @client.delete("domains/#{domain}/credentials/#{login}").to_h
139
+ end
140
+
141
+ # Public: Returns delivery connection settings for the defined domain.
142
+ #
143
+ # domain - [String] Name of the domain (ex. domain.com)
144
+ #
145
+ # Returns [Hash] Information on the delivery connection settings
146
+ def get_domain_connection_settings(domain)
147
+ fail(ParameterError, 'No domain given to retrieve connections on Mailgun', caller) unless domain
148
+ @client.get("domains/#{domain}/connection").to_h
149
+ end
150
+
151
+ # Public: Updates the specified delivery connection settings for the defined domain.d
152
+ #
153
+ # domain - [String] Name of the domain (ex. domain.com)
154
+ # options - [Hash] of
155
+ # require_tls - [Boolean] true or false. If true - requires the message only be sent over a TLS connection
156
+ # skip_verification - [Boolean] true or false. If true - the certificate and hostname will not be verified
157
+ # when trying to establish a TLS connection
158
+ #
159
+ # Returns [Hash] Information on the delivery connection settings
160
+ def update_domain_connection_settings(domain, options = {})
161
+ fail(ParameterError, 'No domain given to update connections on Mailgun', caller) unless domain
162
+ @client.put("domains/#{domain}/connection", options).to_h
163
+ end
164
+
165
+ # Public: Returns tracking settings for the defined domain.
166
+ #
167
+ # domain - [String] Name of the domain (ex. domain.com)
168
+ #
169
+ # Returns [Hash] Information on the tracking settings
170
+ def get_domain_tracking_settings(domain)
171
+ fail(ParameterError, 'No domain given to retrieve tracking settings on Mailgun', caller) unless domain
172
+ @client.get("domains/#{domain}/tracking").to_h
173
+ end
174
+
175
+ # Public: Updates the open tracking settings for a domain.
176
+ #
177
+ # domain - [String] Name of the domain (ex. domain.com)
178
+ # options - [Hash] of
179
+ # active - [Boolean] yes or no. If set to yes, a tracking pixel will be inserted below your HTML content.
180
+ # place_at_the_top - [Boolean] yes or no. If set to yes, tracking pixel will be moved to top of your HTML content.
181
+ #
182
+ # Returns [Hash] Information on the tracking open settings
183
+ def update_domain_tracking_open_settings(domain, options = {})
184
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
185
+ @client.put("domains/#{domain}/tracking/open", options).to_h
186
+ end
187
+
188
+ # Public: Updates the click tracking settings for a domain.
189
+ #
190
+ # domain - [String] Name of the domain (ex. domain.com)
191
+ # options - [Hash] of
192
+ # active - [Boolean] yes or no. If set to yes, links will be overwritten and pointed to our servers so we can track clicks.
193
+ #
194
+ # Returns [Hash] Information on the tracking click settings
195
+ def update_domain_tracking_click_settings(domain, options = {})
196
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
197
+ @client.put("domains/#{domain}/tracking/click", options).to_h
198
+ end
199
+
200
+ # Public: Updates unsubscribe tracking settings for a domain.
201
+ #
202
+ # domain - [String] Name of the domain (ex. domain.com)
203
+ # options - [Hash] of
204
+ # active - [Boolean] true or false.
205
+ # html_footer - [String] Custom HTML version of unsubscribe footer.
206
+ # text_footer - [String] Custom text version of unsubscribe footer.
207
+ #
208
+ # Returns [Hash] Information on the tracking unsubscribe settings
209
+ def update_domain_tracking_unsubscribe_settings(domain, options = {})
210
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
211
+ @client.put("domains/#{domain}/tracking/unsubscribe", options).to_h
212
+ end
213
+
214
+ # Public: Change the DKIM authority for a domain.
215
+ #
216
+ # domain - [String] Name of the domain (ex. domain.com)
217
+ # options - [Hash] of
218
+ # self - [Boolean] true - the domain will be the DKIM authority for itself even
219
+ # if the root domain is registered on the same mailgun account
220
+ #
221
+ # Returns [Hash] Information on the DKIM authority
222
+ def update_domain_dkim_authority(domain, options = {})
223
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
224
+ @client.put("domains/#{domain}/dkim_authority", options).to_h
225
+ end
226
+
227
+ # Public: Update the DKIM selector for a domains
228
+ #
229
+ # domain - [String] Name of the domain (ex. domain.com)
230
+ # options - [Hash] of
231
+ # dkim_selector - [String] change the DKIM selector for a domain.
232
+ #
233
+ # Returns [Hash] with message key
234
+ def update_domain_dkim_selector(domain, options = {})
235
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
236
+ @client.put("domains/#{domain}/dkim_selector", options).to_h
237
+ end
238
+
239
+ # Public: Update the CNAME used for tracking opens and clicks
240
+ #
241
+ # domain - [String] Name of the domain (ex. domain.com)
242
+ # options - [Hash] of
243
+ # web_prefix - [String] change the tracking CNAME for a domain.
244
+ #
245
+ # Returns [Hash] with message key
246
+ def update_domain_web_prefix(domain, options = {})
247
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
248
+ @client.put("domains/#{domain}/web_prefix", options).to_h
249
+ end
250
+
251
+ # Public: Lists the domain keys for a specified signing domain / authority
252
+ #
253
+ # domain - [String] Name of the domain (ex. domain.com)
254
+ #
255
+ # Returns [Hash] with domain keys data
256
+ def get_domain_keys(domain)
257
+ fail(ParameterError, 'Client api version must be v4', caller) unless @client.api_version == 'v4'
258
+ fail(ParameterError, 'No domain given to retrieve keys on Mailgun', caller) unless domain
259
+ @client.get("domains/#{domain}/keys").to_h
260
+ end
261
+
262
+ # Public: Activate a domain key for a specified authority and selector.
263
+ #
264
+ # domain - [String] Name of the domain (ex. domain.com)
265
+ # selector - [String] The selector you want to activate for the domain key
266
+ #
267
+ # Returns [Hash] with message key and autority + selector data
268
+ def activate_domain_key(domain, selector)
269
+ fail(ParameterError, 'Client api version must be v4', caller) unless @client.api_version == 'v4'
270
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
271
+ fail(ParameterError, 'No selector given to activate key on Mailgun', caller) unless selector
272
+ @client.put("domains/#{domain}/keys/#{selector}/activate", {}).to_h
273
+ end
274
+
275
+ # Public: Deactivate a domain key for a specified authority and selector
276
+ #
277
+ # domain - [String] Name of the domain (ex. domain.com)
278
+ # selector - [String] The selector you want to activate for the domain key
279
+ #
280
+ # Returns [Hash] with message key and autority + selector data
281
+ def deactivate_domain_key(domain, selector)
282
+ fail(ParameterError, 'Client api version must be v4', caller) unless @client.api_version == 'v4'
283
+ fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
284
+ fail(ParameterError, 'No selector given to activate key on Mailgun', caller) unless selector
285
+ @client.put("domains/#{domain}/keys/#{selector}/deactivate", {}).to_h
286
+ end
287
+
288
+ # Public: Create a domain key
289
+ #
290
+ # options - [Hash] of
291
+ # signing_domain - [String] Name of the domain (ex. domain.com)
292
+ # selector - [String] Selector to be used for the new domain key
293
+ # bits - [Integer] Key size, can be 1024 or 2048
294
+ # pem - [String] Private key PEM
295
+ #
296
+ # Returns [Hash] with message key
297
+ def create_domain_key(options = {})
298
+ fail(ParameterError, 'Client api version must be v1', caller) unless @client.api_version == 'v1'
299
+ @client.post("dkim/keys", options).to_h
300
+ end
301
+
302
+ # Public: Delete a domain key.
303
+ #
304
+ # options - [Hash] of
305
+ # signing_domain - [Integer] Name of the domain (ex. domain.com)
306
+ # selector - [String] Name of the selector
307
+ #
308
+ # Returns [Hash] with message key
309
+ def delete_domain_key(options = {})
310
+ fail(ParameterError, 'Client api version must be v1', caller) unless @client.api_version == 'v1'
311
+ @client.delete("dkim/keys", options).to_h
312
+ end
313
+
314
+ # Public: Returns total stats for a given domains
315
+ #
316
+ # domain - [String] Name of the domain (ex. domain.com)
317
+ # options - [Hash] of
318
+ # event - [String] The type of the event.
319
+ # start - [String] The starting time. Should be in RFC 2822 or unix epoch format.
320
+ # end - [String] The ending date. Should be in RFC 2822 or unix epoch format
321
+ # resolution - [String] Can be either hour, day or month. Default: day
322
+ # duration - [String] Period of time with resoluton encoded
323
+ #
324
+ # Returns [Array] A list of domains (hash)
325
+ def get_domain_stats(domain, options = {})
326
+ fail(ParameterError, 'No domain given to list stats on Mailgun', caller) unless domain
327
+ @client.get("#{domain}/stats/total", options).to_h
328
+ end
101
329
  end
102
330
  end
@@ -116,6 +116,14 @@ module Mailgun
116
116
  body_html(html_body)
117
117
  end
118
118
 
119
+ # Set an AMP part for the message object
120
+ #
121
+ # @param [String] amp The AMP HTML for the email.
122
+ # @return [void]
123
+ def amp_html(amp = nil)
124
+ set_single('amp-html', amp)
125
+ end
126
+
119
127
  # Adds a series of attachments, when called upon.
120
128
  #
121
129
  # @param [String|File] attachment A file object for attaching as an attachment.