mailgun-ruby 1.2.15 → 1.3.5
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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +52 -3
- data/Gemfile +1 -0
- data/README.md +2 -2
- data/docs/MessageBuilder.md +12 -0
- data/docs/Metrics.md +108 -0
- data/docs/Webhooks.md +4 -2
- data/lib/mailgun/chains.rb +1 -1
- data/lib/mailgun/client.rb +40 -30
- data/lib/mailgun/domains/domains.rb +19 -0
- data/lib/mailgun/events/events.rb +4 -4
- data/lib/mailgun/exceptions/exceptions.rb +7 -7
- data/lib/mailgun/messages/message_builder.rb +14 -2
- data/lib/mailgun/metrics/metrics.rb +61 -0
- data/lib/mailgun/response.rb +11 -10
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun.rb +2 -1
- data/mailgun.gemspec +6 -3
- data/spec/integration/domains_spec.rb +95 -92
- data/spec/integration/email_validation_spec.rb +2 -1
- data/spec/integration/list_spec.rb +1 -1
- data/spec/integration/mailer_spec.rb +5 -5
- data/spec/integration/mailgun_spec.rb +14 -12
- data/spec/integration/metrics_spec.rb +218 -0
- data/spec/integration/routes_spec.rb +17 -1
- data/spec/integration/stats_spec.rb +1 -1
- data/spec/integration/unsubscribes_spec.rb +2 -2
- data/spec/integration/webhook_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/connection/test_client.rb +1 -1
- data/spec/unit/events/events_spec.rb +1 -1
- data/spec/unit/exceptions/exceptions_spec.rb +3 -3
- data/spec/unit/messages/message_builder_spec.rb +4 -3
- data/vcr_cassettes/bounces.yml +59 -98
- data/vcr_cassettes/complaints.yml +237 -97
- data/vcr_cassettes/domains.yml +332 -763
- data/vcr_cassettes/email_validation.yml +81 -144
- data/vcr_cassettes/events.yml +24 -63
- data/vcr_cassettes/exceptions.yml +49 -2
- data/vcr_cassettes/list_members.yml +187 -179
- data/vcr_cassettes/mailing_list.yml +309 -17
- data/vcr_cassettes/metrics.yml +116 -0
- data/vcr_cassettes/routes.yml +246 -246
- data/vcr_cassettes/send_message.yml +54 -3
- data/vcr_cassettes/stats.yml +28 -24
- data/vcr_cassettes/suppressions.yml +229 -447
- data/vcr_cassettes/unsubscribes.yml +219 -9
- metadata +58 -15
- data/docs/Messages.md +0 -107
- /data/docs/{railgun/Templates.md → Templates.md} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c3decbf9e3cc421d067f05661560a6677c8873792b2895f6ee04ef52aa81323
|
4
|
+
data.tar.gz: 86eda44ce14d19c5c52c8e48671210b36bb8b1d7989756679dad3e087a398690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2af34e19834467ba23ebaf6052a9af8ef6e8e49106128cdcd47a1dc693792af2ea4a543dde46c1f5896df4cc13579cb2c470bd788f40ecd6652bdfa9ba1a9049
|
7
|
+
data.tar.gz: de3d99329bdd5427ef09557f8b4aaac8e285fdaafc196d76be84e4a61a3d67cfbb3bd3112d2b4f2b0fa35b2233ee2f6ffa6e517bcbec0cddb0116a8b1dcdfd6e
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,57 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [
|
5
|
+
## [1.3.5] - 2025-04-07
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
- Set attachment filename on upload IO (https://github.com/mailgun/mailgun-ruby/pull/351)
|
10
|
+
|
11
|
+
## [1.3.4] - 2025-03-28
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Increase max tag limit to 10 per message (https://github.com/mailgun/mailgun-ruby/pull/350)
|
16
|
+
|
17
|
+
## [1.3.3] - 2025-03-25
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Fix specs (https://github.com/mailgun/mailgun-ruby/pull/345)
|
22
|
+
- Fix sending attachments via faraday (https://github.com/mailgun/mailgun-ruby/pull/347)
|
23
|
+
|
24
|
+
## [1.3.2] - 2025-01-30
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
|
28
|
+
- Use Faraday::FlatParamsEncoder (https://github.com/mailgun/mailgun-ruby/pull/334)
|
29
|
+
- Update Message Builder doc (https://github.com/mailgun/mailgun-ruby/pull/338)
|
30
|
+
- Add Domain api version warnings (https://github.com/mailgun/mailgun-ruby/pull/339)
|
31
|
+
|
32
|
+
## [1.3.1] - 2025-01-26
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
- Fix mock mailgun responds (https://github.com/mailgun/mailgun-ruby/pull/331)
|
37
|
+
- Change mime-types to runtime dependency (https://github.com/mailgun/mailgun-ruby/pull/332)
|
38
|
+
|
39
|
+
## [1.3.0] - 2025-01-26
|
40
|
+
|
41
|
+
### Added
|
42
|
+
|
43
|
+
- Faraday as http client (https://github.com/mailgun/mailgun-ruby/pull/330)
|
44
|
+
|
45
|
+
### Fixed
|
46
|
+
|
47
|
+
- Added documentation for updating webhook (https://github.com/mailgun/mailgun-ruby/pull/325)
|
48
|
+
- Remove duplicated entry from CHANGELOG (https://github.com/mailgun/mailgun-ruby/pull/318)
|
49
|
+
- Update template and metrics docs (https://github.com/mailgun/mailgun-ruby/pull/329)
|
50
|
+
|
51
|
+
## [1.2.16] - 2024-11-29
|
52
|
+
|
53
|
+
### Added
|
54
|
+
|
55
|
+
- Metrics API support (https://github.com/mailgun/mailgun-ruby/pull/326)
|
6
56
|
|
7
57
|
## [1.2.15] - 2024-02-13
|
8
58
|
|
@@ -19,7 +69,6 @@ All notable changes to this project will be documented in this file.
|
|
19
69
|
- Additional Domain Endpoints (https://github.com/mailgun/mailgun-ruby/pull/314)
|
20
70
|
- Webhooks Update Method (https://github.com/mailgun/mailgun-ruby/pull/305)
|
21
71
|
- Add support for AMP HTML (https://github.com/mailgun/mailgun-ruby/pull/304)
|
22
|
-
- Add support for AMP HTML (https://github.com/mailgun/mailgun-ruby/pull/304)
|
23
72
|
|
24
73
|
### Fixed
|
25
74
|
|
@@ -40,4 +89,4 @@ All notable changes to this project will be documented in this file.
|
|
40
89
|
### Fixed
|
41
90
|
|
42
91
|
- transform_for_mailgun block iteration issue (https://github.com/mailgun/mailgun-ruby/pull/298).
|
43
|
-
- Typos in several files (https://github.com/mailgun/mailgun-ruby/pull/297).
|
92
|
+
- Typos in several files (https://github.com/mailgun/mailgun-ruby/pull/297).
|
data/Gemfile
CHANGED
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
|
22
|
+
gem 'mailgun-ruby', '~>1.3.2'
|
23
23
|
```
|
24
24
|
|
25
25
|
Usage
|
@@ -181,7 +181,6 @@ For usage examples on each API endpoint, head over to our official documentation
|
|
181
181
|
pages. Or the [Snippets](docs/Snippets.md) file.
|
182
182
|
|
183
183
|
This SDK includes the following components:
|
184
|
-
- [Messages](docs/Messages.md)
|
185
184
|
- [Message Builder](docs/MessageBuilder.md)
|
186
185
|
- [Batch Message](docs/MessageBuilder.md#usage---batch-message)
|
187
186
|
- [Opt-In Handler](docs/OptInHandler.md)
|
@@ -193,6 +192,7 @@ This SDK includes the following components:
|
|
193
192
|
- [Suppressions](docs/Suppressions.md)
|
194
193
|
- [Templates](docs/Templates.md)
|
195
194
|
- [EmailValidation](docs/EmailValidation.md)
|
195
|
+
- [Metrics](docs/Metrics.md)
|
196
196
|
|
197
197
|
Message Builder allows you to quickly create the array of parameters, required
|
198
198
|
to send a message, by calling a methods for each parameter.
|
data/docs/MessageBuilder.md
CHANGED
@@ -31,12 +31,18 @@ mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John", "last" =>
|
|
31
31
|
# Define a cc recipient.
|
32
32
|
mb_obj.add_recipient(:cc, "sally.doe@example.com", {"first" => "Sally", "last" => "Doe"});
|
33
33
|
|
34
|
+
# Define the reply-to address.
|
35
|
+
mb_obj.reply_to("bob.doe@example.com", {"first" => "Bob", "last" => "Doe"});
|
36
|
+
|
34
37
|
# Define the subject.
|
35
38
|
mb_obj.subject("A message from the Ruby SDK using Message Builder!");
|
36
39
|
|
37
40
|
# Define the body of the message.
|
38
41
|
mb_obj.body_text("This is the text body of the message!");
|
39
42
|
|
43
|
+
# Define the HTML text of the message
|
44
|
+
mb_obj.body_html("<html><body><p>This is the text body of the message</p></body></html>");
|
45
|
+
|
40
46
|
# Set the Message-Id header, provide a valid Message-Id.
|
41
47
|
mb_obj.message_id("<20141014000000.11111.11111@example.com>")
|
42
48
|
|
@@ -63,6 +69,12 @@ mb_obj.add_inline_image "/path/to/file/header.png"
|
|
63
69
|
# Schedule message in the future
|
64
70
|
mb_obj.deliver_at("tomorrow 8:00AM PST");
|
65
71
|
|
72
|
+
# Turn Click Tracking on
|
73
|
+
mb_obj.track_clicks(true)
|
74
|
+
|
75
|
+
# Turn Click Tracking off
|
76
|
+
mb_obj.track_clicks(false)
|
77
|
+
|
66
78
|
# Finally, send your message using the client
|
67
79
|
result = mg_client.send_message("sending_domain.com", mb_obj)
|
68
80
|
|
data/docs/Metrics.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
Mailgun - Metrics
|
2
|
+
====================
|
3
|
+
|
4
|
+
This is the Mailgun Ruby *Metrics* 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. It currently supports
|
8
|
+
all calls except credentials.
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
Mailgun collects many different events and generates event metrics which are available
|
13
|
+
in your Control Panel. This data is also available via our analytics metrics API endpoint.
|
14
|
+
|
15
|
+
You can view additional samples in the [metrics_spec.rb](/spec/integration/metrics_spec.rb)
|
16
|
+
or the Metrics client API in [metrics.rb](/lib/metrics/metrics.rb).
|
17
|
+
|
18
|
+
Usage
|
19
|
+
-----
|
20
|
+
|
21
|
+
To get an instance of the Metrics client:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'mailgun'
|
25
|
+
|
26
|
+
mg_client = Mailgun::Client.new('your-api-key', 'mailgun-api-host', 'v1')
|
27
|
+
metrics = Mailgun::Metrics.new(mg_client)
|
28
|
+
````
|
29
|
+
---
|
30
|
+
Get filtered metrics for an account:
|
31
|
+
```ruby
|
32
|
+
options = {
|
33
|
+
{
|
34
|
+
resolution: 'hour',
|
35
|
+
metrics: [
|
36
|
+
'accepted_count',
|
37
|
+
'delivered_count',
|
38
|
+
'clicked_rate',
|
39
|
+
'opened_rate'
|
40
|
+
],
|
41
|
+
include_aggregates: true,
|
42
|
+
start: 'Tue, 26 Nov 2024 20:56:50 -0500',
|
43
|
+
duration: '1m',
|
44
|
+
filter: {
|
45
|
+
AND: [
|
46
|
+
{
|
47
|
+
attribute: 'domain',
|
48
|
+
comparator: '!=',
|
49
|
+
values: [
|
50
|
+
{
|
51
|
+
label: 'example.com',
|
52
|
+
value: 'example.com'
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
56
|
+
]
|
57
|
+
},
|
58
|
+
dimensions: ['time'],
|
59
|
+
end: 'Tue, 30 Nov 2024 20:56:50 -0500',
|
60
|
+
include_subaccounts: true
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
metrics.account_metrics(options)
|
65
|
+
```
|
66
|
+
---
|
67
|
+
|
68
|
+
Get filtered usage metrics for an account:
|
69
|
+
```ruby
|
70
|
+
options = {
|
71
|
+
resolution: 'hour',
|
72
|
+
metrics: [
|
73
|
+
'accepted_count',
|
74
|
+
'delivered_count',
|
75
|
+
'clicked_rate',
|
76
|
+
'opened_rate'
|
77
|
+
],
|
78
|
+
include_aggregates: true,
|
79
|
+
start: 'Tue, 26 Nov 2024 20:56:50 -0500',
|
80
|
+
duration: '1m',
|
81
|
+
filter: {
|
82
|
+
AND: [
|
83
|
+
{
|
84
|
+
attribute: 'domain',
|
85
|
+
comparator: '!=',
|
86
|
+
values: [
|
87
|
+
{
|
88
|
+
label: 'example.com',
|
89
|
+
value: 'example.com'
|
90
|
+
}
|
91
|
+
]
|
92
|
+
}
|
93
|
+
]
|
94
|
+
},
|
95
|
+
dimensions: ['time'],
|
96
|
+
end: 'Tue, 30 Nov 2024 20:56:50 -0500',
|
97
|
+
include_subaccounts: true
|
98
|
+
}
|
99
|
+
|
100
|
+
metrics.account_usage_metrics(options)
|
101
|
+
```
|
102
|
+
|
103
|
+
---
|
104
|
+
|
105
|
+
More Documentation
|
106
|
+
------------------
|
107
|
+
See the official [Mailgun Domain Docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/)
|
108
|
+
for more information
|
data/docs/Webhooks.md
CHANGED
@@ -4,8 +4,7 @@ Mailgun - Webhooks
|
|
4
4
|
This is the Mailgun Ruby *Webhook* utilities.
|
5
5
|
|
6
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
|
-
all calls except updating webhooks.
|
7
|
+
project. If not, go back to the master README for instructions.
|
9
8
|
|
10
9
|
Usage - Webhooks
|
11
10
|
-----------------------
|
@@ -27,6 +26,9 @@ hook.create_all 'my.perfect.domain', 'https://the.webhook.url/'
|
|
27
26
|
# Add a url for a specific webhook
|
28
27
|
hook.create 'my.perfect.domain', 'deliver', 'https://the.webhook.url/'
|
29
28
|
|
29
|
+
# Update the url for a specific webhook
|
30
|
+
hook.update 'my.perfect.domain', 'deliver', 'https://the.webhook.url/'
|
31
|
+
|
30
32
|
# Remove a url for a specific webhook
|
31
33
|
hook.remove 'my.perfect.domain', 'deliver'
|
32
34
|
|
data/lib/mailgun/chains.rb
CHANGED
data/lib/mailgun/client.rb
CHANGED
@@ -19,16 +19,28 @@ module Mailgun
|
|
19
19
|
timeout = nil,
|
20
20
|
proxy_url = Mailgun.proxy_url)
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
endpoint = endpoint_generator(api_host, api_version, ssl)
|
23
|
+
|
24
|
+
request_options = {
|
25
|
+
url: endpoint,
|
26
|
+
proxy: Mailgun.proxy_url,
|
27
|
+
ssl: {verify: ssl},
|
28
|
+
headers: {
|
29
|
+
'User-Agent' => "mailgun-sdk-ruby/#{Mailgun::VERSION}",
|
30
|
+
'Accept' =>'*/*'
|
31
|
+
}
|
26
32
|
}
|
27
|
-
|
33
|
+
request_options.merge!(request: {timeout: timeout}) if timeout
|
34
|
+
|
35
|
+
@http_client = Faraday.new(request_options) do |conn|
|
36
|
+
conn.request :multipart
|
37
|
+
conn.request :authorization, :basic, 'api', api_key
|
38
|
+
conn.request :url_encoded
|
39
|
+
conn.response :raise_error, include_request: true
|
40
|
+
conn.adapter Faraday.default_adapter
|
41
|
+
conn.options.params_encoder = Faraday::FlatParamsEncoder
|
42
|
+
end
|
28
43
|
|
29
|
-
endpoint = endpoint_generator(api_host, api_version, ssl)
|
30
|
-
RestClient.proxy = proxy_url
|
31
|
-
@http_client = RestClient::Resource.new(endpoint, rest_client_params)
|
32
44
|
@test_mode = test_mode
|
33
45
|
@api_version = api_version
|
34
46
|
end
|
@@ -49,17 +61,17 @@ module Mailgun
|
|
49
61
|
|
50
62
|
# Change API key
|
51
63
|
def set_api_key(api_key)
|
52
|
-
@http_client.
|
64
|
+
@http_client.set_basic_auth('api', api_key)
|
53
65
|
end
|
54
66
|
|
55
67
|
# Add subaccount id to headers
|
56
68
|
def set_subaccount(subaccount_id)
|
57
|
-
@http_client.
|
69
|
+
@http_client.headers = @http_client.headers.merge!({ SUBACCOUNT_HEADER => subaccount_id })
|
58
70
|
end
|
59
71
|
|
60
72
|
# Reset subaccount for primary usage
|
61
73
|
def reset_subaccount
|
62
|
-
@http_client.
|
74
|
+
@http_client.headers.delete(SUBACCOUNT_HEADER)
|
63
75
|
end
|
64
76
|
|
65
77
|
# Client is in test mode?
|
@@ -95,7 +107,7 @@ module Mailgun
|
|
95
107
|
return Response.from_hash(
|
96
108
|
{
|
97
109
|
:body => "{\"id\": \"test-mode-mail-#{SecureRandom.uuid}@localhost\", \"message\": \"Queued. Thank you.\"}",
|
98
|
-
:
|
110
|
+
:status => 200,
|
99
111
|
}
|
100
112
|
)
|
101
113
|
end
|
@@ -130,7 +142,7 @@ module Mailgun
|
|
130
142
|
# @param [Hash] headers Additional headers to pass to the resource.
|
131
143
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
132
144
|
def post(resource_path, data, headers = {})
|
133
|
-
response = @http_client
|
145
|
+
response = @http_client.post(resource_path, data, headers)
|
134
146
|
Response.new(response)
|
135
147
|
rescue => err
|
136
148
|
raise communication_error err
|
@@ -138,21 +150,19 @@ module Mailgun
|
|
138
150
|
|
139
151
|
# Generic Mailgun GET Handler
|
140
152
|
#
|
141
|
-
# @param [String] resource_path
|
142
|
-
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
# @
|
146
|
-
# @
|
147
|
-
def get(resource_path, params =
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
response = @http_client[resource_path].get(accept: accept)
|
152
|
-
end
|
153
|
+
# @param [String] resource_path The API resource path to request, including the domain if required.
|
154
|
+
# @param [Hash] params Optional request parameters, including query parameters and headers.
|
155
|
+
# - `:headers` [Hash] (optional) Custom headers for the request.
|
156
|
+
# @param [String] accept The expected Content-Type of the response. Defaults to '*/*'.
|
157
|
+
# @return [Mailgun::Response] A response object containing the API response data.
|
158
|
+
# @raise [CommunicationError] If the request fails, raises a communication error.
|
159
|
+
def get(resource_path, params = {}, accept = '*/*')
|
160
|
+
headers = (params[:headers] || {}).merge(accept: accept)
|
161
|
+
response = @http_client.get(resource_path, params, headers)
|
162
|
+
|
153
163
|
Response.new(response)
|
154
164
|
rescue => err
|
155
|
-
raise communication_error
|
165
|
+
raise communication_error(err)
|
156
166
|
end
|
157
167
|
|
158
168
|
# Generic Mailgun PUT Handler
|
@@ -163,7 +173,7 @@ module Mailgun
|
|
163
173
|
# containing required parameters for the requested resource.
|
164
174
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
165
175
|
def put(resource_path, data)
|
166
|
-
response = @http_client
|
176
|
+
response = @http_client.put(resource_path, data)
|
167
177
|
Response.new(response)
|
168
178
|
rescue => err
|
169
179
|
raise communication_error err
|
@@ -176,9 +186,9 @@ module Mailgun
|
|
176
186
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
177
187
|
def delete(resource_path, params = nil)
|
178
188
|
if params
|
179
|
-
response = @http_client
|
189
|
+
response = @http_client.delete(resource_path, params: params)
|
180
190
|
else
|
181
|
-
response = @http_client
|
191
|
+
response = @http_client.delete(resource_path)
|
182
192
|
end
|
183
193
|
Response.new(response)
|
184
194
|
rescue => err
|
@@ -227,7 +237,7 @@ module Mailgun
|
|
227
237
|
# @param [StandardException] e upstream exception object
|
228
238
|
def communication_error(e)
|
229
239
|
if e.respond_to?(:response) && e.response
|
230
|
-
return case e.
|
240
|
+
return case e.response_status
|
231
241
|
when Unauthorized::CODE
|
232
242
|
Unauthorized.new(e.message, e.response)
|
233
243
|
when BadRequest::CODE
|
@@ -19,6 +19,7 @@ module Mailgun
|
|
19
19
|
#
|
20
20
|
# Returns [Array] A list of domains (hash)
|
21
21
|
def list(options = {})
|
22
|
+
warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
|
22
23
|
@client.get('domains', options).to_h['items']
|
23
24
|
end
|
24
25
|
alias_method :get_domains, :list
|
@@ -29,6 +30,7 @@ module Mailgun
|
|
29
30
|
#
|
30
31
|
# Returns [Hash] Information on the requested domains.
|
31
32
|
def info(domain)
|
33
|
+
warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
|
32
34
|
fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
33
35
|
@client.get("domains/#{domain}").to_h!
|
34
36
|
end
|
@@ -43,6 +45,7 @@ module Mailgun
|
|
43
45
|
#
|
44
46
|
# Returns [Hash] Information on the updated/verified domains
|
45
47
|
def verify(domain)
|
48
|
+
warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
|
46
49
|
fail(ParameterError, 'No domain given to verify on Mailgun', caller) unless domain
|
47
50
|
@client.put("domains/#{domain}/verify", nil).to_h!
|
48
51
|
end
|
@@ -61,6 +64,7 @@ module Mailgun
|
|
61
64
|
#
|
62
65
|
# Returns [Hash] of created domain
|
63
66
|
def create(domain, options = {})
|
67
|
+
warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
|
64
68
|
fail(ParameterError, 'No domain given to add on Mailgun', caller) unless domain
|
65
69
|
options = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge(options)
|
66
70
|
options[:name] = domain
|
@@ -75,6 +79,7 @@ module Mailgun
|
|
75
79
|
#
|
76
80
|
# Returns [Boolean] if successful or not
|
77
81
|
def remove(domain)
|
82
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
78
83
|
fail(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
|
79
84
|
@client.delete("domains/#{domain}").to_h['message'] == 'Domain has been deleted'
|
80
85
|
end
|
@@ -95,6 +100,7 @@ module Mailgun
|
|
95
100
|
#
|
96
101
|
# Returns [Hash] of updated domain
|
97
102
|
def update(domain, options = {})
|
103
|
+
warn('WARN: Client api version must be v4') unless @client.api_version == 'v4'
|
98
104
|
fail(ParameterError, 'No domain given to update on Mailgun', caller) unless domain
|
99
105
|
@client.put("domains/#{domain}", options).to_h
|
100
106
|
end
|
@@ -108,6 +114,7 @@ module Mailgun
|
|
108
114
|
#
|
109
115
|
# Returns [Hash] with message key
|
110
116
|
def create_smtp_credentials(domain, options = {})
|
117
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
111
118
|
fail(ParameterError, 'No domain given to create credentials on Mailgun', caller) unless domain
|
112
119
|
@client.post("domains/#{domain}/credentials", options).to_h
|
113
120
|
end
|
@@ -121,6 +128,7 @@ module Mailgun
|
|
121
128
|
#
|
122
129
|
# Returns [Hash] with message key
|
123
130
|
def update_smtp_credentials(domain, login, options = {})
|
131
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
124
132
|
fail(ParameterError, 'No domain given to update credentials on Mailgun', caller) unless domain
|
125
133
|
fail(ParameterError, 'No login given to update credentials on Mailgun', caller) unless login
|
126
134
|
@client.put("domains/#{domain}/credentials/#{login}", options).to_h
|
@@ -133,6 +141,7 @@ module Mailgun
|
|
133
141
|
#
|
134
142
|
# Returns [Hash] with message and spec keys
|
135
143
|
def delete_smtp_credentials(domain, login)
|
144
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
136
145
|
fail(ParameterError, 'No domain given to delete credentials on Mailgun', caller) unless domain
|
137
146
|
fail(ParameterError, 'No login given to delete credentials on Mailgun', caller) unless login
|
138
147
|
@client.delete("domains/#{domain}/credentials/#{login}").to_h
|
@@ -144,6 +153,7 @@ module Mailgun
|
|
144
153
|
#
|
145
154
|
# Returns [Hash] Information on the delivery connection settings
|
146
155
|
def get_domain_connection_settings(domain)
|
156
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
147
157
|
fail(ParameterError, 'No domain given to retrieve connections on Mailgun', caller) unless domain
|
148
158
|
@client.get("domains/#{domain}/connection").to_h
|
149
159
|
end
|
@@ -158,6 +168,7 @@ module Mailgun
|
|
158
168
|
#
|
159
169
|
# Returns [Hash] Information on the delivery connection settings
|
160
170
|
def update_domain_connection_settings(domain, options = {})
|
171
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
161
172
|
fail(ParameterError, 'No domain given to update connections on Mailgun', caller) unless domain
|
162
173
|
@client.put("domains/#{domain}/connection", options).to_h
|
163
174
|
end
|
@@ -168,6 +179,7 @@ module Mailgun
|
|
168
179
|
#
|
169
180
|
# Returns [Hash] Information on the tracking settings
|
170
181
|
def get_domain_tracking_settings(domain)
|
182
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
171
183
|
fail(ParameterError, 'No domain given to retrieve tracking settings on Mailgun', caller) unless domain
|
172
184
|
@client.get("domains/#{domain}/tracking").to_h
|
173
185
|
end
|
@@ -181,6 +193,7 @@ module Mailgun
|
|
181
193
|
#
|
182
194
|
# Returns [Hash] Information on the tracking open settings
|
183
195
|
def update_domain_tracking_open_settings(domain, options = {})
|
196
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
184
197
|
fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
|
185
198
|
@client.put("domains/#{domain}/tracking/open", options).to_h
|
186
199
|
end
|
@@ -193,6 +206,7 @@ module Mailgun
|
|
193
206
|
#
|
194
207
|
# Returns [Hash] Information on the tracking click settings
|
195
208
|
def update_domain_tracking_click_settings(domain, options = {})
|
209
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
196
210
|
fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
|
197
211
|
@client.put("domains/#{domain}/tracking/click", options).to_h
|
198
212
|
end
|
@@ -207,6 +221,7 @@ module Mailgun
|
|
207
221
|
#
|
208
222
|
# Returns [Hash] Information on the tracking unsubscribe settings
|
209
223
|
def update_domain_tracking_unsubscribe_settings(domain, options = {})
|
224
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
210
225
|
fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
|
211
226
|
@client.put("domains/#{domain}/tracking/unsubscribe", options).to_h
|
212
227
|
end
|
@@ -220,6 +235,7 @@ module Mailgun
|
|
220
235
|
#
|
221
236
|
# Returns [Hash] Information on the DKIM authority
|
222
237
|
def update_domain_dkim_authority(domain, options = {})
|
238
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
223
239
|
fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
|
224
240
|
@client.put("domains/#{domain}/dkim_authority", options).to_h
|
225
241
|
end
|
@@ -232,6 +248,7 @@ module Mailgun
|
|
232
248
|
#
|
233
249
|
# Returns [Hash] with message key
|
234
250
|
def update_domain_dkim_selector(domain, options = {})
|
251
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
235
252
|
fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
|
236
253
|
@client.put("domains/#{domain}/dkim_selector", options).to_h
|
237
254
|
end
|
@@ -244,6 +261,7 @@ module Mailgun
|
|
244
261
|
#
|
245
262
|
# Returns [Hash] with message key
|
246
263
|
def update_domain_web_prefix(domain, options = {})
|
264
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
247
265
|
fail(ParameterError, 'No domain given to update tracking settings on Mailgun', caller) unless domain
|
248
266
|
@client.put("domains/#{domain}/web_prefix", options).to_h
|
249
267
|
end
|
@@ -323,6 +341,7 @@ module Mailgun
|
|
323
341
|
#
|
324
342
|
# Returns [Array] A list of domains (hash)
|
325
343
|
def get_domain_stats(domain, options = {})
|
344
|
+
warn('WARN: Client api version must be v3') unless @client.api_version == 'v3'
|
326
345
|
fail(ParameterError, 'No domain given to list stats on Mailgun', caller) unless domain
|
327
346
|
@client.get("#{domain}/stats/total", options).to_h
|
328
347
|
end
|
@@ -29,7 +29,7 @@ module Mailgun
|
|
29
29
|
# params - a Hash of query options and/or filters.
|
30
30
|
#
|
31
31
|
# Returns a Mailgun::Response object.
|
32
|
-
def get(params =
|
32
|
+
def get(params = {})
|
33
33
|
self.next(params)
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ module Mailgun
|
|
40
40
|
# params - a Hash of query options and/or filters.
|
41
41
|
#
|
42
42
|
# Returns a Mailgun::Response object.
|
43
|
-
def next(params =
|
43
|
+
def next(params = {})
|
44
44
|
get_events(params, @paging_next)
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ module Mailgun
|
|
51
51
|
# params - a Hash of query options and/or filters.
|
52
52
|
#
|
53
53
|
# Returns Mailgun::Response object.
|
54
|
-
def previous(params =
|
54
|
+
def previous(params = {})
|
55
55
|
get_events(params, @paging_previous)
|
56
56
|
end
|
57
57
|
|
@@ -75,7 +75,7 @@ module Mailgun
|
|
75
75
|
# paging - the URL key used for previous/next requests
|
76
76
|
#
|
77
77
|
# Returns a Mailgun.Response object.
|
78
|
-
def get_events(params =
|
78
|
+
def get_events(params = {}, paging = nil)
|
79
79
|
response = @client.get(construct_url(paging), params)
|
80
80
|
extract_paging(response)
|
81
81
|
response
|
@@ -29,10 +29,10 @@ module Mailgun
|
|
29
29
|
# Public: Class for managing communications (eg http) response errors
|
30
30
|
# Inherits from Mailgun::Error
|
31
31
|
class CommunicationError < Error
|
32
|
-
# Public: gets HTTP status
|
33
|
-
attr_reader :
|
32
|
+
# Public: gets HTTP status status
|
33
|
+
attr_reader :status
|
34
34
|
|
35
|
-
# Public: fallback if there is no response
|
35
|
+
# Public: fallback if there is no response status on the object
|
36
36
|
NOCODE = 000
|
37
37
|
FORBIDDEN = 'Forbidden'
|
38
38
|
|
@@ -43,17 +43,17 @@ module Mailgun
|
|
43
43
|
#
|
44
44
|
def initialize(message = nil, response = nil)
|
45
45
|
@response = response
|
46
|
-
@
|
46
|
+
@status = if response.nil?
|
47
47
|
NOCODE
|
48
48
|
else
|
49
|
-
response.
|
49
|
+
response.status
|
50
50
|
end
|
51
51
|
|
52
52
|
begin
|
53
53
|
json = JSON.parse(response.body)
|
54
54
|
api_message = json['message'] || json['Error'] || json['error']
|
55
55
|
rescue JSON::ParserError
|
56
|
-
api_message = response.
|
56
|
+
api_message = response.response_body
|
57
57
|
rescue NoMethodError
|
58
58
|
api_message = "Unknown API error"
|
59
59
|
rescue
|
@@ -65,7 +65,7 @@ module Mailgun
|
|
65
65
|
|
66
66
|
super(message, response)
|
67
67
|
rescue NoMethodError, JSON::ParserError
|
68
|
-
@
|
68
|
+
@status = NOCODE
|
69
69
|
super(message, response)
|
70
70
|
end
|
71
71
|
end
|