mailgun-ruby 1.1.2 → 1.1.6
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-env.yml.example +1 -1
- data/.travis.yml +6 -4
- data/README.md +46 -8
- data/{Domains.md → docs/Domains.md} +18 -0
- data/{Events.md → docs/Events.md} +0 -0
- data/{MessageBuilder.md → docs/MessageBuilder.md} +21 -5
- data/{Messages.md → docs/Messages.md} +3 -3
- data/{OptInHandler.md → docs/OptInHandler.md} +0 -0
- data/{Snippets.md → docs/Snippets.md} +21 -2
- data/docs/Suppressions.md +82 -0
- data/{Webhooks.md → docs/Webhooks.md} +0 -0
- data/lib/mailgun/client.rb +27 -3
- data/lib/mailgun/events/events.rb +23 -6
- data/lib/mailgun/messages/batch_message.rb +2 -2
- data/lib/mailgun/messages/message_builder.rb +79 -24
- data/lib/mailgun/suppressions.rb +270 -0
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun-ruby.rb +2 -1
- data/lib/railgun/attachment.rb +56 -0
- data/lib/railgun/errors.rb +27 -0
- data/lib/railgun/mailer.rb +158 -0
- data/lib/railgun/message.rb +17 -0
- data/lib/railgun/railtie.rb +9 -0
- data/lib/railgun.rb +8 -0
- data/mailgun.gemspec +1 -1
- data/spec/integration/events_spec.rb +9 -1
- data/spec/integration/mailgun_spec.rb +0 -0
- data/spec/integration/suppressions_spec.rb +126 -0
- data/spec/unit/events/events_spec.rb +17 -2
- data/spec/unit/messages/message_builder_spec.rb +44 -7
- data/vcr_cassettes/events.yml +48 -1
- data/vcr_cassettes/suppressions.yml +676 -0
- metadata +21 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e16b23def5c2076ebf90803c69e67c11275dd4cf
|
4
|
+
data.tar.gz: 538a0a0aa99f037d0ef044fc9d427483eb4073b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c76cf234af827e8280e5eaa466d961817d30c3875345f4c481871ac8ca5083f11d4257ab06531c12dd693eab09e70910e6feaa13576766cd689caa32653c1f6
|
7
|
+
data.tar.gz: 305a1d5edc83fef3006682c884d9abee4ecf190e40919008b8985e6a86e5dd4f1506c3344a7641f67a435a5a3f510f1e350fb63daccb25fbcdec5cbfc1a20617
|
data/.ruby-env.yml.example
CHANGED
@@ -7,6 +7,6 @@
|
|
7
7
|
# Replace <THESE_VALUES> with yours from
|
8
8
|
# https://mailgun.com/app/dashboard (don't include <brackets>)
|
9
9
|
# and rename to/save as: .ruby-env.yml
|
10
|
-
MAILGUN_APIKEY : '<MAILGUN_APIKEY'
|
10
|
+
MAILGUN_APIKEY : '<MAILGUN_APIKEY>'
|
11
11
|
MAILGUN_PUB_APIKEY : '<MAILGUN_PUBLIC_APIKEY>'
|
12
12
|
MAILGUN_TESTDOMAIN : '<MAILGUN_SANDBOX_DOMAIN>'
|
data/.travis.yml
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
rvm:
|
4
|
-
- 2.3.1
|
5
|
-
- 2.2
|
6
|
-
- 2.1
|
7
4
|
- 2.0.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- 2.3.1
|
8
8
|
script:
|
9
|
+
- bundle install
|
9
10
|
- bundle exec rake spec
|
10
11
|
- '[[ "${TRAVIS_PULL_REQUEST}" == "false" ]] && ( bundle exec rake spec:integration
|
11
12
|
) || ( echo "Testing PR - No integration tests available")'
|
12
13
|
deploy:
|
13
14
|
provider: rubygems
|
14
15
|
api_key:
|
15
|
-
secure:
|
16
|
+
secure: DoX3w48gRyhDM1o1OLvtWsTi8ehLIarIsErzg/UlNRoLacQt5l5UzwD+u6wqsCEr4+c2uAHNahafpnw/j1rPG3LBPIXOK5A0SYbjovlckutiAC0330Q4PHwOZb73AFN1DG5JTeg4/fguEjdsEBdZObF7mh5gBMBQtNjo1Fos+4w=
|
16
17
|
gemspec: mailgun.gemspec
|
17
18
|
on:
|
18
19
|
tags: true
|
20
|
+
condition: "$TRAVIS_RUBY_VERSION == 2.3.1"
|
19
21
|
notifications:
|
20
22
|
slack:
|
21
23
|
rooms:
|
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.1.
|
22
|
+
gem 'mailgun-ruby', '~>1.1.6'
|
23
23
|
```
|
24
24
|
|
25
25
|
Usage
|
@@ -27,6 +27,8 @@ Usage
|
|
27
27
|
Here's how to send a message using the library:
|
28
28
|
|
29
29
|
```ruby
|
30
|
+
require 'mailgun'
|
31
|
+
|
30
32
|
# First, instantiate the Mailgun Client with your API key
|
31
33
|
mg_client = Mailgun::Client.new 'your-api-key'
|
32
34
|
|
@@ -65,6 +67,15 @@ end
|
|
65
67
|
```
|
66
68
|
Or have the initializer read your environment setting if you perfer.
|
67
69
|
|
70
|
+
To use as the ActionMailer delivery method, add this to your `config/environments/whatever.yml`
|
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
|
+
```
|
68
79
|
|
69
80
|
Response
|
70
81
|
--------
|
@@ -136,15 +147,17 @@ mg_client.send_message("sending_domain.com", message_params)
|
|
136
147
|
```
|
137
148
|
|
138
149
|
For usage examples on each API endpoint, head over to our official documentation
|
139
|
-
pages. Or the [Snippets](Snippets.md) file.
|
150
|
+
pages. Or the [Snippets](docs/Snippets.md) file.
|
140
151
|
|
141
152
|
This SDK includes the following components:
|
142
|
-
- [
|
143
|
-
- [
|
144
|
-
- [
|
145
|
-
- [
|
146
|
-
- [
|
147
|
-
- [
|
153
|
+
- [Messages](docs/Messages.md)
|
154
|
+
- [Message Builder](docs/MessageBuilder.md)
|
155
|
+
- [Batch Message](docs/MessageBuilder.md)
|
156
|
+
- [Opt-In Handler](docs/OptInHandler.md)
|
157
|
+
- [Domains](docs/Domains.md)
|
158
|
+
- [Webhooks](docs/Webhooks.md)
|
159
|
+
- [Events](docs/Events.md)
|
160
|
+
- [Suppressions](docs/Suppressions.md)
|
148
161
|
|
149
162
|
Message Builder allows you to quickly create the array of parameters, required
|
150
163
|
to send a message, by calling a methods for each parameter.
|
@@ -152,6 +165,31 @@ Batch Message is an extension of Message Builder, and allows you to easily send
|
|
152
165
|
a batch message job within a few seconds. The complexity of
|
153
166
|
batch messaging is eliminated!
|
154
167
|
|
168
|
+
Testing mail deliveries
|
169
|
+
----------------------
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
# First, instantiate the Mailgun Client with your API key
|
173
|
+
mg_client = Mailgun::Client.new 'your-api-key'
|
174
|
+
|
175
|
+
# Put the client in test mode
|
176
|
+
mg_client.enable_test_mode!
|
177
|
+
|
178
|
+
# Define your message parameters
|
179
|
+
message_params = { from: 'bob@sending_domain.com',
|
180
|
+
to: 'sally@example.com',
|
181
|
+
subject: 'The Ruby SDK is awesome!',
|
182
|
+
text: 'It is really easy to send a message!'
|
183
|
+
}
|
184
|
+
|
185
|
+
# Send your message through the client
|
186
|
+
# Note: This will not actually hit the API, and will return a generic OK response.
|
187
|
+
mg_client.send_message('sending_domain.com', message_params)
|
188
|
+
|
189
|
+
# You can now access a copy of message_params
|
190
|
+
Mailgun::Client.deliveries.first[:from] # => 'bob@sending_domain.com'
|
191
|
+
```
|
192
|
+
|
155
193
|
Testing
|
156
194
|
-------
|
157
195
|
|
@@ -30,6 +30,24 @@ domainer.create 'my.new.moreness', { some: 'options' }
|
|
30
30
|
domainer.remove 'this.one.is.not.needed.'
|
31
31
|
```
|
32
32
|
|
33
|
+
Suppressions for a Domain
|
34
|
+
-------------------------
|
35
|
+
|
36
|
+
You can manage domain suppressions (bounces, unsubscribes, complaints) using the
|
37
|
+
[`Mailgun::Suppressions`](/docs/Suppressions.md) client:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# Instantiate the Mailgun Client with your API key
|
41
|
+
mg_client = Mailgun::Client.new('your-api-key')
|
42
|
+
supp_client = mg_client.suppressions('example.org')
|
43
|
+
|
44
|
+
# ...
|
45
|
+
```
|
46
|
+
|
47
|
+
See the [Suppressions](/docs/Suppressions.md) for usage samples and
|
48
|
+
[suppressions.rb](/lib/mailgun/suppressions.rb) for suppressions client API.
|
49
|
+
|
50
|
+
|
33
51
|
More Documentation
|
34
52
|
------------------
|
35
53
|
See the official [Mailgun Domain Docs](https://documentation.mailgun.com/api-domains.html)
|
File without changes
|
@@ -24,28 +24,41 @@ mb_obj = Mailgun::MessageBuilder.new()
|
|
24
24
|
|
25
25
|
# Define the from address.
|
26
26
|
mb_obj.from("me@example.com", {"first"=>"Ruby", "last" => "SDK"});
|
27
|
+
|
27
28
|
# Define a to recipient.
|
28
29
|
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John", "last" => "Doe"});
|
30
|
+
|
29
31
|
# Define a cc recipient.
|
30
32
|
mb_obj.add_recipient(:cc, "sally.doe@example.com", {"first" => "Sally", "last" => "Doe"});
|
33
|
+
|
31
34
|
# Define the subject.
|
32
35
|
mb_obj.subject("A message from the Ruby SDK using Message Builder!");
|
36
|
+
|
33
37
|
# Define the body of the message.
|
34
38
|
mb_obj.body_text("This is the text body of the message!");
|
39
|
+
|
35
40
|
# Set the Message-Id header, provide a valid Message-Id.
|
36
41
|
mb_obj.message_id("<20141014000000.11111.11111@example.com>")
|
42
|
+
|
37
43
|
# Or clear the Message-Id header, provide nil or empty string.
|
38
44
|
mb_obj.message_id(nil)
|
39
45
|
mb_obj.message_id('')
|
40
|
-
|
46
|
+
|
47
|
+
# Campaigns and headers.
|
41
48
|
mb_obj.add_campaign_id("My-Awesome-Campaign");
|
42
|
-
mb_obj.
|
49
|
+
mb_obj.header("Customer-Id", "12345");
|
50
|
+
|
51
|
+
# Custom variables
|
52
|
+
mb_obj.variable("Customer-Data", { :first_name => "John", :last_name => "Smith" })
|
43
53
|
|
44
54
|
# Attach a file and rename it.
|
45
|
-
mb_obj.add_attachment
|
55
|
+
mb_obj.add_attachment "/path/to/file/receipt_123491820.pdf", "Receipt.pdf"
|
56
|
+
|
57
|
+
# Attach an image inline.
|
58
|
+
mb_obj.add_inline_image "/path/to/file/header.png"
|
46
59
|
|
47
60
|
# Schedule message in the future
|
48
|
-
mb_obj.
|
61
|
+
mb_obj.deliver_at("tomorrow 8:00AM PST");
|
49
62
|
|
50
63
|
# Finally, send your message using the client
|
51
64
|
result = mg_client.send_message("sending_domain.com", mb_obj)
|
@@ -60,13 +73,16 @@ Here's how to use Batch Message to easily handle batch sending jobs.
|
|
60
73
|
```ruby
|
61
74
|
# First, instantiate the Mailgun Client with your API key
|
62
75
|
mg_client = Mailgun::Client.new("your-api-key")
|
76
|
+
|
63
77
|
# Create a Batch Message object, pass in the client and your domain.
|
64
78
|
mb_obj = Mailgun::BatchMessage.new(mg_client, "example.com")
|
65
79
|
|
66
80
|
# Define the from address.
|
67
|
-
mb_obj.from("me@example.com", {"first"=>"Ruby", "last" => "SDK"});
|
81
|
+
mb_obj.from("me@example.com", {"first" => "Ruby", "last" => "SDK"});
|
82
|
+
|
68
83
|
# Define the subject.
|
69
84
|
mb_obj.subject("A message from the Ruby SDK using Message Builder!");
|
85
|
+
|
70
86
|
# Define the body of the message.
|
71
87
|
mb_obj.body_text("This is the text body of the message!");
|
72
88
|
|
@@ -50,8 +50,8 @@ mb_obj.set_message_id('')
|
|
50
50
|
|
51
51
|
# Other Optional Parameters.
|
52
52
|
mb_obj.add_campaign_id("My-Awesome-Campaign")
|
53
|
-
mb_obj.
|
54
|
-
mb_obj.add_attachment("
|
53
|
+
mb_obj.header("Customer-Id", "12345")
|
54
|
+
mb_obj.add_attachment("./tron.jpg")
|
55
55
|
mb_obj.set_delivery_time("tomorrow 8:00AM PST")
|
56
56
|
mb_obj.set_click_tracking(true)
|
57
57
|
|
@@ -79,7 +79,7 @@ mb_obj.set_text_body("Hello %recipient.first%,
|
|
79
79
|
This is the text body of the message
|
80
80
|
using recipient variables!
|
81
81
|
If you need to include custom data,
|
82
|
-
you could do it like this: %account-id%.")
|
82
|
+
you could do it like this: %recipient.account-id%.")
|
83
83
|
|
84
84
|
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John",
|
85
85
|
"last" => "Doe",
|
File without changes
|
@@ -41,8 +41,7 @@ mg_client.send_message "sending_domain.com", data
|
|
41
41
|
|
42
42
|
```ruby
|
43
43
|
# Don't include a file, pull the file to a string
|
44
|
-
mime_string = '
|
45
|
-
From: Bob Sample <example@example.com>
|
44
|
+
mime_string = 'From: Bob Sample <example@example.com>
|
46
45
|
MIME-Version: 1.0
|
47
46
|
Content-Type: multipart/mixed;
|
48
47
|
boundary="--boundary-goes-here--"
|
@@ -76,6 +75,26 @@ mb_obj.set_text_body "This is the text body."
|
|
76
75
|
mg_client.send_message "sending_domain.com", mb_obj
|
77
76
|
```
|
78
77
|
|
78
|
+
**Build a message with attachments, part by part, with Message Builder:**
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
mb_obj = Mailgun::MessageBuilder.new
|
82
|
+
|
83
|
+
mb_obj.set_from_address "sender@example.com", {'first' => 'Sending', 'last' => 'User'}
|
84
|
+
mb_obj.add_recipient :to, "recipient@example.com", {'first' => 'Recipient', 'last' => 'User'}
|
85
|
+
mb_obj.set_subject "This is the subject!"
|
86
|
+
mb_obj.set_text_body "This is the text body."
|
87
|
+
|
88
|
+
# Add separate attachments
|
89
|
+
mb_obj.add_attachment "/path/to/file/invoice_8675309.pdf", "Order Invoice - 8675309.pdf"
|
90
|
+
mb_obj.add_attachment "/path/to/file/datasheet_00001.pdf", "Product Datasheet - 00001.pdf"
|
91
|
+
|
92
|
+
# Attach inline image to message
|
93
|
+
mb_obj.add_inline_image "/path/to/file/product_image_00001.png"
|
94
|
+
|
95
|
+
mg_client.send_message "sending_domain.com", mb_obj
|
96
|
+
```
|
97
|
+
|
79
98
|
**Send batches of 1000 messages per post:**
|
80
99
|
|
81
100
|
```ruby
|
@@ -0,0 +1,82 @@
|
|
1
|
+
Mailgun - Suppressions
|
2
|
+
====================
|
3
|
+
|
4
|
+
This is the Mailgun Ruby *Suppressions* 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
|
+
The Suppressions client lets you manage bounces, unsubscribes, and complaints for a
|
13
|
+
single domain.
|
14
|
+
|
15
|
+
You can view additional samples in the [suppressions_spec.rb](/spec/integration/suppressions_spec.rb)
|
16
|
+
or the Suppressions client API in [suppressions.rb](/lib/mailgun/suppressions.rb).
|
17
|
+
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
To get an instance of the Suppressions client:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
mg_client = Mailgun::Client.new('api_key')
|
26
|
+
supp_client = mg_client.suppressions('yourdomain.com')
|
27
|
+
```
|
28
|
+
|
29
|
+
----
|
30
|
+
|
31
|
+
To get a list of bounces, unsubscribes, and/or complaints:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
supp_client.list_bounces
|
35
|
+
supp_client.list_unsubscribes
|
36
|
+
supp_client.list_complaints
|
37
|
+
```
|
38
|
+
|
39
|
+
----
|
40
|
+
|
41
|
+
To batch-add a set of bounces:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
@addresses = <load or generate some addresses...>
|
45
|
+
|
46
|
+
bounces = []
|
47
|
+
@addresses.each do |addr|
|
48
|
+
bounces.push({
|
49
|
+
:address => addr,
|
50
|
+
:code => 500,
|
51
|
+
:error => 'some bounce because reasons',
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
response, addt_responses = @supp_client.create_bounces bounces
|
56
|
+
```
|
57
|
+
|
58
|
+
`create_bounces`, `create_unsubscribes`, and `create_complaints` will all
|
59
|
+
return two values - first, a simple `Mailgun::Response` object. Second,
|
60
|
+
a list containing any `Mailgun::Response` objects created recursively, if over 998
|
61
|
+
bounces were provided to `create_*`.
|
62
|
+
|
63
|
+
----
|
64
|
+
|
65
|
+
To delete bounces:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
@addresses = <load addresses...>
|
69
|
+
|
70
|
+
@addresses.each do |addr|
|
71
|
+
@supp_client.delete_bounce addr
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Or, alternatively, to remove *all* bounces:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
@supp_client.delete_all_bounces
|
79
|
+
```
|
80
|
+
|
81
|
+
The `delete_*` methods are similar for `bounces`, `unsubscribe`, and `complaints` -
|
82
|
+
they all will return a `Mailgun::Response` object.
|
File without changes
|
data/lib/mailgun/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mailgun/chains'
|
2
|
+
require 'mailgun/suppressions'
|
2
3
|
require 'mailgun/exceptions/exceptions'
|
3
4
|
|
4
5
|
module Mailgun
|
@@ -44,6 +45,13 @@ module Mailgun
|
|
44
45
|
@test_mode
|
45
46
|
end
|
46
47
|
|
48
|
+
# Provides a store of all the emails sent in test mode so you can check them.
|
49
|
+
#
|
50
|
+
# @return [Hash]
|
51
|
+
def self.deliveries
|
52
|
+
@@deliveries ||= []
|
53
|
+
end
|
54
|
+
|
47
55
|
# Simple Message Sending
|
48
56
|
#
|
49
57
|
# @param [String] working_domain This is the domain you wish to send from.
|
@@ -52,6 +60,7 @@ module Mailgun
|
|
52
60
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
53
61
|
def send_message(working_domain, data)
|
54
62
|
if test_mode? then
|
63
|
+
Mailgun::Client.deliveries << data
|
55
64
|
return Response.from_hash(
|
56
65
|
{
|
57
66
|
:body => '{"id": "test-mode-mail@localhost", "message": "Queued. Thank you."}',
|
@@ -62,6 +71,11 @@ module Mailgun
|
|
62
71
|
|
63
72
|
case data
|
64
73
|
when Hash
|
74
|
+
# Remove nil values from the data hash
|
75
|
+
# Submitting nils to the API will likely cause an error.
|
76
|
+
# See also: https://github.com/mailgun/mailgun-ruby/issues/32
|
77
|
+
data = data.select { |k, v| v != nil }
|
78
|
+
|
65
79
|
if data.key?(:message)
|
66
80
|
if data[:message].is_a?(String)
|
67
81
|
data[:message] = convert_string_to_file(data[:message])
|
@@ -82,9 +96,10 @@ module Mailgun
|
|
82
96
|
# with. Be sure to include your domain, where necessary.
|
83
97
|
# @param [Hash] data This should be a standard Hash
|
84
98
|
# containing required parameters for the requested resource.
|
99
|
+
# @param [Hash] headers Additional headers to pass to the resource.
|
85
100
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
86
|
-
def post(resource_path, data)
|
87
|
-
response = @http_client[resource_path].post(data)
|
101
|
+
def post(resource_path, data, headers = {})
|
102
|
+
response = @http_client[resource_path].post(data, headers)
|
88
103
|
Response.new(response)
|
89
104
|
rescue => err
|
90
105
|
raise communication_error err
|
@@ -94,8 +109,9 @@ module Mailgun
|
|
94
109
|
#
|
95
110
|
# @param [String] resource_path This is the API resource you wish to interact
|
96
111
|
# with. Be sure to include your domain, where necessary.
|
97
|
-
# @param [Hash]
|
112
|
+
# @param [Hash] params This should be a standard Hash
|
98
113
|
# containing required parameters for the requested resource.
|
114
|
+
# @param [String] accept Acceptable Content-Type of the response body.
|
99
115
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
100
116
|
def get(resource_path, params = nil, accept = '*/*')
|
101
117
|
if params
|
@@ -134,6 +150,14 @@ module Mailgun
|
|
134
150
|
raise communication_error err
|
135
151
|
end
|
136
152
|
|
153
|
+
# Constructs a Suppressions client for the given domain.
|
154
|
+
#
|
155
|
+
# @param [String] domain Domain which suppressions requests will be made for
|
156
|
+
# @return [Mailgun::Suppressions]
|
157
|
+
def suppressions(domain)
|
158
|
+
Suppressions.new(self, domain)
|
159
|
+
end
|
160
|
+
|
137
161
|
private
|
138
162
|
|
139
163
|
# Converts MIME string to file for easy uploading to API
|
@@ -11,6 +11,7 @@ module Mailgun
|
|
11
11
|
#
|
12
12
|
# See the Github documentation for full examples.
|
13
13
|
class Events
|
14
|
+
include Enumerable
|
14
15
|
|
15
16
|
# Public: event initializer
|
16
17
|
#
|
@@ -23,31 +24,47 @@ module Mailgun
|
|
23
24
|
@paging_previous = nil
|
24
25
|
end
|
25
26
|
|
26
|
-
# Public: Issues a simple get against the client.
|
27
|
+
# Public: Issues a simple get against the client. Alias of `next`.
|
27
28
|
#
|
28
29
|
# params - a Hash of query options and/or filters.
|
29
30
|
#
|
30
31
|
# Returns a Mailgun::Response object.
|
31
32
|
def get(params = nil)
|
32
|
-
|
33
|
+
self.next(params)
|
33
34
|
end
|
34
35
|
|
35
36
|
# Public: Using built in paging, obtains the next set of data.
|
36
37
|
# If an events request hasn't been sent previously, this will send one
|
37
38
|
# without parameters
|
38
39
|
#
|
40
|
+
# params - a Hash of query options and/or filters.
|
41
|
+
#
|
39
42
|
# Returns a Mailgun::Response object.
|
40
|
-
def next
|
41
|
-
get_events(
|
43
|
+
def next(params = nil)
|
44
|
+
get_events(params, @paging_next)
|
42
45
|
end
|
43
46
|
|
44
47
|
# Public: Using built in paging, obtains the previous set of data.
|
45
48
|
# If an events request hasn't been sent previously, this will send one
|
46
49
|
# without parameters
|
47
50
|
#
|
51
|
+
# params - a Hash of query options and/or filters.
|
52
|
+
#
|
48
53
|
# Returns Mailgun::Response object.
|
49
|
-
def previous
|
50
|
-
get_events(
|
54
|
+
def previous(params = nil)
|
55
|
+
get_events(params, @paging_previous)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Public: Allows iterating through all events and performs automatic paging.
|
59
|
+
#
|
60
|
+
# &block - Block to execute on items.
|
61
|
+
def each(&block)
|
62
|
+
items = self.next.to_h['items']
|
63
|
+
|
64
|
+
until items.empty?
|
65
|
+
items.each(&block)
|
66
|
+
items = self.next.to_h['items']
|
67
|
+
end
|
51
68
|
end
|
52
69
|
|
53
70
|
private
|
@@ -48,7 +48,7 @@ module Mailgun
|
|
48
48
|
send_message if @counters[:recipients][recipient_type] == Mailgun::Chains::MAX_RECIPIENTS
|
49
49
|
|
50
50
|
compiled_address = parse_address(address, variables)
|
51
|
-
|
51
|
+
set_multi_complex(recipient_type, compiled_address)
|
52
52
|
|
53
53
|
store_recipient_variables(recipient_type, address, variables) if recipient_type != :from
|
54
54
|
|
@@ -84,7 +84,7 @@ module Mailgun
|
|
84
84
|
# @return [Boolean]
|
85
85
|
def send_message
|
86
86
|
rkey = 'recipient-variables'
|
87
|
-
|
87
|
+
set_multi_simple rkey, JSON.generate(@recipient_variables)
|
88
88
|
@message[rkey] = @message[rkey].first if @message.key?(rkey)
|
89
89
|
|
90
90
|
response = @client.send_message(@domain, @message).to_h!
|