mailgun-ruby 1.1.6 → 1.1.8
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/.ruby-version +1 -0
- data/README.md +11 -3
- data/docs/MessageBuilder.md +3 -0
- data/lib/mailgun/address.rb +5 -2
- data/lib/mailgun/events/events.rb +17 -6
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun/webhooks/webhooks.rb +1 -1
- data/lib/railgun/mailer.rb +5 -2
- data/spec/integration/email_validation_spec.rb +6 -0
- data/vcr_cassettes/email_validation.yml +57 -9
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03bb73706b0d179b3f48cfa58f68acc8b0d716e7
|
4
|
+
data.tar.gz: 3fc860e152511f367033a5954ba95720a474fd01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d1f7e536083087eb9c2423c8cb3cd54624b5d0a7fbfb96eb8740b06c2947c14d94542e6ef22439d0f0711d9627b5219e09b9ccab7408b454e20ad1531a07d56
|
7
|
+
data.tar.gz: 9e03a0244f385c15497856fe9c421d3d330a38309798313c88f3139a86b6fc163cf6234654e15a1c1faceca40b70ad590ff5caf02c3cefc2d225a4eb3bc2b852
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p0
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Usage
|
|
27
27
|
Here's how to send a message using the library:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
require 'mailgun'
|
30
|
+
require 'mailgun'
|
31
31
|
|
32
32
|
# First, instantiate the Mailgun Client with your API key
|
33
33
|
mg_client = Mailgun::Client.new 'your-api-key'
|
@@ -65,9 +65,9 @@ Mailgun.configure do |config|
|
|
65
65
|
config.api_key = 'your-secret-api-key'
|
66
66
|
end
|
67
67
|
```
|
68
|
-
Or have the initializer read your environment setting if you
|
68
|
+
Or have the initializer read your environment setting if you prefer.
|
69
69
|
|
70
|
-
To use as the ActionMailer delivery method, add this to your `config/environments/whatever.
|
70
|
+
To use as the ActionMailer delivery method, add this to your `config/environments/whatever.rb`
|
71
71
|
and replace `api-myapikey` and `mydomain.com` with your secret API key and domain, respectively:
|
72
72
|
```ruby
|
73
73
|
config.action_mailer.delivery_method = :mailgun
|
@@ -77,6 +77,14 @@ and replace `api-myapikey` and `mydomain.com` with your secret API key and domai
|
|
77
77
|
}
|
78
78
|
```
|
79
79
|
|
80
|
+
To get the Mailgun `message_id` after ActionMailer has successfully delivered the email:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
mailer = UserNotifier.welcome_email(current_user)
|
84
|
+
mailer_response = mailer.deliver_now
|
85
|
+
mailgun_message_id = mailer_response.message_id
|
86
|
+
```
|
87
|
+
|
80
88
|
Response
|
81
89
|
--------
|
82
90
|
|
data/docs/MessageBuilder.md
CHANGED
@@ -44,6 +44,9 @@ mb_obj.message_id("<20141014000000.11111.11111@example.com>")
|
|
44
44
|
mb_obj.message_id(nil)
|
45
45
|
mb_obj.message_id('')
|
46
46
|
|
47
|
+
# Set the Message-tags at most 3.
|
48
|
+
mb_obj.add_tag("You can track mails as tag-units!")
|
49
|
+
|
47
50
|
# Campaigns and headers.
|
48
51
|
mb_obj.add_campaign_id("My-Awesome-Campaign");
|
49
52
|
mb_obj.header("Customer-Id", "12345");
|
data/lib/mailgun/address.rb
CHANGED
@@ -18,8 +18,11 @@ module Mailgun
|
|
18
18
|
# Given an arbitrary address, validates it based on defined checks.
|
19
19
|
#
|
20
20
|
# @param [String] address Email address to validate (max 512 chars.)
|
21
|
-
def validate(address)
|
22
|
-
|
21
|
+
def validate(address, mailbox_verification = false)
|
22
|
+
params = {:address => address}
|
23
|
+
params[:mailbox_verification] = true if mailbox_verification
|
24
|
+
|
25
|
+
res = @client.get "address/validate", params
|
23
26
|
return res.to_h!
|
24
27
|
end
|
25
28
|
|
@@ -87,12 +87,23 @@ module Mailgun
|
|
87
87
|
#
|
88
88
|
# Return is irrelevant.
|
89
89
|
def extract_paging(response)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
@
|
95
|
-
|
90
|
+
paging = response.to_h['paging']
|
91
|
+
next_page_url = paging && paging['next'] # gives nil when any one of the keys doens't exist
|
92
|
+
previous_page_url = paging && paging['previous'] # can be replaced with Hash#dig for ruby >= 2.3.0
|
93
|
+
@paging_next = extract_endpoint_from(next_page_url)
|
94
|
+
@paging_previous = extract_endpoint_from(previous_page_url)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Internal: given a paging URL, extract the endpoint
|
98
|
+
#
|
99
|
+
# response - the endpoint for the previous/next page
|
100
|
+
#
|
101
|
+
# Returns a String of the partial URI if the given url follows the regular API format
|
102
|
+
# Returns nil in other cases (e.g. when given nil, or an irrelevant url)
|
103
|
+
def extract_endpoint_from(url = nil)
|
104
|
+
URI.parse(url).path[/api.mailgun.net\/v[\d]\/#{@domain}\/events\/(.+)/,1]
|
105
|
+
rescue URI::InvalidURIError
|
106
|
+
nil
|
96
107
|
end
|
97
108
|
|
98
109
|
# Internal: construct the event path to be used by the client
|
data/lib/mailgun/version.rb
CHANGED
@@ -46,7 +46,7 @@ module Mailgun
|
|
46
46
|
# Returns a Boolean of whether the webhook was created
|
47
47
|
def create(domain, action, url = '')
|
48
48
|
res = @client.post("domains/#{domain}/webhooks", id: action, url: url)
|
49
|
-
res.to_h['webhook'] == url && res.to_h[message] == 'Webhook has been created'
|
49
|
+
res.to_h['webhook']['url'] == url && res.to_h[message] == 'Webhook has been created'
|
50
50
|
end
|
51
51
|
alias_method :add, :create
|
52
52
|
alias_method :add_webhook, :create
|
data/lib/railgun/mailer.rb
CHANGED
@@ -11,7 +11,7 @@ module Railgun
|
|
11
11
|
|
12
12
|
# [Hash] config ->
|
13
13
|
# Requires *at least* `api_key` and `domain` keys.
|
14
|
-
attr_accessor :config, :domain
|
14
|
+
attr_accessor :config, :domain, :settings
|
15
15
|
|
16
16
|
# Initialize the Railgun mailer.
|
17
17
|
#
|
@@ -26,6 +26,9 @@ module Railgun
|
|
26
26
|
@mg_client = Mailgun::Client.new(config[:api_key])
|
27
27
|
@domain = @config[:domain]
|
28
28
|
|
29
|
+
# To avoid exception in mail gem v2.6
|
30
|
+
@settings = { return_response: true }
|
31
|
+
|
29
32
|
if (@config[:fake_message_send] || false)
|
30
33
|
Rails.logger.info "NOTE: fake message sending has been enabled for mailgun-ruby!"
|
31
34
|
@mg_client.enable_test_mode!
|
@@ -37,7 +40,7 @@ module Railgun
|
|
37
40
|
response = @mg_client.send_message(@domain, mg_message)
|
38
41
|
|
39
42
|
if response.code == 200 then
|
40
|
-
mg_id = response.
|
43
|
+
mg_id = response.to_h['id']
|
41
44
|
mail.message_id = mg_id
|
42
45
|
end
|
43
46
|
response
|
@@ -38,6 +38,12 @@ describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
|
|
38
38
|
expect(res).to eq(expected)
|
39
39
|
end
|
40
40
|
|
41
|
+
it 'performs mailbox validation for alice@mailgun.net' do
|
42
|
+
res = @mg_obj.validate("alice@mailgun.net", true)
|
43
|
+
|
44
|
+
expect(res["mailbox_verification"]).to eq("true")
|
45
|
+
end
|
46
|
+
|
41
47
|
it 'fails to validate example.org' do
|
42
48
|
res = @mg_obj.validate("example.org")
|
43
49
|
|
@@ -2,13 +2,13 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api:<
|
5
|
+
uri: https://api:<APIKEY>@api.mailgun.net/v3/address/parse?addresses=Alice%20%3Calice@example.com%3E%3Bbob@example.com%3Bexample.org&syntax_only=true
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
10
|
Accept:
|
11
|
-
-
|
11
|
+
- '*/*'
|
12
12
|
Accept-Encoding:
|
13
13
|
- gzip, deflate
|
14
14
|
User-Agent:
|
@@ -33,7 +33,7 @@ http_interactions:
|
|
33
33
|
Content-Disposition:
|
34
34
|
- inline
|
35
35
|
Access-Control-Allow-Origin:
|
36
|
-
-
|
36
|
+
- '*'
|
37
37
|
Access-Control-Max-Age:
|
38
38
|
- '600'
|
39
39
|
Access-Control-Allow-Methods:
|
@@ -56,13 +56,13 @@ http_interactions:
|
|
56
56
|
recorded_at: Wed, 26 Oct 2016 22:44:50 GMT
|
57
57
|
- request:
|
58
58
|
method: get
|
59
|
-
uri: https://api:<
|
59
|
+
uri: https://api:<APIKEY>@api.mailgun.net/v3/address/validate?address=alice@mailgun.net
|
60
60
|
body:
|
61
61
|
encoding: US-ASCII
|
62
62
|
string: ''
|
63
63
|
headers:
|
64
64
|
Accept:
|
65
|
-
-
|
65
|
+
- '*/*'
|
66
66
|
Accept-Encoding:
|
67
67
|
- gzip, deflate
|
68
68
|
User-Agent:
|
@@ -87,7 +87,7 @@ http_interactions:
|
|
87
87
|
Content-Disposition:
|
88
88
|
- inline
|
89
89
|
Access-Control-Allow-Origin:
|
90
|
-
-
|
90
|
+
- '*'
|
91
91
|
Access-Control-Max-Age:
|
92
92
|
- '600'
|
93
93
|
Access-Control-Allow-Methods:
|
@@ -111,13 +111,13 @@ http_interactions:
|
|
111
111
|
recorded_at: Wed, 26 Oct 2016 22:44:50 GMT
|
112
112
|
- request:
|
113
113
|
method: get
|
114
|
-
uri: https://api:<
|
114
|
+
uri: https://api:<APIKEY>@api.mailgun.net/v3/address/validate?address=example.org
|
115
115
|
body:
|
116
116
|
encoding: US-ASCII
|
117
117
|
string: ''
|
118
118
|
headers:
|
119
119
|
Accept:
|
120
|
-
-
|
120
|
+
- '*/*'
|
121
121
|
Accept-Encoding:
|
122
122
|
- gzip, deflate
|
123
123
|
User-Agent:
|
@@ -142,7 +142,7 @@ http_interactions:
|
|
142
142
|
Content-Disposition:
|
143
143
|
- inline
|
144
144
|
Access-Control-Allow-Origin:
|
145
|
-
-
|
145
|
+
- '*'
|
146
146
|
Access-Control-Max-Age:
|
147
147
|
- '600'
|
148
148
|
Access-Control-Allow-Methods:
|
@@ -164,4 +164,52 @@ http_interactions:
|
|
164
164
|
}
|
165
165
|
http_version:
|
166
166
|
recorded_at: Wed, 26 Oct 2016 22:44:50 GMT
|
167
|
+
- request:
|
168
|
+
method: get
|
169
|
+
uri: https://api:<APIKEY>@api.mailgun.net/v3/address/validate?address=alice@mailgun.net&mailbox_verification=true
|
170
|
+
body:
|
171
|
+
encoding: US-ASCII
|
172
|
+
string: ''
|
173
|
+
headers:
|
174
|
+
Accept:
|
175
|
+
- '*/*'
|
176
|
+
Accept-Encoding:
|
177
|
+
- gzip, deflate
|
178
|
+
User-Agent:
|
179
|
+
- rest-client/2.0.2 (darwin16.7.0 x86_64) ruby/2.0.0p0
|
180
|
+
Host:
|
181
|
+
- api.mailgun.net
|
182
|
+
response:
|
183
|
+
status:
|
184
|
+
code: 200
|
185
|
+
message: OK
|
186
|
+
headers:
|
187
|
+
Access-Control-Allow-Headers:
|
188
|
+
- Content-Type, x-requested-with
|
189
|
+
Access-Control-Allow-Methods:
|
190
|
+
- GET, POST, PUT, DELETE, OPTIONS
|
191
|
+
Access-Control-Allow-Origin:
|
192
|
+
- '*'
|
193
|
+
Access-Control-Max-Age:
|
194
|
+
- '600'
|
195
|
+
Content-Disposition:
|
196
|
+
- inline
|
197
|
+
Content-Type:
|
198
|
+
- application/json
|
199
|
+
Date:
|
200
|
+
- Tue, 12 Sep 2017 16:55:09 GMT
|
201
|
+
Server:
|
202
|
+
- nginx
|
203
|
+
Content-Length:
|
204
|
+
- '243'
|
205
|
+
Connection:
|
206
|
+
- keep-alive
|
207
|
+
body:
|
208
|
+
encoding: UTF-8
|
209
|
+
string: '{"address": "alice@mailgun.net", "did_you_mean": null, "is_disposable_address":
|
210
|
+
false, "is_role_address": false, "is_valid": true, "mailbox_verification":
|
211
|
+
"true", "parts": {"display_name": null, "domain": "mailgun.net", "local_part":
|
212
|
+
"alice"}}'
|
213
|
+
http_version:
|
214
|
+
recorded_at: Tue, 12 Sep 2017 16:55:09 GMT
|
167
215
|
recorded_with: VCR 3.0.3
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailgun-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mailgun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- ".rubocop.yml"
|
134
134
|
- ".rubocop_todo.yml"
|
135
135
|
- ".ruby-env.yml.example"
|
136
|
+
- ".ruby-version"
|
136
137
|
- ".travis.yml"
|
137
138
|
- Gemfile
|
138
139
|
- LICENSE
|
@@ -229,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
230
|
version: '0'
|
230
231
|
requirements: []
|
231
232
|
rubyforge_project:
|
232
|
-
rubygems_version: 2.
|
233
|
+
rubygems_version: 2.6.13
|
233
234
|
signing_key:
|
234
235
|
specification_version: 4
|
235
236
|
summary: Mailgun's Official Ruby SDK
|