mailgun-ruby 1.0.0 → 1.0.1
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/Messages.md +15 -15
- data/README.md +36 -36
- data/lib/mailgun.rb +14 -14
- data/lib/mailgun/messages/batch_message.rb +17 -17
- data/lib/mailgun/messages/message_builder.rb +26 -20
- data/lib/mailgun/version.rb +2 -2
- data/mailgun.gemspec +3 -4
- data/spec/unit/mailgun_spec.rb +0 -2
- data/spec/unit/messages/batch_message_spec.rb +2 -2
- data/spec/unit/messages/message_builder_spec.rb +0 -5
- metadata +5 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e560063e4d8cf1632c762c36b84bafa2c7eb356
|
4
|
+
data.tar.gz: df5159ba95e42cdb82a4102c6af18f6e35c3523b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50ad029f9bf264cc0393413a61b3de2fd24269cac123d1ea26e72edc320fd8cf9d9080d346604c2aaf4055edf2e990453beadeee096cf03df58801522dab5420
|
7
|
+
data.tar.gz: 9c5228866ab40ae51021adf56cb71ba578de65c9fc8d72f0b9af7985c2971357bd3cc12333b41037826af4d46a01322c05d4d1be949baa9a034dde5e11fc74ed
|
data/Messages.md
CHANGED
@@ -1,27 +1,27 @@
|
|
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
|
-
The below assumes you've already installed the Mailgun Ruby SDK in to your
|
6
|
+
The below assumes you've already installed the Mailgun Ruby SDK in to your
|
7
7
|
project. If not, go back to the master README for instructions.
|
8
8
|
|
9
|
-
There are two utilities included, Message Builder and Batch Message.
|
9
|
+
There are two utilities included, Message Builder and Batch Message.
|
10
10
|
|
11
|
-
Message Builder: Allows you to build a message object by calling methods for
|
12
|
-
each MIME attribute.
|
13
|
-
Batch Message: Inherits Message Builder and allows you to iterate through
|
14
|
-
recipients from a list. Messages will fire after the 1,000th recipient has been
|
15
|
-
added.
|
11
|
+
Message Builder: Allows you to build a message object by calling methods for
|
12
|
+
each MIME attribute.
|
13
|
+
Batch Message: Inherits Message Builder and allows you to iterate through
|
14
|
+
recipients from a list. Messages will fire after the 1,000th recipient has been
|
15
|
+
added.
|
16
16
|
|
17
17
|
Usage - Message Builder
|
18
18
|
-----------------------
|
19
|
-
Here's how to use Message Builder to build your Message.
|
19
|
+
Here's how to use Message Builder to build your Message.
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
# First, instantiate the Mailgun Client with your API key
|
23
23
|
mg_client = Mailgun::Client.new("your-api-key")
|
24
|
-
mb_obj = Mailgun::
|
24
|
+
mb_obj = Mailgun::MessageBuilder.new(@mb_client, "example.com")
|
25
25
|
|
26
26
|
# Define the from address.
|
27
27
|
mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"});
|
@@ -29,7 +29,7 @@ mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"});
|
|
29
29
|
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John", "last" => "Doe"});
|
30
30
|
# Define a cc recipient.
|
31
31
|
mb_obj.add_recipient(:cc, "sally.doe@example.com", {"first" => "Sally", "last" => "Doe"});
|
32
|
-
# Define the subject.
|
32
|
+
# Define the subject.
|
33
33
|
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!");
|
34
34
|
# Define the body of the message.
|
35
35
|
mb_obj.set_text_body("This is the text body of the message!");
|
@@ -47,7 +47,7 @@ mg_client.send_message("sending_domain.com", mb_obj)
|
|
47
47
|
|
48
48
|
Usage - Batch Message
|
49
49
|
---------------------
|
50
|
-
Here's how to use Batch Message to easily handle batch sending jobs.
|
50
|
+
Here's how to use Batch Message to easily handle batch sending jobs.
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
# First, instantiate the Mailgun Client with your API key
|
@@ -56,7 +56,7 @@ mb_obj = Mailgun::BatchMessage.new(@mb_client, "example.com")
|
|
56
56
|
|
57
57
|
# Define the from address.
|
58
58
|
mb_obj.set_from_address("me@example.com", {"first"=>"Ruby", "last" => "SDK"});
|
59
|
-
# Define the subject.
|
59
|
+
# Define the subject.
|
60
60
|
mb_obj.set_subject("A message from the Ruby SDK using Message Builder!");
|
61
61
|
# Define the body of the message.
|
62
62
|
mb_obj.set_text_body("This is the text body of the message!");
|
@@ -73,5 +73,5 @@ message_ids = mg_client.finalize
|
|
73
73
|
|
74
74
|
More Documentation
|
75
75
|
------------------
|
76
|
-
See the official [Mailgun Docs](http://documentation.mailgun.com/api-sending.html)
|
77
|
-
for more information.
|
76
|
+
See the official [Mailgun Docs](http://documentation.mailgun.com/api-sending.html)
|
77
|
+
for more information.
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Mailgun-Ruby
|
2
2
|
============
|
3
3
|
|
4
|
-
This is the Mailgun Ruby Library. This library contains methods for easily interacting
|
5
|
-
with the Mailgun API.
|
6
|
-
Below are examples to get you started. For additional examples, please see our
|
7
|
-
official documentation
|
4
|
+
This is the Mailgun Ruby Library. This library contains methods for easily interacting
|
5
|
+
with the Mailgun API.
|
6
|
+
Below are examples to get you started. For additional examples, please see our
|
7
|
+
official documentation
|
8
8
|
at http://documentation.mailgun.com
|
9
9
|
|
10
10
|
Installation
|
@@ -18,7 +18,7 @@ gem install mailgun-ruby
|
|
18
18
|
Gemfile:
|
19
19
|
|
20
20
|
```ruby
|
21
|
-
gem 'mailgun-ruby', "~>1.0.
|
21
|
+
gem 'mailgun-ruby', "~>1.0.1"
|
22
22
|
```
|
23
23
|
|
24
24
|
Include
|
@@ -37,16 +37,16 @@ Here's how to send a message using the library:
|
|
37
37
|
mg_client = Mailgun::Client.new "your-api-key"
|
38
38
|
|
39
39
|
# Define your message parameters
|
40
|
-
message_params = {:from => 'bob@sending_domain.com',
|
41
|
-
:to => 'sally@example.com',
|
42
|
-
:subject => 'The Ruby SDK is awesome!',
|
40
|
+
message_params = {:from => 'bob@sending_domain.com',
|
41
|
+
:to => 'sally@example.com',
|
42
|
+
:subject => 'The Ruby SDK is awesome!',
|
43
43
|
:text => 'It is really easy to send a message!'}
|
44
44
|
|
45
45
|
# Send your message through the client
|
46
46
|
mg_client.send_message "sending_domain.com", message_params
|
47
47
|
```
|
48
48
|
|
49
|
-
Or obtain the last couple log items:
|
49
|
+
Or obtain the last couple log items:
|
50
50
|
|
51
51
|
```ruby
|
52
52
|
# First, instantiate the Mailgun Client with your API key
|
@@ -71,7 +71,7 @@ result = mg_client.get("#{domain}/events", {:event => 'delivered'})
|
|
71
71
|
result.to_h
|
72
72
|
|
73
73
|
# To YAML.
|
74
|
-
result.to_yaml
|
74
|
+
result.to_yaml
|
75
75
|
|
76
76
|
# Or raw JSON
|
77
77
|
result.body
|
@@ -82,11 +82,11 @@ Here's an example, breaking out the response:
|
|
82
82
|
```ruby
|
83
83
|
mg_client = Mailgun::Client.new("your-api-key")
|
84
84
|
|
85
|
-
message_params = {:from => 'bob@example.com',
|
86
|
-
:to => 'sally@example.com',
|
87
|
-
:subject => 'The Ruby SDK is awesome!',
|
85
|
+
message_params = {:from => 'bob@example.com',
|
86
|
+
:to => 'sally@example.com',
|
87
|
+
:subject => 'The Ruby SDK is awesome!',
|
88
88
|
:text => 'It is really easy to send a message!'}
|
89
|
-
|
89
|
+
|
90
90
|
result = mg_client.send_message("example.com", message_params).to_h!
|
91
91
|
|
92
92
|
message_id = result['id']
|
@@ -96,17 +96,17 @@ message = result['message']
|
|
96
96
|
Debugging
|
97
97
|
---------
|
98
98
|
|
99
|
-
Debugging the Ruby Library can be really helpful when things aren't working quite right.
|
100
|
-
To debug the library, here are some suggestions:
|
99
|
+
Debugging the Ruby Library can be really helpful when things aren't working quite right.
|
100
|
+
To debug the library, here are some suggestions:
|
101
101
|
|
102
|
-
Set the endpoint to Mailgun's Postbin. A Postbin is a web service that allows you to
|
102
|
+
Set the endpoint to Mailgun's Postbin. A Postbin is a web service that allows you to
|
103
103
|
post data, which is then displayed through a browser. This allows you to quickly determine
|
104
|
-
what is actually being transmitted to Mailgun's API.
|
104
|
+
what is actually being transmitted to Mailgun's API.
|
105
105
|
|
106
|
-
**Step 1 - Create a new Postbin.**
|
107
|
-
Go to http://bin.mailgun.net. The Postbin will generate a special URL. Save that URL.
|
106
|
+
**Step 1 - Create a new Postbin.**
|
107
|
+
Go to http://bin.mailgun.net. The Postbin will generate a special URL. Save that URL.
|
108
108
|
|
109
|
-
**Step 2 - Instantiate the Mailgun client using Postbin.**
|
109
|
+
**Step 2 - Instantiate the Mailgun client using Postbin.**
|
110
110
|
|
111
111
|
*Tip: The bin id will be the URL part after bin.mailgun.net. It will be random generated letters and numbers. For example, the bin id in this URL, http://bin.mailgun.net/aecf68de, is "aecf68de".*
|
112
112
|
|
@@ -115,36 +115,36 @@ Go to http://bin.mailgun.net. The Postbin will generate a special URL. Save that
|
|
115
115
|
mg_client = Mailgun::Client.new("your-api-key", "bin.mailgun.net", "aecf68de", ssl = false)
|
116
116
|
|
117
117
|
# Define your message parameters
|
118
|
-
message_params = {:from => 'bob@sending_domain.com',
|
119
|
-
:to => 'sally@example.com',
|
120
|
-
:subject => 'The Ruby SDK is awesome!',
|
118
|
+
message_params = {:from => 'bob@sending_domain.com',
|
119
|
+
:to => 'sally@example.com',
|
120
|
+
:subject => 'The Ruby SDK is awesome!',
|
121
121
|
:text => 'It is really easy to send a message!'}
|
122
122
|
|
123
123
|
# Send your message through the client
|
124
124
|
mg_client.send_message("sending_domain.com", message_params)
|
125
125
|
```
|
126
126
|
|
127
|
-
For usage examples on each API endpoint, head over to our official documentation
|
127
|
+
For usage examples on each API endpoint, head over to our official documentation
|
128
128
|
pages. Or the [Snippets](Snippets.md) file.
|
129
129
|
|
130
|
-
This SDK includes a [Message Builder](Messages.md),
|
130
|
+
This SDK includes a [Message Builder](Messages.md),
|
131
131
|
[Batch Message](Messages.md) and [Opt-In Handler](OptInHandler.md) component.
|
132
132
|
|
133
|
-
Message Builder allows you to quickly create the array of parameters, required
|
133
|
+
Message Builder allows you to quickly create the array of parameters, required
|
134
134
|
to send a message, by calling a methods for each parameter.
|
135
|
-
Batch Message is an extension of Message Builder, and allows you to easily send
|
136
|
-
a batch message job within a few seconds. The complexity of
|
137
|
-
batch messaging is eliminated!
|
135
|
+
Batch Message is an extension of Message Builder, and allows you to easily send
|
136
|
+
a batch message job within a few seconds. The complexity of
|
137
|
+
batch messaging is eliminated!
|
138
138
|
|
139
139
|
Support and Feedback
|
140
140
|
--------------------
|
141
141
|
|
142
|
-
Be sure to visit the Mailgun official
|
143
|
-
[documentation website](http://documentation.mailgun.com/) for additional
|
144
|
-
information about our API.
|
142
|
+
Be sure to visit the Mailgun official
|
143
|
+
[documentation website](http://documentation.mailgun.com/) for additional
|
144
|
+
information about our API.
|
145
145
|
|
146
|
-
If you find a bug, please submit the issue in Github directly.
|
146
|
+
If you find a bug, please submit the issue in Github directly.
|
147
147
|
[Mailgun-Ruby Issues](https://github.com/mailgun/mailgun-ruby/issues)
|
148
148
|
|
149
|
-
As always, if you need additional assistance, drop us a note at
|
150
|
-
[support@mailgun.com](mailto:support@mailgun.com).
|
149
|
+
As always, if you need additional assistance, drop us a note at
|
150
|
+
[support@mailgun.com](mailto:support@mailgun.com).
|
data/lib/mailgun.rb
CHANGED
@@ -11,9 +11,9 @@ require "mailgun/exceptions/exceptions"
|
|
11
11
|
|
12
12
|
module Mailgun
|
13
13
|
|
14
|
-
# A Mailgun::Client object is used to communicate with the Mailgun API. It is a
|
15
|
-
# wrapper around RestClient so you don't have to worry about the HTTP aspect
|
16
|
-
# of communicating with our API.
|
14
|
+
# A Mailgun::Client object is used to communicate with the Mailgun API. It is a
|
15
|
+
# wrapper around RestClient so you don't have to worry about the HTTP aspect
|
16
|
+
# of communicating with our API.
|
17
17
|
#
|
18
18
|
# See the Github documentation for full examples.
|
19
19
|
|
@@ -34,13 +34,13 @@ module Mailgun
|
|
34
34
|
# Simple Message Sending
|
35
35
|
#
|
36
36
|
# @param [String] working_domain This is the domain you wish to send from.
|
37
|
-
# @param [Hash] data This should be a standard Hash
|
37
|
+
# @param [Hash] data This should be a standard Hash
|
38
38
|
# containing required parameters for the requested resource.
|
39
39
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
40
40
|
|
41
41
|
def send_message(working_domain, data)
|
42
42
|
case data
|
43
|
-
when Hash
|
43
|
+
when Hash
|
44
44
|
if data.has_key?(:message)
|
45
45
|
if data[:message].is_a?(String)
|
46
46
|
data[:message] = convert_string_to_file(data[:message])
|
@@ -60,7 +60,7 @@ module Mailgun
|
|
60
60
|
#
|
61
61
|
# @param [String] resource_path This is the API resource you wish to interact
|
62
62
|
# with. Be sure to include your domain, where necessary.
|
63
|
-
# @param [Hash] data This should be a standard Hash
|
63
|
+
# @param [Hash] data This should be a standard Hash
|
64
64
|
# containing required parameters for the requested resource.
|
65
65
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
66
66
|
|
@@ -77,16 +77,16 @@ module Mailgun
|
|
77
77
|
#
|
78
78
|
# @param [String] resource_path This is the API resource you wish to interact
|
79
79
|
# with. Be sure to include your domain, where necessary.
|
80
|
-
# @param [Hash] query_string This should be a standard Hash
|
80
|
+
# @param [Hash] query_string This should be a standard Hash
|
81
81
|
# containing required parameters for the requested resource.
|
82
82
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
83
83
|
|
84
|
-
def get(resource_path, params=nil)
|
84
|
+
def get(resource_path, params=nil, accept="*/*")
|
85
85
|
begin
|
86
86
|
if params
|
87
|
-
response =
|
87
|
+
response = http_client[resource_path].get(:params => params, :accept => accept)
|
88
88
|
else
|
89
|
-
response = @http_client[resource_path].get()
|
89
|
+
response = @http_client[resource_path].get(:accept => accept)
|
90
90
|
end
|
91
91
|
Response.new(response)
|
92
92
|
rescue Exception => e
|
@@ -98,7 +98,7 @@ module Mailgun
|
|
98
98
|
#
|
99
99
|
# @param [String] resource_path This is the API resource you wish to interact
|
100
100
|
# with. Be sure to include your domain, where necessary.
|
101
|
-
# @param [Hash] data This should be a standard Hash
|
101
|
+
# @param [Hash] data This should be a standard Hash
|
102
102
|
# containing required parameters for the requested resource.
|
103
103
|
# @return [Mailgun::Response] A Mailgun::Response object.
|
104
104
|
|
@@ -139,7 +139,7 @@ module Mailgun
|
|
139
139
|
file
|
140
140
|
end
|
141
141
|
|
142
|
-
# Generates the endpoint URL to for the API. Allows overriding
|
142
|
+
# Generates the endpoint URL to for the API. Allows overriding
|
143
143
|
# API endpoint, API versions, and toggling SSL.
|
144
144
|
#
|
145
145
|
# @param [String] api_host URL endpoint the library will hit
|
@@ -160,7 +160,7 @@ module Mailgun
|
|
160
160
|
# A Mailgun::Response object is instantiated for each response generated
|
161
161
|
# by the Client request. The Response object supports deserialization of
|
162
162
|
# the JSON result. Or, if you prefer JSON or YAML formatting, call the
|
163
|
-
# method for conversion.
|
163
|
+
# method for conversion.
|
164
164
|
#
|
165
165
|
# See the Github documentation for full examples.
|
166
166
|
|
@@ -223,5 +223,5 @@ module Mailgun
|
|
223
223
|
end
|
224
224
|
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
end
|
@@ -10,16 +10,16 @@ module Mailgun
|
|
10
10
|
# this code makes it dead simple to send millions of messages in batches of
|
11
11
|
# 1,000 recipients per HTTP call.
|
12
12
|
#
|
13
|
-
# For the curious, the class simply keeps track of recipient data (count,
|
13
|
+
# For the curious, the class simply keeps track of recipient data (count,
|
14
14
|
# user variables), and fires the API payload on the 1,000th addition of a recipient.
|
15
15
|
#
|
16
16
|
# The best way to use this class is:
|
17
|
-
# 1. Build your message using the Message Builder methods.
|
18
|
-
# 2. Query your source and create an iterable list.
|
19
|
-
# 3. Iterate through your source data, and add your recipients using the
|
20
|
-
# add_recipient() method.
|
21
|
-
# 4. Call finalize() to flush any remaining recipients and obtain/store
|
22
|
-
# the message_ids for tracking purposes.
|
17
|
+
# 1. Build your message using the Message Builder methods.
|
18
|
+
# 2. Query your source and create an iterable list.
|
19
|
+
# 3. Iterate through your source data, and add your recipients using the
|
20
|
+
# add_recipient() method.
|
21
|
+
# 4. Call finalize() to flush any remaining recipients and obtain/store
|
22
|
+
# the message_ids for tracking purposes.
|
23
23
|
#
|
24
24
|
# See the Github documentation for full examples.
|
25
25
|
|
@@ -48,7 +48,7 @@ module Mailgun
|
|
48
48
|
end
|
49
49
|
|
50
50
|
compiled_address = parse_address(address, variables)
|
51
|
-
|
51
|
+
complex_setter(recipient_type, compiled_address)
|
52
52
|
if recipient_type != :from
|
53
53
|
store_recipient_variables(recipient_type, address, variables)
|
54
54
|
end
|
@@ -68,7 +68,7 @@ module Mailgun
|
|
68
68
|
end
|
69
69
|
@message_ids
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
private
|
73
73
|
|
74
74
|
# This method determines if it's necessary to send another batch.
|
@@ -88,21 +88,21 @@ module Mailgun
|
|
88
88
|
end
|
89
89
|
|
90
90
|
# This method initiates a batch send to the API. It formats the recipient
|
91
|
-
# variables, posts to the API, gathers the message IDs, then flushes that data
|
91
|
+
# variables, posts to the API, gathers the message IDs, then flushes that data
|
92
92
|
# to prepare for the next batch. This method implements the Mailgun Client, thus,
|
93
|
-
# an exception will be thrown if a communication error occurs.
|
93
|
+
# an exception will be thrown if a communication error occurs.
|
94
94
|
#
|
95
95
|
# @return [Boolean]
|
96
96
|
|
97
97
|
def send_message(message)
|
98
|
-
|
98
|
+
simple_setter("recipient-variables", JSON.generate(@recipient_variables))
|
99
99
|
response = @client.send_message(@domain, @message).to_h!
|
100
100
|
message_id = response['id'].gsub(/\>|\</, '')
|
101
101
|
@message_ids[message_id] = count_recipients()
|
102
102
|
reset_message()
|
103
103
|
end
|
104
104
|
|
105
|
-
# This method stores recipient variables for each recipient added, if
|
105
|
+
# This method stores recipient variables for each recipient added, if
|
106
106
|
# variables exist.
|
107
107
|
|
108
108
|
def store_recipient_variables(recipient_type, address, variables)
|
@@ -112,7 +112,7 @@ module Mailgun
|
|
112
112
|
@recipient_variables[address] = variables
|
113
113
|
end
|
114
114
|
|
115
|
-
# This method stores recipient variables for each recipient added, if
|
115
|
+
# This method stores recipient variables for each recipient added, if
|
116
116
|
# variables exist.
|
117
117
|
|
118
118
|
def count_recipients()
|
@@ -121,8 +121,8 @@ module Mailgun
|
|
121
121
|
count
|
122
122
|
end
|
123
123
|
|
124
|
-
# This method resets the message object to prepare for the next batch
|
125
|
-
# of recipients.
|
124
|
+
# This method resets the message object to prepare for the next batch
|
125
|
+
# of recipients.
|
126
126
|
|
127
127
|
def reset_message()
|
128
128
|
@message.delete("recipient-variables")
|
@@ -135,5 +135,5 @@ module Mailgun
|
|
135
135
|
end
|
136
136
|
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'multimap'
|
2
1
|
require 'time'
|
3
2
|
require 'json'
|
4
3
|
|
@@ -15,7 +14,7 @@ module Mailgun
|
|
15
14
|
attr_reader :message, :counters
|
16
15
|
|
17
16
|
def initialize()
|
18
|
-
@message =
|
17
|
+
@message = Hash.new{|hash, key| hash[key] = []}
|
19
18
|
@counters = {:recipients =>
|
20
19
|
{:to => 0,
|
21
20
|
:cc => 0,
|
@@ -40,7 +39,7 @@ module Mailgun
|
|
40
39
|
end
|
41
40
|
|
42
41
|
compiled_address = parse_address(address, variables)
|
43
|
-
|
42
|
+
complex_setter(recipient_type, compiled_address)
|
44
43
|
|
45
44
|
if @counters[:recipients].has_key?(recipient_type)
|
46
45
|
@counters[:recipients][recipient_type] += 1
|
@@ -100,7 +99,7 @@ module Mailgun
|
|
100
99
|
if !filename.nil?
|
101
100
|
attachment.instance_eval "def original_filename; '#{filename}'; end"
|
102
101
|
end
|
103
|
-
|
102
|
+
complex_setter(:attachment, attachment)
|
104
103
|
end
|
105
104
|
|
106
105
|
# Adds an inline image to the mesage object.
|
@@ -119,7 +118,7 @@ module Mailgun
|
|
119
118
|
if !filename.nil?
|
120
119
|
inline_image.instance_eval "def original_filename; '#{filename}'; end"
|
121
120
|
end
|
122
|
-
|
121
|
+
complex_setter(:inline, inline_image)
|
123
122
|
end
|
124
123
|
|
125
124
|
# Send a message in test mode. (The message won't really be sent to the recipient)
|
@@ -149,7 +148,7 @@ module Mailgun
|
|
149
148
|
if (@counters[:attributes][:campaign_id] == 3)
|
150
149
|
raise ParameterError.new("Too many campaigns added to message.", campaign_id)
|
151
150
|
end
|
152
|
-
|
151
|
+
complex_setter("o:campaign", campaign_id)
|
153
152
|
@counters[:attributes][:campaign_id] += 1
|
154
153
|
end
|
155
154
|
|
@@ -162,7 +161,7 @@ module Mailgun
|
|
162
161
|
if (@counters[:attributes][:tag] == 3)
|
163
162
|
raise ParameterError.new("Too many tags added to message.", tag)
|
164
163
|
end
|
165
|
-
|
164
|
+
complex_setter("o:tag", tag)
|
166
165
|
@counters[:attributes][:tag] += 1
|
167
166
|
end
|
168
167
|
|
@@ -228,7 +227,7 @@ module Mailgun
|
|
228
227
|
# @return [void]
|
229
228
|
|
230
229
|
def add_custom_parameter(name, data)
|
231
|
-
|
230
|
+
complex_setter(name, data)
|
232
231
|
end
|
233
232
|
|
234
233
|
private
|
@@ -242,17 +241,24 @@ module Mailgun
|
|
242
241
|
|
243
242
|
def simple_setter(parameter, value)
|
244
243
|
if value.nil?
|
245
|
-
|
246
|
-
@message.replace({parameter => ''})
|
247
|
-
else
|
248
|
-
@message[parameter] = ''
|
249
|
-
end
|
244
|
+
@message[parameter] = ['']
|
250
245
|
else
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
246
|
+
@message[parameter] = [value]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# Sets values within the multidict, however, allows
|
251
|
+
# duplicate values for keys.
|
252
|
+
#
|
253
|
+
# @param [String] parameter The message object parameter name.
|
254
|
+
# @param [String] value The value of the parameter.
|
255
|
+
# @return [void]
|
256
|
+
|
257
|
+
def complex_setter(parameter, value)
|
258
|
+
if value.nil?
|
259
|
+
@message[parameter] << ''
|
260
|
+
else
|
261
|
+
@message[parameter] << value
|
256
262
|
end
|
257
263
|
end
|
258
264
|
|
@@ -268,7 +274,7 @@ module Mailgun
|
|
268
274
|
value.downcase!
|
269
275
|
if ['true', 'yes', 'yep'].include? value
|
270
276
|
return "yes"
|
271
|
-
elsif ['false', 'no', 'nope'].include? value
|
277
|
+
elsif ['false', 'no', 'nope'].include? value
|
272
278
|
return "no"
|
273
279
|
else
|
274
280
|
return value
|
@@ -317,5 +323,5 @@ module Mailgun
|
|
317
323
|
end
|
318
324
|
|
319
325
|
end
|
320
|
-
|
326
|
+
|
321
327
|
end
|
data/lib/mailgun/version.rb
CHANGED
data/mailgun.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.license = 'Apache'
|
13
13
|
|
14
14
|
spec.summary = "Mailgun's Official Ruby SDK"
|
15
|
-
spec.description = "
|
15
|
+
spec.description = "Mailgun's Official Ruby SDK for interacting with the Mailgun API."
|
16
16
|
|
17
17
|
spec.authors = ["Mailgun", "Travis Swientek"]
|
18
18
|
spec.email = "support@mailgunhq.com"
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.post_install_message = %q{
|
26
26
|
---------------------------------------------------------------
|
27
|
-
Congrats, you've successfully installed the Mailgun SDK!
|
27
|
+
Congrats, you've successfully installed the Mailgun SDK!
|
28
28
|
Check out our documentation at http://documentation.mailgun.com
|
29
29
|
|
30
30
|
Contact us at support@mailgunhq.com with any questions.
|
@@ -37,6 +37,5 @@ Gem::Specification.new do |spec|
|
|
37
37
|
|
38
38
|
spec.add_dependency "rest-client", "~> 1.6"
|
39
39
|
spec.add_dependency "json", "~> 1.8"
|
40
|
-
|
41
|
-
|
40
|
+
|
42
41
|
end
|
data/spec/unit/mailgun_spec.rb
CHANGED
@@ -24,12 +24,10 @@ describe 'The method send_message()' do
|
|
24
24
|
|
25
25
|
it 'accepts only specific data types' do
|
26
26
|
@mb_obj = Mailgun::MessageBuilder.new()
|
27
|
-
@mm_obj = Multimap.new()
|
28
27
|
@mh_obj = {}
|
29
28
|
|
30
29
|
expect {@mg_obj.send_message("test.com", "incorrect data")}.to raise_error
|
31
30
|
expect {@mg_obj.send_message("test.com", @mb_obj)}.not_to raise_error
|
32
|
-
expect {@mg_obj.send_message("test.com", @mm_obj)}.not_to raise_error
|
33
31
|
expect {@mg_obj.send_message("test.com", @mh_obj)}.not_to raise_error
|
34
32
|
end
|
35
33
|
|
@@ -27,8 +27,8 @@ describe 'The instantiation of Batch Message' do
|
|
27
27
|
@mb_obj = Mailgun::BatchMessage.new(@mb_client, "example.com")
|
28
28
|
end
|
29
29
|
|
30
|
-
it 'contains Message, which should be of type
|
31
|
-
@mb_obj.message.should be_a(
|
30
|
+
it 'contains Message, which should be of type Hash and empty' do
|
31
|
+
@mb_obj.message.should be_a(Hash)
|
32
32
|
@mb_obj.message.length.should eq(0)
|
33
33
|
end
|
34
34
|
|
@@ -14,11 +14,6 @@ describe 'The instantiation of MessageBuilder' do
|
|
14
14
|
@mb_obj = Mailgun::MessageBuilder.new()
|
15
15
|
end
|
16
16
|
|
17
|
-
it 'contains Message, which should be of type Multimap and empty' do
|
18
|
-
@mb_obj.message.should be_a(Multimap)
|
19
|
-
@mb_obj.message.length.should eq(0)
|
20
|
-
end
|
21
|
-
|
22
17
|
it 'contains counters, which should be of type hash and contain several important counters' do
|
23
18
|
@mb_obj.counters.should be_a(Hash)
|
24
19
|
@mb_obj.counters.should include(:recipients)
|
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.0.
|
4
|
+
version: 1.0.1
|
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: 2014-
|
12
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,22 +81,7 @@ dependencies:
|
|
81
81
|
- - ~>
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '1.8'
|
84
|
-
|
85
|
-
name: multimap
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '1.1'
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - ~>
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '1.1'
|
98
|
-
description: This Gem allows you to interact with Mailgun's API. A few utilities are
|
99
|
-
included!
|
84
|
+
description: Mailgun's Official Ruby SDK for interacting with the Mailgun API.
|
100
85
|
email: support@mailgunhq.com
|
101
86
|
executables: []
|
102
87
|
extensions: []
|
@@ -134,7 +119,7 @@ licenses:
|
|
134
119
|
- Apache
|
135
120
|
metadata: {}
|
136
121
|
post_install_message: "\n ---------------------------------------------------------------\n
|
137
|
-
\ Congrats, you've successfully installed the Mailgun SDK
|
122
|
+
\ Congrats, you've successfully installed the Mailgun SDK!\n Check out our
|
138
123
|
documentation at http://documentation.mailgun.com\n\n Contact us at support@mailgunhq.com
|
139
124
|
with any questions.\n ----------------------------------------------------------------\n
|
140
125
|
\ "
|
@@ -153,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
138
|
version: '0'
|
154
139
|
requirements: []
|
155
140
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.0.3
|
157
142
|
signing_key:
|
158
143
|
specification_version: 4
|
159
144
|
summary: Mailgun's Official Ruby SDK
|