mailgun-ruby 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +22 -0
- data/.ruby-env.yml.example +12 -0
- data/.travis.yml +6 -12
- data/Domains.md +36 -0
- data/MessageBuilder.md +14 -14
- data/Messages.md +44 -30
- data/OptInHandler.md +34 -34
- data/README.md +74 -24
- data/Rakefile +22 -20
- data/Snippets.md +26 -26
- data/Webhooks.md +40 -0
- data/lib/mailgun.rb +26 -228
- data/lib/mailgun/chains.rb +16 -0
- data/lib/mailgun/client.rb +143 -0
- data/lib/mailgun/domains/domains.rb +84 -0
- data/lib/mailgun/events/events.rb +53 -35
- data/lib/mailgun/exceptions/exceptions.rb +43 -10
- data/lib/mailgun/lists/opt_in_handler.rb +18 -19
- data/lib/mailgun/messages/batch_message.rb +31 -48
- data/lib/mailgun/messages/message_builder.rb +160 -144
- data/lib/mailgun/response.rb +55 -0
- data/lib/mailgun/version.rb +2 -3
- data/lib/mailgun/webhooks/webhooks.rb +101 -0
- data/mailgun.gemspec +16 -10
- data/spec/integration/bounces_spec.rb +44 -0
- data/spec/integration/campaign_spec.rb +60 -0
- data/spec/integration/complaints_spec.rb +38 -0
- data/spec/integration/domains_spec.rb +39 -0
- data/spec/integration/email_validation_spec.rb +29 -0
- data/spec/integration/events_spec.rb +20 -0
- data/spec/integration/list_members_spec.rb +63 -0
- data/spec/integration/list_spec.rb +58 -0
- data/spec/integration/mailgun_spec.rb +26 -550
- data/spec/integration/routes_spec.rb +74 -0
- data/spec/integration/stats_spec.rb +15 -0
- data/spec/integration/unsubscribes_spec.rb +42 -0
- data/spec/integration/webhook_spec.rb +54 -0
- data/spec/spec_helper.rb +37 -7
- data/spec/unit/connection/test_client.rb +15 -95
- data/spec/unit/events/events_spec.rb +9 -6
- data/spec/unit/lists/opt_in_handler_spec.rb +6 -4
- data/spec/unit/mailgun_spec.rb +25 -19
- data/spec/unit/messages/batch_message_spec.rb +47 -38
- data/spec/unit/messages/message_builder_spec.rb +282 -111
- data/vcr_cassettes/bounces.yml +175 -0
- data/vcr_cassettes/complaints.yml +175 -0
- data/vcr_cassettes/domains.todo.yml +42 -0
- data/vcr_cassettes/domains.yml +360 -0
- data/vcr_cassettes/email_validation.yml +104 -0
- data/vcr_cassettes/events.yml +61 -0
- data/vcr_cassettes/list_members.yml +320 -0
- data/vcr_cassettes/mailing_list.todo.yml +43 -0
- data/vcr_cassettes/mailing_list.yml +390 -0
- data/vcr_cassettes/routes.yml +359 -0
- data/vcr_cassettes/send_message.yml +107 -0
- data/vcr_cassettes/stats.yml +44 -0
- data/vcr_cassettes/unsubscribes.yml +191 -0
- data/vcr_cassettes/webhooks.yml +276 -0
- metadata +114 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c6226ce2745501543bd148db41a0297f2d58df
|
4
|
+
data.tar.gz: 2110bec8de2f21d49fee5d56ad41aef0d4fbc2b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04f6a82d67c5d8cda08c7a38956edfab2ff28b9c16b9344fcee2e3ec3caf1e0e69f901797de3a98640a962af9c28fff58d7151deb3cffbc32bee740df48eb901
|
7
|
+
data.tar.gz: 4fc8aec4b0e5e5c100a707c3cf44151b9eb2fe1e1cd047bf0df3c0122c1443c9264e048d27fe65390e23a9718be2ce5ab8d6009deaaf7ec0f512e9a7217f3552
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-01-07 12:11:06 -0500 using RuboCop version 0.35.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: CountComments.
|
11
|
+
Metrics/ClassLength:
|
12
|
+
Max: 169
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: CountComments.
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 14
|
18
|
+
|
19
|
+
# Offense count: 9
|
20
|
+
Style/AccessorMethodName:
|
21
|
+
Exclude:
|
22
|
+
- 'lib/mailgun/messages/message_builder.rb'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
---
|
2
|
+
# To assist with testing.
|
3
|
+
#
|
4
|
+
# DO NOT CHANGE AND COMMIT. YOU HAVE BEEN WARNED.
|
5
|
+
# Alternatively, use environment variables of the same.
|
6
|
+
#
|
7
|
+
# Replace <THESE_VALUES> with yours from
|
8
|
+
# https://mailgun.com/app/dashboard (don't include <brackets>)
|
9
|
+
# and rename to/save as: .ruby-env.yml
|
10
|
+
MAILGUN_APIKEY : '<MAILGUN_APIKEY'>
|
11
|
+
MAILGUN_PUB_APIKEY : '<MAILGUN_PUBLIC_APIKEY>'
|
12
|
+
MAILGUN_TESTDOMAIN : '<MAILGUN_SANDBOX_DOMAIN>'
|
data/.travis.yml
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
3
|
+
- 2.2
|
4
|
+
- 2.1
|
4
5
|
- 2.0.0
|
5
|
-
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
- 2.1.4
|
10
|
-
- 2.1.5
|
11
|
-
- 2.2.0-preview1
|
12
|
-
gemfile:
|
13
|
-
- Gemfile
|
14
|
-
script:
|
15
|
-
- bundle exec rake spec
|
6
|
+
- 1.9.3
|
7
|
+
sudo: false
|
8
|
+
gemfile: Gemfile
|
9
|
+
script: bundle exec rake spec
|
data/Domains.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Mailgun - Domains
|
2
|
+
====================
|
3
|
+
|
4
|
+
This is the Mailgun Ruby *Domain* 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
|
+
Usage - Domains
|
11
|
+
-----------------------
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
# First, instantiate the Mailgun Client with your API key
|
15
|
+
mg_client = Mailgun::Client.new('your-api-key')
|
16
|
+
domainer = Mailgun::Domains.new(mg_client)
|
17
|
+
|
18
|
+
# Get a list of current domains.
|
19
|
+
domainer.list
|
20
|
+
|
21
|
+
# View details of a domain
|
22
|
+
domainer.info 'my.perfect.domain'
|
23
|
+
|
24
|
+
# Add a new domain
|
25
|
+
domainer.create 'my.new.moreness'
|
26
|
+
# or with options
|
27
|
+
domainer.create 'my.new.moreness', { some: 'options' }
|
28
|
+
|
29
|
+
# Remove a domain
|
30
|
+
domainer.remove 'this.one.is.not.needed.'
|
31
|
+
```
|
32
|
+
|
33
|
+
More Documentation
|
34
|
+
------------------
|
35
|
+
See the official [Mailgun Domain Docs](https://documentation.mailgun.com/api-domains.html)
|
36
|
+
for more information
|
data/MessageBuilder.md
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
Mailgun - Messages
|
2
2
|
====================
|
3
3
|
|
4
|
-
This is the Mailgun Ruby *Message* utilities.
|
4
|
+
This is the Mailgun Ruby *Message* utilities.
|
5
5
|
|
6
6
|
The below assumes you've already installed the Mailgun Gem. If not, go back to the master README for instructions.
|
7
7
|
|
8
|
-
There are two utilities included, Message Builder and Batch Message.
|
8
|
+
There are two utilities included, Message Builder and Batch Message.
|
9
9
|
|
10
|
-
Message Builder: Allows you to build a message object by calling methods for
|
11
|
-
each attribute.
|
12
|
-
Batch Message: Inherits Message Builder and allows you to iterate through
|
13
|
-
recipients from a list. Messages will fire after the 1,000th recipient has been
|
14
|
-
added.
|
10
|
+
Message Builder: Allows you to build a message object by calling methods for
|
11
|
+
each attribute.
|
12
|
+
Batch Message: Inherits Message Builder and allows you to iterate through
|
13
|
+
recipients from a list. Messages will fire after the 1,000th recipient has been
|
14
|
+
added.
|
15
15
|
|
16
16
|
Usage - Message Builder
|
17
17
|
-----------------------
|
18
|
-
Here's how to use Message Builder to build your Message.
|
18
|
+
Here's how to use Message Builder to build your Message.
|
19
19
|
|
20
20
|
```ruby
|
21
21
|
# First, instantiate the Mailgun Client with your API key
|
@@ -28,7 +28,7 @@ mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"});
|
|
28
28
|
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John", "last" => "Doe"});
|
29
29
|
# Define a cc recipient.
|
30
30
|
mb_obj.add_recipient(:cc, "sally.doe@example.com", {"first" => "Sally", "last" => "Doe"});
|
31
|
-
# Define the subject.
|
31
|
+
# Define the subject.
|
32
32
|
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!");
|
33
33
|
# Define the body of the message.
|
34
34
|
mb_obj.set_text_body("This is the text body of the message!");
|
@@ -45,7 +45,7 @@ mb_obj.add_custom_parameter("h:Customer-Id", "12345");
|
|
45
45
|
mb_obj.add_attachment("/path/to/file/receipt_123491820.pdf", "Receipt.pdf");
|
46
46
|
|
47
47
|
# Schedule message in the future
|
48
|
-
mb_obj.set_delivery_time("tomorrow 8:00AM
|
48
|
+
mb_obj.set_delivery_time("tomorrow 8:00AM PST");
|
49
49
|
|
50
50
|
# Finally, send your message using the client
|
51
51
|
result = mg_client.send_message("sending_domain.com", mb_obj)
|
@@ -55,7 +55,7 @@ puts result.body.to_s
|
|
55
55
|
|
56
56
|
Usage - Batch Message
|
57
57
|
---------------------
|
58
|
-
Here's how to use Batch Message to easily handle batch sending jobs.
|
58
|
+
Here's how to use Batch Message to easily handle batch sending jobs.
|
59
59
|
|
60
60
|
```ruby
|
61
61
|
# First, instantiate the Mailgun Client with your API key
|
@@ -65,7 +65,7 @@ mb_obj = Mailgun::BatchMessage.new(mg_client, "example.com")
|
|
65
65
|
|
66
66
|
# Define the from address.
|
67
67
|
mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"});
|
68
|
-
# Define the subject.
|
68
|
+
# Define the subject.
|
69
69
|
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!");
|
70
70
|
# Define the body of the message.
|
71
71
|
mb_obj.set_text_body("This is the text body of the message!");
|
@@ -85,5 +85,5 @@ message_ids = mb_obj.finalize
|
|
85
85
|
|
86
86
|
More Documentation
|
87
87
|
------------------
|
88
|
-
See the official [Mailgun Docs](http://documentation.mailgun.com/api-sending.html)
|
89
|
-
for more information.
|
88
|
+
See the official [Mailgun Docs](http://documentation.mailgun.com/api-sending.html)
|
89
|
+
for more information.
|
data/Messages.md
CHANGED
@@ -24,26 +24,36 @@ mg_client = Mailgun::Client.new("your-api-key")
|
|
24
24
|
mb_obj = Mailgun::MessageBuilder.new
|
25
25
|
|
26
26
|
# Define the from address.
|
27
|
-
mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"})
|
27
|
+
mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"})
|
28
|
+
|
28
29
|
# Define a to recipient.
|
29
|
-
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John", "last" => "Doe"})
|
30
|
+
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John", "last" => "Doe"})
|
31
|
+
|
30
32
|
# Define a cc recipient.
|
31
|
-
mb_obj.add_recipient(:cc, "sally.doe@example.com", {"first" => "Sally", "last" => "Doe"})
|
33
|
+
mb_obj.add_recipient(:cc, "sally.doe@example.com", {"first" => "Sally", "last" => "Doe"})
|
34
|
+
|
32
35
|
# Define the subject.
|
33
|
-
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!")
|
36
|
+
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!")
|
37
|
+
|
34
38
|
# Define the body of the message.
|
35
|
-
mb_obj.set_text_body("This is the text body of the message!")
|
39
|
+
mb_obj.set_text_body("This is the text body of the message!")
|
40
|
+
|
41
|
+
# Define the HTML text of the message
|
42
|
+
mb_obj.set_html_body("<html><body><p>This is the text body of the message</p></body></html>")
|
43
|
+
|
36
44
|
# Set the Message-Id header. Pass in a valid Message-Id.
|
37
45
|
mb_obj.set_message_id("<20141014000000.11111.11111@example.com>")
|
46
|
+
|
38
47
|
# Clear the Message-Id header. Pass in nil or empty string.
|
39
48
|
mb_obj.set_message_id(nil)
|
40
49
|
mb_obj.set_message_id('')
|
50
|
+
|
41
51
|
# Other Optional Parameters.
|
42
|
-
mb_obj.add_campaign_id("My-Awesome-Campaign")
|
43
|
-
mb_obj.add_custom_parameter("h:Customer-Id", "12345")
|
44
|
-
mb_obj.add_attachment("@/tron.jpg")
|
45
|
-
mb_obj.set_delivery_time("tomorrow 8:00AM
|
46
|
-
mb_obj.set_click_tracking(true)
|
52
|
+
mb_obj.add_campaign_id("My-Awesome-Campaign")
|
53
|
+
mb_obj.add_custom_parameter("h:Customer-Id", "12345")
|
54
|
+
mb_obj.add_attachment("@/tron.jpg")
|
55
|
+
mb_obj.set_delivery_time("tomorrow 8:00AM PST")
|
56
|
+
mb_obj.set_click_tracking(true)
|
47
57
|
|
48
58
|
# Send your message through the client
|
49
59
|
mg_client.send_message("sending_domain.com", mb_obj)
|
@@ -59,29 +69,33 @@ mg_client = Mailgun::Client.new("your-api-key")
|
|
59
69
|
mb_obj = Mailgun::BatchMessage.new(mg_client, "example.com")
|
60
70
|
|
61
71
|
# Define the from address.
|
62
|
-
mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"})
|
72
|
+
mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"})
|
73
|
+
|
63
74
|
# Define the subject.
|
64
|
-
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!")
|
75
|
+
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!")
|
76
|
+
|
65
77
|
# Define the body of the message.
|
66
|
-
mb_obj.set_text_body("Hello %recipient.first%,
|
67
|
-
This is the text body of the message
|
78
|
+
mb_obj.set_text_body("Hello %recipient.first%,
|
79
|
+
This is the text body of the message
|
68
80
|
using recipient variables!
|
69
|
-
If you need to include custom data,
|
70
|
-
you could do it like this: %account-id%.")
|
71
|
-
|
72
|
-
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John",
|
73
|
-
"last" => "Doe",
|
74
|
-
"account-id" => 1234})
|
75
|
-
|
76
|
-
|
77
|
-
"
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
If you need to include custom data,
|
82
|
+
you could do it like this: %account-id%.")
|
83
|
+
|
84
|
+
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John",
|
85
|
+
"last" => "Doe",
|
86
|
+
"account-id" => 1234})
|
87
|
+
|
88
|
+
mb_obj.add_recipient(:to, "jane.doe@example.com", {"first" => "Jane",
|
89
|
+
"last" => "Doe",
|
90
|
+
"account-id" => 5678})
|
91
|
+
|
92
|
+
mb_obj.add_recipient(:to, "bob.doe@example.com", {"first" => "Bob",
|
93
|
+
"last" => "Doe",
|
94
|
+
"account-id" => 91011})
|
81
95
|
...
|
82
|
-
mb_obj.add_recipient(:to, "sally.doe@example.com", {"first" => "Sally",
|
83
|
-
"last" => "Doe",
|
84
|
-
"account-id" => 121314})
|
96
|
+
mb_obj.add_recipient(:to, "sally.doe@example.com", {"first" => "Sally",
|
97
|
+
"last" => "Doe",
|
98
|
+
"account-id" => 121314})
|
85
99
|
|
86
100
|
# Send your message through the client
|
87
101
|
message_ids = mb_obj.finalize
|
@@ -89,5 +103,5 @@ message_ids = mb_obj.finalize
|
|
89
103
|
|
90
104
|
More Documentation
|
91
105
|
------------------
|
92
|
-
See the official [Mailgun Docs](
|
106
|
+
See the official [Mailgun Docs](https://documentation.mailgun.com/api-sending.html)
|
93
107
|
for more information.
|
data/OptInHandler.md
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
Mailgun - Lists
|
2
2
|
====================
|
3
3
|
|
4
|
-
This is the Mailgun Ruby *Lists* utilities.
|
4
|
+
This is the Mailgun Ruby *Lists* utilities.
|
5
5
|
|
6
|
-
The below assumes you've already installed the Mailgun Ruby SDK in your project.
|
6
|
+
The below assumes you've already installed the Mailgun Ruby SDK in your project.
|
7
7
|
If not, go back to the master README for a few quick install steps.
|
8
8
|
|
9
|
-
OptInHandler: Provides methods for authenticating an Opt-In Request.
|
9
|
+
OptInHandler: Provides methods for authenticating an Opt-In Request.
|
10
10
|
|
11
|
-
The typical flow for using this utility would be as follows:
|
12
|
-
**Recipient Requests Subscribe** -> [Validate Recipient Address] -> [Generate Opt-In Link] -> [Email Recipient Opt-In Link]
|
13
|
-
**Recipient Clicks Opt-In Link** -> [Validate Opt-In Link] -> [Subscribe User] -> [Send final confirmation]
|
11
|
+
The typical flow for using this utility would be as follows:
|
12
|
+
**Recipient Requests Subscribe** -> [Validate Recipient Address] -> [Generate Opt-In Link] -> [Email Recipient Opt-In Link]
|
13
|
+
**Recipient Clicks Opt-In Link** -> [Validate Opt-In Link] -> [Subscribe User] -> [Send final confirmation]
|
14
14
|
|
15
15
|
The above flow is modeled below.
|
16
16
|
|
17
17
|
Usage - Opt-In Handler (Recipient Requests Subscribe)
|
18
18
|
-----------------------------------------------------
|
19
|
-
Here's how to use Opt-In Handler to validate Opt-In requests.
|
19
|
+
Here's how to use Opt-In Handler to validate Opt-In requests.
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
# First, instantiate the SDK with your API credentials, domain, and required parameters for example.
|
22
|
+
# First, instantiate the SDK with your API credentials, domain, and required parameters for example.
|
23
23
|
mg_client = Mailgun::Client.new("your-api-key")
|
24
24
|
mg_validate = Mailgun::Client.new("your-pub-api-key")
|
25
25
|
|
@@ -31,22 +31,23 @@ recipient_address = 'recipient@example.com';
|
|
31
31
|
|
32
32
|
# Let's validate the customer's email address, using Mailgun's validation endpoint.
|
33
33
|
result = mg_validate.get('address/validate', {:address => recipient_address});
|
34
|
+
body = JSON.parse(result.body)
|
34
35
|
|
35
|
-
if
|
36
|
+
if body['is_valid'] == true
|
36
37
|
# Next, generate a hash.
|
37
38
|
generated_hash = Mailgun::OptInHandler.generate_hash(mailing_list, secret_app_id, recipient_address);
|
38
39
|
|
39
40
|
# Now, let's send a confirmation to the recipient with our link.
|
40
|
-
mg_client.send_message(domain, {:from => 'bob@example.com',
|
41
|
-
:to => recipient_address,
|
42
|
-
:subject => 'Please Confirm!',
|
43
|
-
:html => "<html><body>Hello,<br><br>You have requested to be subscribed
|
44
|
-
to the mailing list #{mailing_list}. Please <a
|
41
|
+
mg_client.send_message(domain, {:from => 'bob@example.com',
|
42
|
+
:to => recipient_address,
|
43
|
+
:subject => 'Please Confirm!',
|
44
|
+
:html => "<html><body>Hello,<br><br>You have requested to be subscribed
|
45
|
+
to the mailing list #{mailing_list}. Please <a
|
45
46
|
href=\"http://yourdomain.com/subscribe.php?hash=#{generated_hash}\">
|
46
47
|
confirm</a> your subscription.<br><br>Thank you!</body></html>"});
|
47
48
|
|
48
49
|
# Finally, let's add the subscriber to a Mailing List, as unsubscribed, so we can track non-conversions.
|
49
|
-
mg_client.post("lists/#{mailing_list}/members", {:address => recipient_address,
|
50
|
+
mg_client.post("lists/#{mailing_list}/members", {:address => recipient_address,
|
50
51
|
:subscribed => 'no',
|
51
52
|
:upsert => 'yes'});
|
52
53
|
end
|
@@ -54,10 +55,10 @@ end
|
|
54
55
|
|
55
56
|
Usage - Opt-In Handler (Recipient Clicks Opt In Link)
|
56
57
|
-----------------------------------------------------
|
57
|
-
Here's how to use Opt-In Handler to validate an Opt-In Hash.
|
58
|
+
Here's how to use Opt-In Handler to validate an Opt-In Hash.
|
58
59
|
|
59
60
|
```ruby
|
60
|
-
# First, instantiate the SDK with your API credentials and domain.
|
61
|
+
# First, instantiate the SDK with your API credentials and domain.
|
61
62
|
mg_client = Mailgun::Client.new("your-api-key")
|
62
63
|
domain = 'example.com';
|
63
64
|
|
@@ -69,35 +70,34 @@ if !hash_validation.nil?
|
|
69
70
|
validated_list = hash_validation['mailing_list'];
|
70
71
|
validated_recipient = hash_validation['recipient_address'];
|
71
72
|
|
72
|
-
mg_client.put("lists/#{validated_list}/members/#{validated_recipient}",
|
73
|
-
{:address => validated_recipient,
|
73
|
+
mg_client.put("lists/#{validated_list}/members/#{validated_recipient}",
|
74
|
+
{:address => validated_recipient,
|
74
75
|
:subscribed => 'yes'})
|
75
76
|
|
76
|
-
mg_client.send_message(domain, {:from => 'bob@example.com',
|
77
|
-
:to => validated_recipient,
|
78
|
-
:subject => 'Confirmation Received!',
|
77
|
+
mg_client.send_message(domain, {:from => 'bob@example.com',
|
78
|
+
:to => validated_recipient,
|
79
|
+
:subject => 'Confirmation Received!',
|
79
80
|
:html => "<html><body>Hello,<br><br>We've successfully subscribed you to the list, #{validated_list}!<br><br>Thank you!
|
80
|
-
</body></html>")
|
81
|
+
</body></html>"});
|
81
82
|
end
|
82
83
|
```
|
83
84
|
|
84
|
-
A few notes:
|
85
|
-
1. 'secret_app_id' can be anything. It's used as the *key* in hashing,
|
86
|
-
since your email address will vary. It should be secured like a password.
|
87
|
-
2. validateHash will return an array containing the recipient address and list
|
88
|
-
address.
|
89
|
-
3. You should *always* send an email confirmation before and after the
|
90
|
-
subscription request. This is what double-opt in means.
|
85
|
+
A few notes:
|
86
|
+
1. 'secret_app_id' can be anything. It's used as the *key* in hashing,
|
87
|
+
since your email address will vary. It should be secured like a password.
|
88
|
+
2. validateHash will return an array containing the recipient address and list
|
89
|
+
address.
|
90
|
+
3. You should *always* send an email confirmation before and after the
|
91
|
+
subscription request. This is what double-opt in means.
|
91
92
|
|
92
93
|
|
93
94
|
Available Functions
|
94
95
|
-----------------------------------------------------
|
95
96
|
|
96
|
-
`string generate_hash(string mailing_list, string secret_app_id, string recipient_address)`
|
97
|
+
`string generate_hash(string mailing_list, string secret_app_id, string recipient_address)`
|
97
98
|
|
98
|
-
`array validate_hash(string secret_app_id, string unique_hash)`
|
99
|
+
`array validate_hash(string secret_app_id, string unique_hash)`
|
99
100
|
|
100
101
|
More Documentation
|
101
102
|
------------------
|
102
|
-
See the official [Mailgun Docs](
|
103
|
-
for more information.
|
103
|
+
See the official [Mailgun Docs](https://documentation.mailgun.com/api-sending.html) for more information.
|
data/README.md
CHANGED
@@ -6,8 +6,7 @@ Mailgun-Ruby
|
|
6
6
|
This is the Mailgun Ruby Library. This library contains methods for easily interacting
|
7
7
|
with the Mailgun API.
|
8
8
|
Below are examples to get you started. For additional examples, please see our
|
9
|
-
official documentation
|
10
|
-
at http://documentation.mailgun.com
|
9
|
+
official documentation at https://documentation.mailgun.com
|
11
10
|
|
12
11
|
Installation
|
13
12
|
------------
|
@@ -20,7 +19,7 @@ gem install mailgun-ruby
|
|
20
19
|
Gemfile:
|
21
20
|
|
22
21
|
```ruby
|
23
|
-
gem 'mailgun-ruby', '~>1.0.
|
22
|
+
gem 'mailgun-ruby', '~>1.0.5', require: 'mailgun'
|
24
23
|
```
|
25
24
|
|
26
25
|
Include
|
@@ -36,31 +35,44 @@ Here's how to send a message using the library:
|
|
36
35
|
|
37
36
|
```ruby
|
38
37
|
# First, instantiate the Mailgun Client with your API key
|
39
|
-
mg_client = Mailgun::Client.new
|
38
|
+
mg_client = Mailgun::Client.new 'your-api-key'
|
40
39
|
|
41
40
|
# Define your message parameters
|
42
|
-
message_params =
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
message_params = { from: 'bob@sending_domain.com',
|
42
|
+
to: 'sally@example.com',
|
43
|
+
subject: 'The Ruby SDK is awesome!',
|
44
|
+
text: 'It is really easy to send a message!'
|
45
|
+
}
|
46
46
|
|
47
47
|
# Send your message through the client
|
48
|
-
mg_client.send_message
|
48
|
+
mg_client.send_message 'sending_domain.com', message_params
|
49
49
|
```
|
50
50
|
|
51
51
|
Or obtain the last couple log items:
|
52
52
|
|
53
53
|
```ruby
|
54
54
|
# First, instantiate the Mailgun Client with your API key
|
55
|
-
mg_client = Mailgun::Client.new
|
55
|
+
mg_client = Mailgun::Client.new 'your-api-key'
|
56
56
|
|
57
57
|
# Define the domain you wish to query
|
58
|
-
domain =
|
58
|
+
domain = 'example.com'
|
59
59
|
|
60
60
|
# Issue the get request
|
61
61
|
result = mg_client.get("#{domain}/events", {:event => 'delivered'})
|
62
62
|
```
|
63
63
|
|
64
|
+
Rails
|
65
|
+
-----
|
66
|
+
|
67
|
+
The library can be initialized with a Rails initializer containing similar:
|
68
|
+
```ruby
|
69
|
+
Mailgun.configure do |config|
|
70
|
+
config.api_key = 'your-secret-key'
|
71
|
+
end
|
72
|
+
```
|
73
|
+
Or have the initializer read your environment setting if you perfer.
|
74
|
+
|
75
|
+
|
64
76
|
Response
|
65
77
|
--------
|
66
78
|
|
@@ -84,12 +96,14 @@ Here's an example, breaking out the response:
|
|
84
96
|
```ruby
|
85
97
|
mg_client = Mailgun::Client.new("your-api-key")
|
86
98
|
|
87
|
-
message_params =
|
88
|
-
|
89
|
-
|
90
|
-
|
99
|
+
message_params = {
|
100
|
+
from: 'bob@example.com',
|
101
|
+
to: 'sally@example.com',
|
102
|
+
subject: 'The Ruby SDK is awesome!',
|
103
|
+
text: 'It is really easy to send a message!'
|
104
|
+
}
|
91
105
|
|
92
|
-
result = mg_client.send_message(
|
106
|
+
result = mg_client.send_message('example.com', message_params).to_h!
|
93
107
|
|
94
108
|
message_id = result['id']
|
95
109
|
message = result['message']
|
@@ -110,17 +124,19 @@ Go to http://bin.mailgun.net. The Postbin will generate a special URL. Save that
|
|
110
124
|
|
111
125
|
**Step 2 - Instantiate the Mailgun client using Postbin.**
|
112
126
|
|
113
|
-
*Tip: The bin id will be the URL part after bin.mailgun.net. It will be random generated letters and numbers.
|
127
|
+
*Tip: The bin id will be the URL part after bin.mailgun.net. It will be random generated letters and numbers.
|
128
|
+
For example, the bin id in this URL, http://bin.mailgun.net/aecf68de, is "aecf68de".*
|
114
129
|
|
115
130
|
```ruby
|
116
131
|
# First, instantiate the Mailgun Client with your API key
|
117
132
|
mg_client = Mailgun::Client.new("your-api-key", "bin.mailgun.net", "aecf68de", ssl = false)
|
118
133
|
|
119
134
|
# Define your message parameters
|
120
|
-
message_params = {:
|
121
|
-
|
122
|
-
|
123
|
-
|
135
|
+
message_params = { from: 'bob@sending_domain.com',
|
136
|
+
to: 'sally@example.com',
|
137
|
+
subject: 'The Ruby SDK is awesome!',
|
138
|
+
text: 'It is really easy to send a message!'
|
139
|
+
}
|
124
140
|
|
125
141
|
# Send your message through the client
|
126
142
|
mg_client.send_message("sending_domain.com", message_params)
|
@@ -129,8 +145,13 @@ mg_client.send_message("sending_domain.com", message_params)
|
|
129
145
|
For usage examples on each API endpoint, head over to our official documentation
|
130
146
|
pages. Or the [Snippets](Snippets.md) file.
|
131
147
|
|
132
|
-
This SDK includes
|
133
|
-
[
|
148
|
+
This SDK includes the following components:
|
149
|
+
- [Message Builder](Messages.md)
|
150
|
+
- [Batch Message](Messages.md)
|
151
|
+
- [Opt-In Handler](OptInHandler.md)
|
152
|
+
- [Domains](Domains.md)
|
153
|
+
- [Webhooks](Webhooks.md)
|
154
|
+
- [Events](Events.md)
|
134
155
|
|
135
156
|
Message Builder allows you to quickly create the array of parameters, required
|
136
157
|
to send a message, by calling a methods for each parameter.
|
@@ -138,11 +159,40 @@ Batch Message is an extension of Message Builder, and allows you to easily send
|
|
138
159
|
a batch message job within a few seconds. The complexity of
|
139
160
|
batch messaging is eliminated!
|
140
161
|
|
162
|
+
Testing
|
163
|
+
-------
|
164
|
+
|
165
|
+
There are unit tests and integration tests. Unit tests do not require Mailgun account keys. Integration tests do.
|
166
|
+
By default:
|
167
|
+
```
|
168
|
+
bundle exec rake spec
|
169
|
+
```
|
170
|
+
will run just unit tests. To run integration tests:
|
171
|
+
```
|
172
|
+
bundle exec rake spec:integration
|
173
|
+
```
|
174
|
+
will run just integration tests.
|
175
|
+
```
|
176
|
+
bundle exec rake spec:all
|
177
|
+
```
|
178
|
+
will run all both types.
|
179
|
+
|
180
|
+
Integrations tests will run against [VCR](https://github.com/vcr/vcr) cassettes if they exist.
|
181
|
+
If you'd like to run tests against your mailgun account, remove the cassettes.
|
182
|
+
|
183
|
+
To set up Mailgun key information. See the example file: .ruby-env.yml.example.
|
184
|
+
Rename this file to .ruby-env.yml and replace the items between the <> (including the <>) with the private
|
185
|
+
and public keys, and sandbox domain. Alternatively use a different domain registered in Mailgun if you
|
186
|
+
have one you want to test against.
|
187
|
+
|
188
|
+
The MAILGUN_* variables in .ruby-env.yml(.example) can also be set as
|
189
|
+
environment variables, if you'd like to do that instead.
|
190
|
+
|
141
191
|
Support and Feedback
|
142
192
|
--------------------
|
143
193
|
|
144
194
|
Be sure to visit the Mailgun official
|
145
|
-
[documentation website](
|
195
|
+
[documentation website](https://documentation.mailgun.com/) for additional
|
146
196
|
information about our API.
|
147
197
|
|
148
198
|
If you find a bug, please submit the issue in Github directly.
|