mailgun-ruby 1.2.13 → 1.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -2
- data/README.md +1 -1
- data/docs/Domains.md +1 -1
- data/docs/Events.md +1 -1
- data/docs/MessageBuilder.md +1 -1
- data/docs/Messages.md +1 -1
- data/docs/OptInHandler.md +1 -1
- data/docs/Snippets.md +1 -1
- data/docs/Webhooks.md +1 -1
- data/lib/mailgun/client.rb +12 -2
- data/lib/mailgun/domains/domains.rb +229 -1
- data/lib/mailgun/messages/message_builder.rb +8 -0
- data/lib/mailgun/tags/tags.rb +120 -0
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun/webhooks/webhooks.rb +20 -4
- data/lib/mailgun.rb +1 -0
- data/lib/railgun/mailer.rb +29 -0
- data/spec/integration/domains_spec.rb +244 -0
- data/spec/integration/events_spec.rb +1 -1
- data/spec/integration/mailer_spec.rb +2 -8
- data/spec/integration/tags.rb +139 -0
- data/spec/integration/webhook_spec.rb +10 -10
- data/spec/unit/messages/message_builder_spec.rb +11 -0
- data/spec/unit/railgun/content_type_spec.rb +17 -0
- data/vcr_cassettes/domains.yml +1068 -1
- data/vcr_cassettes/tags.yml +417 -0
- data/vcr_cassettes/webhooks.yml +156 -186
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3905ad8ab1dae85ea3b87b10d2ac01700de085adab73d9e02373f4d54e70451d
|
4
|
+
data.tar.gz: e5794e301066318205a9ffb6de455d73642d3162b1ad75900cefed7aa95db798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af8ed54564c2f13b818aa7da6a550b9000b4148ee437b108d01219d80b610580fde3a1973dd831db3ffd8b0dbe934d9288b479a335a5521e3f275815a9f30c8e
|
7
|
+
data.tar.gz: 5d11d20420e6333e9e71104fc529d80f19ed689cb300bc5b19ec4c2b855e9c92e24e59d7de83122d2bcdc910a0ec60f783ea277e011e8d375bb1e471be30802e
|
data/CHANGELOG.md
CHANGED
@@ -4,13 +4,33 @@ 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
|
+
|
7
21
|
## [1.2.13] - 2023-11-25
|
8
22
|
|
9
23
|
### Added
|
10
24
|
|
11
|
-
- Subaccounts API support (https://github.com/mailgun/mailgun-ruby/pull/
|
25
|
+
- Subaccounts API support (https://github.com/mailgun/mailgun-ruby/pull/310).
|
26
|
+
|
27
|
+
## [1.2.12] - 2023-10-22
|
28
|
+
|
29
|
+
### Added
|
30
|
+
|
31
|
+
- Templates CRUD support (https://github.com/mailgun/mailgun-ruby/pull/300).
|
12
32
|
|
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
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
|
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](
|
45
|
+
See the official [Mailgun Docs](https://documentation.mailgun.com/en/latest/api-events.html)
|
46
46
|
for more information.
|
data/docs/MessageBuilder.md
CHANGED
@@ -104,5 +104,5 @@ message_ids = mb_obj.finalize
|
|
104
104
|
|
105
105
|
More Documentation
|
106
106
|
------------------
|
107
|
-
See the official [Mailgun Docs](
|
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/
|
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/
|
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).
|
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
|
data/lib/mailgun/client.rb
CHANGED
@@ -30,6 +30,7 @@ module Mailgun
|
|
30
30
|
RestClient.proxy = proxy_url
|
31
31
|
@http_client = RestClient::Resource.new(endpoint, rest_client_params)
|
32
32
|
@test_mode = test_mode
|
33
|
+
@api_version = api_version
|
33
34
|
end
|
34
35
|
|
35
36
|
# Enable test mode
|
@@ -68,6 +69,11 @@ module Mailgun
|
|
68
69
|
@test_mode
|
69
70
|
end
|
70
71
|
|
72
|
+
# @return [String] client api version
|
73
|
+
def api_version
|
74
|
+
@api_version
|
75
|
+
end
|
76
|
+
|
71
77
|
# Provides a store of all the emails sent in test mode so you can check them.
|
72
78
|
#
|
73
79
|
# @return [Hash]
|
@@ -168,8 +174,12 @@ module Mailgun
|
|
168
174
|
# @param [String] resource_path This is the API resource you wish to interact
|
169
175
|
# with. Be sure to include your domain, where necessary.
|
170
176
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
171
|
-
def delete(resource_path)
|
172
|
-
|
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
|
173
183
|
Response.new(response)
|
174
184
|
rescue => err
|
175
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
|
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.
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'mailgun/exceptions/exceptions'
|
2
|
+
|
3
|
+
module Mailgun
|
4
|
+
|
5
|
+
# A Mailgun::Tags object is a simple CRUD interface to Mailgun Tags.
|
6
|
+
# Uses Mailgun
|
7
|
+
class Tags
|
8
|
+
|
9
|
+
# Public: creates a new Mailgun::Tags instance.
|
10
|
+
# Defaults to Mailgun::Client
|
11
|
+
def initialize(client = Mailgun::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Get Tags
|
16
|
+
#
|
17
|
+
# domain - [String] Domain name where tag is stored
|
18
|
+
# options - [Hash] of
|
19
|
+
# limit - [Integer] Number of entries to return. Default: 100.
|
20
|
+
#
|
21
|
+
# Returns [Array] A list of tags (hash)
|
22
|
+
def get_tags(domain, options = {})
|
23
|
+
fail(ParameterError, 'No domain given to store template on', caller) unless domain
|
24
|
+
@client.get("#{domain}/tags", options).to_h['items']
|
25
|
+
end
|
26
|
+
|
27
|
+
# Public: Get tag information
|
28
|
+
#
|
29
|
+
# domain - [String] Domain name where tag is stored
|
30
|
+
# tag - [String] Tag name to lookup for
|
31
|
+
#
|
32
|
+
# Returns [Hash] Information on the requested tag.
|
33
|
+
def get_tag(domain, tag)
|
34
|
+
fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
35
|
+
fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
36
|
+
@client.get("#{domain}/tags/#{tag}").to_h!
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Updates a given tag with the information provided
|
40
|
+
#
|
41
|
+
# domain - [String] Domain name where tag is stored
|
42
|
+
# tag - [String] Tag name to lookup for
|
43
|
+
# options - [Hash] of
|
44
|
+
# description - [String] Updated description of the tag
|
45
|
+
#
|
46
|
+
# Returns [Boolean] if successful or not
|
47
|
+
def update(domain, tag, options = {})
|
48
|
+
fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
49
|
+
fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
50
|
+
@client.put("#{domain}/tags/#{tag}", options).to_h['message'] == 'Tag updated'
|
51
|
+
end
|
52
|
+
|
53
|
+
# Public: Get statistics for a given tag
|
54
|
+
#
|
55
|
+
# domain - [String] Domain name where tag is stored
|
56
|
+
# tag - [String] Tag name to lookup for
|
57
|
+
# options - [Hash] of
|
58
|
+
# event - [String] The type of the event. Required. (ex. accepted, delivered, failed, opened)
|
59
|
+
# start - [String] The starting time. Should be in RFC 282 or unix epoch format. Default: 7 days from the current time.
|
60
|
+
# end - [String] The ending date. Should be in RFC 2822 or unix epoch time in seconds. Default: current time.
|
61
|
+
# resolution - [String] Can be either hour, day or month. Default: day
|
62
|
+
# duration - [String] Period of time with resolution encoded. If provided, overwrites the start date and resolution.
|
63
|
+
#
|
64
|
+
# Returns [Hash] of tag stats info
|
65
|
+
def get_tag_stats(domain, tag, options = {})
|
66
|
+
fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
67
|
+
fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
68
|
+
@client.get("#{domain}/tags/#{tag}/stats", options).to_h
|
69
|
+
end
|
70
|
+
|
71
|
+
# Public: Delete Tag
|
72
|
+
# NOTE: Deletes the tag. Note: The statistics for the tag are not destroyed.
|
73
|
+
#
|
74
|
+
# domain - [String] Domain name where tag is stored
|
75
|
+
# tag - [String] Tag name to lookup for
|
76
|
+
#
|
77
|
+
# Returns [Boolean] if successful or not
|
78
|
+
def remove(domain, tag)
|
79
|
+
fail(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
|
80
|
+
fail(ParameterError, 'No template name given to find on provided domain', caller) unless tag
|
81
|
+
@client.delete("#{domain}/tags/#{tag}").to_h['message'] == 'Tag deleted'
|
82
|
+
end
|
83
|
+
|
84
|
+
# Public: Get a list of countries of origin for a given domain for different event types.
|
85
|
+
#
|
86
|
+
# domain - [String] Domain name where tag is stored
|
87
|
+
# tag - [String] Tag name to lookup for
|
88
|
+
#
|
89
|
+
# Returns [Hash] of countries of origin for a given domain
|
90
|
+
def get_countries_aggregated_stats(domain, tag)
|
91
|
+
fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
92
|
+
fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
93
|
+
@client.get("#{domain}/tags/#{tag}/stats/aggregates/countries").to_h
|
94
|
+
end
|
95
|
+
|
96
|
+
# Public: Get a list of email providers for a given domain for different event types
|
97
|
+
#
|
98
|
+
# domain - [String] Domain name where tag is stored
|
99
|
+
# tag - [String] Tag name to lookup for
|
100
|
+
#
|
101
|
+
# Returns [Hash] of email providers for a given domain
|
102
|
+
def get_providers_aggregated_stats(domain, tag)
|
103
|
+
fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
104
|
+
fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
105
|
+
@client.get("#{domain}/tags/#{tag}/stats/aggregates/providers").to_h
|
106
|
+
end
|
107
|
+
|
108
|
+
# Public: Get a list of devices for a given domain that have triggered event types.
|
109
|
+
#
|
110
|
+
# domain - [String] Domain name where tag is stored
|
111
|
+
# tag - [String] Tag name to lookup for
|
112
|
+
#
|
113
|
+
# Returns [Hash] of devices for a given domain
|
114
|
+
def get_devices_aggregated_stats(domain, tag)
|
115
|
+
fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
116
|
+
fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
117
|
+
@client.get("#{domain}/tags/#{tag}/stats/aggregates/devices").to_h
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/mailgun/version.rb
CHANGED
@@ -3,6 +3,7 @@ module Mailgun
|
|
3
3
|
# A Mailgun::Webhooks object is a simple CRUD interface to Mailgun Webhooks.
|
4
4
|
# Uses Mailgun
|
5
5
|
class Webhooks
|
6
|
+
ACTIONS = %w(accepted clicked complained delivered opened permanent_fail temporary_fail unsubscribed).freeze
|
6
7
|
|
7
8
|
# Public creates a new Mailgun::Webhooks instance.
|
8
9
|
# Defaults to Mailgun::Client
|
@@ -31,7 +32,7 @@ module Mailgun
|
|
31
32
|
# empty String if one is not set
|
32
33
|
def info(domain, action)
|
33
34
|
res = @client.get("domains/#{domain}/webhooks/#{action}")
|
34
|
-
res.to_h['webhook']['
|
35
|
+
res.to_h['webhook']['urls'] || ''
|
35
36
|
rescue NoMethodError
|
36
37
|
''
|
37
38
|
end
|
@@ -46,7 +47,7 @@ module Mailgun
|
|
46
47
|
# Returns a Boolean of whether the webhook was created
|
47
48
|
def create(domain, action, url = '')
|
48
49
|
res = @client.post("domains/#{domain}/webhooks", id: action, url: url)
|
49
|
-
res.to_h['webhook']['
|
50
|
+
res.to_h['webhook']['urls'].include?(url) && res.to_h['message'] == 'Webhook has been created'
|
50
51
|
end
|
51
52
|
alias_method :add, :create
|
52
53
|
alias_method :add_webhook, :create
|
@@ -58,7 +59,7 @@ module Mailgun
|
|
58
59
|
#
|
59
60
|
# Returns true or false
|
60
61
|
def create_all(domain, url = '')
|
61
|
-
|
62
|
+
ACTIONS.each do |action|
|
62
63
|
add_webhook domain, action, url
|
63
64
|
end
|
64
65
|
true
|
@@ -67,6 +68,21 @@ module Mailgun
|
|
67
68
|
end
|
68
69
|
alias_method :add_all_webhooks, :create_all
|
69
70
|
|
71
|
+
# Public: Update webhook
|
72
|
+
#
|
73
|
+
# domain - A String of the domain name (ex. domain.com)
|
74
|
+
# action - A String of the action to create a webhook for
|
75
|
+
# url - A String of the url of the webhook
|
76
|
+
#
|
77
|
+
# Returns a Boolean of whether the webhook was updated
|
78
|
+
def update(domain, action, url = '')
|
79
|
+
fail Mailgun::ParameterError('Domain not provided to update webhooks') unless domain
|
80
|
+
fail Mailgun::ParameterError('Action not provided to identify webhook to update') unless action
|
81
|
+
res = @client.put("domains/#{domain}/webhooks/#{action}", id: action, url: url)
|
82
|
+
res.to_h['webhook']['urls'] == url && res.to_h['message'] == 'Webhook has been updated'
|
83
|
+
end
|
84
|
+
alias_method :update_webhook, :update
|
85
|
+
|
70
86
|
# Public: Delete a specific webhook
|
71
87
|
#
|
72
88
|
# domain - The required String of domain name
|
@@ -90,7 +106,7 @@ module Mailgun
|
|
90
106
|
# Returns a Boolean on the success
|
91
107
|
def remove_all(domain)
|
92
108
|
fail Mailgun::ParameterError('Domain not provided to remove webhooks from') unless domain
|
93
|
-
|
109
|
+
ACTIONS.each do |action|
|
94
110
|
delete_webhook domain, action
|
95
111
|
end
|
96
112
|
end
|
data/lib/mailgun.rb
CHANGED
data/lib/railgun/mailer.rb
CHANGED
@@ -173,6 +173,7 @@ module Railgun
|
|
173
173
|
mb.subject mail.subject
|
174
174
|
mb.body_html extract_body_html(mail)
|
175
175
|
mb.body_text extract_body_text(mail)
|
176
|
+
mb.amp_html extract_amp_html(mail)
|
176
177
|
|
177
178
|
[:to, :cc, :bcc].each do |rcpt_type|
|
178
179
|
addrs = mail[rcpt_type] || nil
|
@@ -232,6 +233,20 @@ module Railgun
|
|
232
233
|
end
|
233
234
|
end
|
234
235
|
|
236
|
+
# Returns the decoded AMP HTML from the Mail::Message object if it is available,
|
237
|
+
# otherwise nil.
|
238
|
+
#
|
239
|
+
# @param [Mail::Message] mail message to transform
|
240
|
+
#
|
241
|
+
# @return [String]
|
242
|
+
def extract_amp_html(mail)
|
243
|
+
begin
|
244
|
+
retrieve_amp_part(mail).body.decoded || nil
|
245
|
+
rescue
|
246
|
+
nil
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
235
250
|
# Returns the mail object from the Mail::Message object if text part exists,
|
236
251
|
# (decomposing multipart into individual format if necessary)
|
237
252
|
# otherwise nil.
|
@@ -255,4 +270,18 @@ module Railgun
|
|
255
270
|
return mail.html_part if mail.multipart?
|
256
271
|
(mail.mime_type =~ /^text\/html$/i) && mail
|
257
272
|
end
|
273
|
+
|
274
|
+
# Returns the mail object from the Mail::Message object if AMP part exists,
|
275
|
+
# (decomposing multipart into individual format if necessary)
|
276
|
+
# otherwise nil.
|
277
|
+
#
|
278
|
+
# @param [Mail::Message] mail message to transform
|
279
|
+
#
|
280
|
+
# @return [Mail::Message] mail message with its content-type = text/x-amp-html
|
281
|
+
def retrieve_amp_part(mail)
|
282
|
+
# AMP emails should always be multipart, with an HTML fallback.
|
283
|
+
return unless mail.multipart?
|
284
|
+
|
285
|
+
mail.find_first_mime_type('text/x-amp-html')
|
286
|
+
end
|
258
287
|
end
|