wj-mailgun-ruby 1.1.7
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 +7 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +22 -0
- data/.ruby-env.yml.example +12 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +6 -0
- data/LICENSE +191 -0
- data/README.md +241 -0
- data/Rakefile +35 -0
- data/docs/Domains.md +54 -0
- data/docs/Events.md +46 -0
- data/docs/MessageBuilder.md +105 -0
- data/docs/Messages.md +107 -0
- data/docs/OptInHandler.md +103 -0
- data/docs/Snippets.md +526 -0
- data/docs/Suppressions.md +82 -0
- data/docs/Webhooks.md +40 -0
- data/lib/mailgun-ruby.rb +2 -0
- data/lib/mailgun.rb +39 -0
- data/lib/mailgun/address.rb +45 -0
- data/lib/mailgun/chains.rb +16 -0
- data/lib/mailgun/client.rb +199 -0
- data/lib/mailgun/domains/domains.rb +84 -0
- data/lib/mailgun/events/events.rb +120 -0
- data/lib/mailgun/exceptions/exceptions.rb +65 -0
- data/lib/mailgun/lists/opt_in_handler.rb +58 -0
- data/lib/mailgun/messages/batch_message.rb +125 -0
- data/lib/mailgun/messages/message_builder.rb +413 -0
- data/lib/mailgun/response.rb +62 -0
- data/lib/mailgun/suppressions.rb +270 -0
- data/lib/mailgun/version.rb +4 -0
- data/lib/mailgun/webhooks/webhooks.rb +101 -0
- data/lib/railgun.rb +8 -0
- data/lib/railgun/attachment.rb +56 -0
- data/lib/railgun/errors.rb +27 -0
- data/lib/railgun/mailer.rb +161 -0
- data/lib/railgun/message.rb +17 -0
- data/lib/railgun/railtie.rb +9 -0
- data/mailgun.gemspec +37 -0
- 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 +57 -0
- data/spec/integration/events_spec.rb +28 -0
- data/spec/integration/list_members_spec.rb +63 -0
- data/spec/integration/list_spec.rb +58 -0
- data/spec/integration/mailgun_spec.rb +121 -0
- data/spec/integration/messages/sample_data/mime.txt +38 -0
- data/spec/integration/routes_spec.rb +74 -0
- data/spec/integration/stats_spec.rb +15 -0
- data/spec/integration/suppressions_spec.rb +126 -0
- data/spec/integration/unsubscribes_spec.rb +42 -0
- data/spec/integration/webhook_spec.rb +54 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/unit/connection/test_client.rb +99 -0
- data/spec/unit/events/events_spec.rb +50 -0
- data/spec/unit/lists/opt_in_handler_spec.rb +24 -0
- data/spec/unit/mailgun_spec.rb +127 -0
- data/spec/unit/messages/batch_message_spec.rb +131 -0
- data/spec/unit/messages/message_builder_spec.rb +584 -0
- data/spec/unit/messages/sample_data/mailgun_icon.png +0 -0
- data/spec/unit/messages/sample_data/mime.txt +38 -0
- data/spec/unit/messages/sample_data/rackspace_logo.jpg +0 -0
- 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 +167 -0
- data/vcr_cassettes/events.yml +108 -0
- data/vcr_cassettes/exceptions.yml +45 -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/suppressions.yml +676 -0
- data/vcr_cassettes/unsubscribes.yml +191 -0
- data/vcr_cassettes/webhooks.yml +276 -0
- metadata +263 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 052cfc6ec92461618676ecf1e4a108559fc62ae6
|
4
|
+
data.tar.gz: 3088cbccaa13f3c713b5f0dcdd6ddba4438dc624
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b4167a00ccca88c41e0c245c3f5bdd93c2becf91bf8ab49e042e55e9ef1afcf9797ae076965b7bab8eaeaa4f19b5e8a74768b632a064a5699bb00075c316aa15
|
7
|
+
data.tar.gz: 7c9c6df32c8886f9338263673766ef4e1520c6396c1e54d61547e33aca891172da5e070f2a6e53e2f42bfdf6472a6247801600f25c44f83c48934ec08772a2cc
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.DS_Store
|
19
|
+
test.rb
|
20
|
+
ruby
|
21
|
+
.ruby-env.yml
|
22
|
+
.rspec-local
|
23
|
+
.tool-versions
|
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/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p0
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- 2.3.1
|
8
|
+
script:
|
9
|
+
- bundle install
|
10
|
+
- bundle exec rake spec
|
11
|
+
- '[[ "${TRAVIS_PULL_REQUEST}" == "false" ]] && ( bundle exec rake spec:integration
|
12
|
+
) || ( echo "Testing PR - No integration tests available")'
|
13
|
+
deploy:
|
14
|
+
provider: rubygems
|
15
|
+
api_key:
|
16
|
+
secure: DoX3w48gRyhDM1o1OLvtWsTi8ehLIarIsErzg/UlNRoLacQt5l5UzwD+u6wqsCEr4+c2uAHNahafpnw/j1rPG3LBPIXOK5A0SYbjovlckutiAC0330Q4PHwOZb73AFN1DG5JTeg4/fguEjdsEBdZObF7mh5gBMBQtNjo1Fos+4w=
|
17
|
+
gemspec: mailgun.gemspec
|
18
|
+
on:
|
19
|
+
tags: true
|
20
|
+
condition: "$TRAVIS_RUBY_VERSION == 2.3.1"
|
21
|
+
notifications:
|
22
|
+
slack:
|
23
|
+
rooms:
|
24
|
+
secure: G4iBtDfFGeryQslfrKZK4hSPikOy9y3SDnpzwmN8SoB0uIAWE2mLfMUJZonKm7yoz+DbPU0u3c1SwiMLwHkXZhPdnJdC1fb1DpicXnVgGZYdiLGiY+OAwkvcBE9p3piWhpwigTjvmSqTaNSRL/VLhG4qwQbHU0fTl1M1zwU4e6c=
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
13
|
+
owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
21
|
+
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
23
|
+
permissions granted by this License.
|
24
|
+
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
27
|
+
files.
|
28
|
+
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
31
|
+
generated documentation, and conversions to other media types.
|
32
|
+
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
34
|
+
available under the License, as indicated by a copyright notice that is included
|
35
|
+
in or attached to the work (an example is provided in the Appendix below).
|
36
|
+
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
43
|
+
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
47
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
48
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
49
|
+
"submitted" means any form of electronic, verbal, or written communication sent
|
50
|
+
to the Licensor or its representatives, including but not limited to
|
51
|
+
communication on electronic mailing lists, source code control systems, and
|
52
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
53
|
+
the purpose of discussing and improving the Work, but excluding communication
|
54
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
55
|
+
owner as "Not a Contribution."
|
56
|
+
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
59
|
+
incorporated within the Work.
|
60
|
+
|
61
|
+
2. Grant of Copyright License.
|
62
|
+
|
63
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
64
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
65
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
66
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
67
|
+
Derivative Works in Source or Object form.
|
68
|
+
|
69
|
+
3. Grant of Patent License.
|
70
|
+
|
71
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
72
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
73
|
+
irrevocable (except as stated in this section) patent license to make, have
|
74
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
75
|
+
such license applies only to those patent claims licensable by such Contributor
|
76
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
77
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
78
|
+
submitted. If You institute patent litigation against any entity (including a
|
79
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
80
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
81
|
+
patent infringement, then any patent licenses granted to You under this License
|
82
|
+
for that Work shall terminate as of the date such litigation is filed.
|
83
|
+
|
84
|
+
4. Redistribution.
|
85
|
+
|
86
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
87
|
+
in any medium, with or without modifications, and in Source or Object form,
|
88
|
+
provided that You meet the following conditions:
|
89
|
+
|
90
|
+
You must give any other recipients of the Work or Derivative Works a copy of
|
91
|
+
this License; and
|
92
|
+
You must cause any modified files to carry prominent notices stating that You
|
93
|
+
changed the files; and
|
94
|
+
You must retain, in the Source form of any Derivative Works that You distribute,
|
95
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
96
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
97
|
+
Derivative Works; and
|
98
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
99
|
+
Derivative Works that You distribute must include a readable copy of the
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
106
|
+
the NOTICE file are for informational purposes only and do not modify the
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
110
|
+
modifying the License.
|
111
|
+
You may add Your own copyright statement to Your modifications and may provide
|
112
|
+
additional or different license terms and conditions for use, reproduction, or
|
113
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
114
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
115
|
+
with the conditions stated in this License.
|
116
|
+
|
117
|
+
5. Submission of Contributions.
|
118
|
+
|
119
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
120
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
121
|
+
conditions of this License, without any additional terms or conditions.
|
122
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
123
|
+
any separate license agreement you may have executed with Licensor regarding
|
124
|
+
such Contributions.
|
125
|
+
|
126
|
+
6. Trademarks.
|
127
|
+
|
128
|
+
This License does not grant permission to use the trade names, trademarks,
|
129
|
+
service marks, or product names of the Licensor, except as required for
|
130
|
+
reasonable and customary use in describing the origin of the Work and
|
131
|
+
reproducing the content of the NOTICE file.
|
132
|
+
|
133
|
+
7. Disclaimer of Warranty.
|
134
|
+
|
135
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
136
|
+
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
137
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
138
|
+
including, without limitation, any warranties or conditions of TITLE,
|
139
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
140
|
+
solely responsible for determining the appropriateness of using or
|
141
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
142
|
+
permissions under this License.
|
143
|
+
|
144
|
+
8. Limitation of Liability.
|
145
|
+
|
146
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
147
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
148
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
149
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
150
|
+
or consequential damages of any character arising as a result of this License or
|
151
|
+
out of the use or inability to use the Work (including but not limited to
|
152
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
153
|
+
any and all other commercial damages or losses), even if such Contributor has
|
154
|
+
been advised of the possibility of such damages.
|
155
|
+
|
156
|
+
9. Accepting Warranty or Additional Liability.
|
157
|
+
|
158
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
159
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
160
|
+
other liability obligations and/or rights consistent with this License. However,
|
161
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
162
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
163
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
164
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
165
|
+
accepting any such warranty or additional liability.
|
166
|
+
|
167
|
+
END OF TERMS AND CONDITIONS
|
168
|
+
|
169
|
+
APPENDIX: How to apply the Apache License to your work
|
170
|
+
|
171
|
+
To apply the Apache License to your work, attach the following boilerplate
|
172
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
173
|
+
identifying information. (Don't include the brackets!) The text should be
|
174
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
175
|
+
recommend that a file or class name and description of purpose be included on
|
176
|
+
the same "printed page" as the copyright notice for easier identification within
|
177
|
+
third-party archives.
|
178
|
+
|
179
|
+
Copyright [2013] [Rackpace]
|
180
|
+
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
182
|
+
you may not use this file except in compliance with the License.
|
183
|
+
You may obtain a copy of the License at
|
184
|
+
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
186
|
+
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
190
|
+
See the License for the specific language governing permissions and
|
191
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
Mailgun-Ruby
|
2
|
+
============
|
3
|
+
|
4
|
+
[](https://travis-ci.org/mailgun/mailgun-ruby) [](http://badge.fury.io/rb/mailgun-ruby)
|
5
|
+
|
6
|
+
This is the Mailgun Ruby Library. This library contains methods for easily interacting
|
7
|
+
with the Mailgun API.
|
8
|
+
Below are examples to get you started. For additional examples, please see our
|
9
|
+
official documentation at https://documentation.mailgun.com
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
Via RubyGems
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem install mailgun-ruby
|
17
|
+
```
|
18
|
+
|
19
|
+
Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'mailgun-ruby', '~>1.1.6'
|
23
|
+
```
|
24
|
+
|
25
|
+
Usage
|
26
|
+
-----
|
27
|
+
Here's how to send a message using the library:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'mailgun'
|
31
|
+
|
32
|
+
# First, instantiate the Mailgun Client with your API key
|
33
|
+
mg_client = Mailgun::Client.new 'your-api-key'
|
34
|
+
|
35
|
+
# Define your message parameters
|
36
|
+
message_params = { from: 'bob@sending_domain.com',
|
37
|
+
to: 'sally@example.com',
|
38
|
+
subject: 'The Ruby SDK is awesome!',
|
39
|
+
text: 'It is really easy to send a message!'
|
40
|
+
}
|
41
|
+
|
42
|
+
# Send your message through the client
|
43
|
+
mg_client.send_message 'sending_domain.com', message_params
|
44
|
+
```
|
45
|
+
|
46
|
+
Or obtain the last couple log items:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# First, instantiate the Mailgun Client with your API key
|
50
|
+
mg_client = Mailgun::Client.new 'your-secret-api-key'
|
51
|
+
|
52
|
+
# Define the domain you wish to query
|
53
|
+
domain = 'example.com'
|
54
|
+
|
55
|
+
# Issue the get request
|
56
|
+
result = mg_client.get("#{domain}/events", {:event => 'delivered'})
|
57
|
+
```
|
58
|
+
|
59
|
+
Rails
|
60
|
+
-----
|
61
|
+
|
62
|
+
The library can be initialized with a Rails initializer containing similar:
|
63
|
+
```ruby
|
64
|
+
Mailgun.configure do |config|
|
65
|
+
config.api_key = 'your-secret-api-key'
|
66
|
+
end
|
67
|
+
```
|
68
|
+
Or have the initializer read your environment setting if you perfer.
|
69
|
+
|
70
|
+
To use as the ActionMailer delivery method, add this to your `config/environments/whatever.rb`
|
71
|
+
and replace `api-myapikey` and `mydomain.com` with your secret API key and domain, respectively:
|
72
|
+
```ruby
|
73
|
+
config.action_mailer.delivery_method = :mailgun
|
74
|
+
config.action_mailer.mailgun_settings = {
|
75
|
+
api_key: 'api-myapikey',
|
76
|
+
domain: 'mydomain.com',
|
77
|
+
}
|
78
|
+
```
|
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
|
+
|
88
|
+
Response
|
89
|
+
--------
|
90
|
+
|
91
|
+
The results are returned in a Response class:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
result = mg_client.get("#{domain}/events", {:event => 'delivered'})
|
95
|
+
|
96
|
+
# To Ruby standard Hash.
|
97
|
+
result.to_h
|
98
|
+
|
99
|
+
# To YAML.
|
100
|
+
result.to_yaml
|
101
|
+
|
102
|
+
# Or raw JSON
|
103
|
+
result.body
|
104
|
+
```
|
105
|
+
|
106
|
+
Here's an example, breaking out the response:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
mg_client = Mailgun::Client.new("your-api-key")
|
110
|
+
|
111
|
+
message_params = {
|
112
|
+
from: 'bob@example.com',
|
113
|
+
to: 'sally@example.com',
|
114
|
+
subject: 'The Ruby SDK is awesome!',
|
115
|
+
text: 'It is really easy to send a message!'
|
116
|
+
}
|
117
|
+
|
118
|
+
result = mg_client.send_message('example.com', message_params).to_h!
|
119
|
+
|
120
|
+
message_id = result['id']
|
121
|
+
message = result['message']
|
122
|
+
```
|
123
|
+
|
124
|
+
Debugging
|
125
|
+
---------
|
126
|
+
|
127
|
+
Debugging the Ruby Library can be really helpful when things aren't working quite right.
|
128
|
+
To debug the library, here are some suggestions:
|
129
|
+
|
130
|
+
Set the endpoint to Mailgun's Postbin. A Postbin is a web service that allows you to
|
131
|
+
post data, which is then displayed through a browser. This allows you to quickly determine
|
132
|
+
what is actually being transmitted to Mailgun's API.
|
133
|
+
|
134
|
+
**Step 1 - Create a new Postbin.**
|
135
|
+
Go to http://bin.mailgun.net. The Postbin will generate a special URL. Save that URL.
|
136
|
+
|
137
|
+
**Step 2 - Instantiate the Mailgun client using Postbin.**
|
138
|
+
|
139
|
+
*Tip: The bin id will be the URL part after bin.mailgun.net. It will be random generated letters and numbers.
|
140
|
+
For example, the bin id in this URL, http://bin.mailgun.net/aecf68de, is "aecf68de".*
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
# First, instantiate the Mailgun Client with your API key
|
144
|
+
mg_client = Mailgun::Client.new("your-api-key", "bin.mailgun.net", "aecf68de", ssl = false)
|
145
|
+
|
146
|
+
# Define your message parameters
|
147
|
+
message_params = { from: 'bob@sending_domain.com',
|
148
|
+
to: 'sally@example.com',
|
149
|
+
subject: 'The Ruby SDK is awesome!',
|
150
|
+
text: 'It is really easy to send a message!'
|
151
|
+
}
|
152
|
+
|
153
|
+
# Send your message through the client
|
154
|
+
mg_client.send_message("sending_domain.com", message_params)
|
155
|
+
```
|
156
|
+
|
157
|
+
For usage examples on each API endpoint, head over to our official documentation
|
158
|
+
pages. Or the [Snippets](docs/Snippets.md) file.
|
159
|
+
|
160
|
+
This SDK includes the following components:
|
161
|
+
- [Messages](docs/Messages.md)
|
162
|
+
- [Message Builder](docs/MessageBuilder.md)
|
163
|
+
- [Batch Message](docs/MessageBuilder.md)
|
164
|
+
- [Opt-In Handler](docs/OptInHandler.md)
|
165
|
+
- [Domains](docs/Domains.md)
|
166
|
+
- [Webhooks](docs/Webhooks.md)
|
167
|
+
- [Events](docs/Events.md)
|
168
|
+
- [Suppressions](docs/Suppressions.md)
|
169
|
+
|
170
|
+
Message Builder allows you to quickly create the array of parameters, required
|
171
|
+
to send a message, by calling a methods for each parameter.
|
172
|
+
Batch Message is an extension of Message Builder, and allows you to easily send
|
173
|
+
a batch message job within a few seconds. The complexity of
|
174
|
+
batch messaging is eliminated!
|
175
|
+
|
176
|
+
Testing mail deliveries
|
177
|
+
----------------------
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
# First, instantiate the Mailgun Client with your API key
|
181
|
+
mg_client = Mailgun::Client.new 'your-api-key'
|
182
|
+
|
183
|
+
# Put the client in test mode
|
184
|
+
mg_client.enable_test_mode!
|
185
|
+
|
186
|
+
# Define your message parameters
|
187
|
+
message_params = { from: 'bob@sending_domain.com',
|
188
|
+
to: 'sally@example.com',
|
189
|
+
subject: 'The Ruby SDK is awesome!',
|
190
|
+
text: 'It is really easy to send a message!'
|
191
|
+
}
|
192
|
+
|
193
|
+
# Send your message through the client
|
194
|
+
# Note: This will not actually hit the API, and will return a generic OK response.
|
195
|
+
mg_client.send_message('sending_domain.com', message_params)
|
196
|
+
|
197
|
+
# You can now access a copy of message_params
|
198
|
+
Mailgun::Client.deliveries.first[:from] # => 'bob@sending_domain.com'
|
199
|
+
```
|
200
|
+
|
201
|
+
Testing
|
202
|
+
-------
|
203
|
+
|
204
|
+
There are unit tests and integration tests. Unit tests do not require Mailgun account keys. Integration tests do.
|
205
|
+
By default:
|
206
|
+
```
|
207
|
+
bundle exec rake spec
|
208
|
+
```
|
209
|
+
will run just unit tests. To run integration tests:
|
210
|
+
```
|
211
|
+
bundle exec rake spec:integration
|
212
|
+
```
|
213
|
+
will run just integration tests.
|
214
|
+
```
|
215
|
+
bundle exec rake spec:all
|
216
|
+
```
|
217
|
+
will run all both types.
|
218
|
+
|
219
|
+
Integrations tests will run against [VCR](https://github.com/vcr/vcr) cassettes if they exist.
|
220
|
+
If you'd like to run tests against your mailgun account, remove the cassettes.
|
221
|
+
|
222
|
+
To set up Mailgun key information. See the example file: .ruby-env.yml.example.
|
223
|
+
Rename this file to .ruby-env.yml and replace the items between the <> (including the <>) with the private
|
224
|
+
and public keys, and sandbox domain. Alternatively use a different domain registered in Mailgun if you
|
225
|
+
have one you want to test against.
|
226
|
+
|
227
|
+
The MAILGUN_* variables in .ruby-env.yml(.example) can also be set as
|
228
|
+
environment variables, if you'd like to do that instead.
|
229
|
+
|
230
|
+
Support and Feedback
|
231
|
+
--------------------
|
232
|
+
|
233
|
+
Be sure to visit the Mailgun official
|
234
|
+
[documentation website](https://documentation.mailgun.com/) for additional
|
235
|
+
information about our API.
|
236
|
+
|
237
|
+
If you find a bug, please submit the issue in Github directly.
|
238
|
+
[Mailgun-Ruby Issues](https://github.com/mailgun/mailgun-ruby/issues)
|
239
|
+
|
240
|
+
As always, if you need additional assistance, drop us a note through your Control Panel at
|
241
|
+
[https://mailgun.com/cp/support](https://mailgun.com/cp/support).
|