mailgun-ruby 1.1.3 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0e2728bd22128bd8d8209b0b5b1f6c941501f5a
4
- data.tar.gz: b8f2c9a4cccdccd328142fae44a14be8154cb9d6
3
+ metadata.gz: f7a3d2306cc5f23a9f5b198bbcef7767be64f1bc
4
+ data.tar.gz: aa73b428690d284c293a89e848359a9f7617476a
5
5
  SHA512:
6
- metadata.gz: 779520a0342a79b09dbd433f516d969234636b7585d14ab3f7f827a08071611b55b2fc1b81c7aa6215a7ac6fb08535f95a792109a309557e5e612c6be5d02dc1
7
- data.tar.gz: 0ad45cd374509486f177649b7d6dd3f3e3df7b14b3c40643657699670f6acb6e0b710200bc1df19a1bc7710795fe654dd6efcd1590e05650de00460898aca0e0
6
+ metadata.gz: 56e7617f35b16862fee5b06a428d45925447edb12f1d721fdc87e8c382b8db140f40d1de4a5c63de59c96904e1f4322c80097aac7dc3cab838dc2d945922ab42
7
+ data.tar.gz: ce165c6784831eed9240ef7b51b3ba855bea5066a5b294cbf3450eef321ddc33dd3d879d477b7c23cb8f80f4ac02f9125e26e3432f2273f69ec68ab9483aa928
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: QTNP+6720w38b8krtvXM25WDEOUxw9BlUwdXgWLrU0MGAOSvVFgnWTJs+7QvGWODjhrIqAfAm11zc+yEpzgD9P8np9cteWv5K7rMxsUMcb14kaGIA+MKO+RRJXlru4teBNX5jtp2GJiNS2mn7urzn5YhE9x9P7pMjcF+j5usoF0=
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.2'
22
+ gem 'mailgun-ruby', '~>1.1.4'
23
23
  ```
24
24
 
25
25
  Usage
@@ -67,6 +67,15 @@ end
67
67
  ```
68
68
  Or have the initializer read your environment setting if you perfer.
69
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
+ ```
70
79
 
71
80
  Response
72
81
  --------
@@ -138,15 +147,15 @@ mg_client.send_message("sending_domain.com", message_params)
138
147
  ```
139
148
 
140
149
  For usage examples on each API endpoint, head over to our official documentation
141
- pages. Or the [Snippets](Snippets.md) file.
150
+ pages. Or the [Snippets](docs/Snippets.md) file.
142
151
 
143
152
  This SDK includes the following components:
144
- - [Message Builder](MessageBuilder.md)
145
- - [Batch Message](MessageBuilder.md)
146
- - [Opt-In Handler](OptInHandler.md)
147
- - [Domains](Domains.md)
148
- - [Webhooks](Webhooks.md)
149
- - [Events](Events.md)
153
+ - [Message Builder](docs/MessageBuilder.md)
154
+ - [Batch Message](docs/MessageBuilder.md)
155
+ - [Opt-In Handler](docs/OptInHandler.md)
156
+ - [Domains](docs/Domains.md)
157
+ - [Webhooks](docs/Webhooks.md)
158
+ - [Events](docs/Events.md)
150
159
 
151
160
  Message Builder allows you to quickly create the array of parameters, required
152
161
  to send a message, by calling a methods for each parameter.
File without changes
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
- # Campaign and other headers.
46
+
47
+ # Campaigns and headers.
41
48
  mb_obj.add_campaign_id("My-Awesome-Campaign");
42
- mb_obj.add_custom_parameter("h:Customer-Id", "12345");
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("/path/to/file/receipt_123491820.pdf", "Receipt.pdf");
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.delivery_at("tomorrow 8:00AM PST");
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
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.add_custom_parameter("h:Customer-Id", "12345")
54
- mb_obj.add_attachment("@/tron.jpg")
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
 
File without changes
@@ -75,6 +75,26 @@ mb_obj.set_text_body "This is the text body."
75
75
  mg_client.send_message "sending_domain.com", mb_obj
76
76
  ```
77
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
+
78
98
  **Send batches of 1000 messages per post:**
79
99
 
80
100
  ```ruby
File without changes
data/lib/mailgun-ruby.rb CHANGED
@@ -1 +1,2 @@
1
- require 'mailgun'
1
+ require 'mailgun'
2
+ require 'railgun' if defined?(Rails)
@@ -62,6 +62,11 @@ module Mailgun
62
62
 
63
63
  case data
64
64
  when Hash
65
+ # Remove nil values from the data hash
66
+ # Submitting nils to the API will likely cause an error.
67
+ # See also: https://github.com/mailgun/mailgun-ruby/issues/32
68
+ data = data.select { |k, v| v != nil }
69
+
65
70
  if data.key?(:message)
66
71
  if data[:message].is_a?(String)
67
72
  data[:message] = convert_string_to_file(data[:message])
@@ -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
- complex_setter(recipient_type, compiled_address)
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
- simple_setter rkey, JSON.generate(@recipient_variables)
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!
@@ -40,7 +40,7 @@ module Mailgun
40
40
  end
41
41
 
42
42
  compiled_address = parse_address(address, variables)
43
- complex_setter(recipient_type, compiled_address)
43
+ set_multi_complex(recipient_type, compiled_address)
44
44
 
45
45
  @counters[:recipients][recipient_type] += 1 if @counters[:recipients].key?(recipient_type)
46
46
  end
@@ -63,14 +63,14 @@ module Mailgun
63
63
  # Set the message's Reply-To address.
64
64
  #
65
65
  # Rationale: According to RFC, only one Reply-To address is allowed, so it
66
- # is *okay* to bypass the simple_setter and set reply-to directly.
66
+ # is *okay* to bypass the set_multi_simple and set reply-to directly.
67
67
  #
68
68
  # @param [String] address The email address to provide as Reply-To.
69
69
  # @param [Hash] variables A hash of variables associated with the recipient.
70
70
  # @return [void]
71
71
  def reply_to(address, variables = nil)
72
72
  compiled_address = parse_address(address, variables)
73
- @message["h:reply-to"] = compiled_address
73
+ header("reply-to", compiled_address)
74
74
  end
75
75
 
76
76
  # Set a subject for the message object
@@ -78,7 +78,7 @@ module Mailgun
78
78
  # @param [String] subject The subject for the email.
79
79
  # @return [void]
80
80
  def subject(subj = nil)
81
- simple_setter(:subject, subj)
81
+ set_multi_simple(:subject, subj)
82
82
  end
83
83
 
84
84
  # Deprecated: Please use "subject" instead.
@@ -92,7 +92,7 @@ module Mailgun
92
92
  # @param [String] text_body The text body for the email.
93
93
  # @return [void]
94
94
  def body_text(text_body = nil)
95
- simple_setter(:text, text_body)
95
+ set_multi_simple(:text, text_body)
96
96
  end
97
97
 
98
98
  # Deprecated: Please use "body_text" instead.
@@ -106,7 +106,7 @@ module Mailgun
106
106
  # @param [String] html_body The html body for the email.
107
107
  # @return [void]
108
108
  def body_html(html_body = nil)
109
- simple_setter(:html, html_body)
109
+ set_multi_simple(:html, html_body)
110
110
  end
111
111
 
112
112
  # Deprecated: Please use "body_html" instead.
@@ -138,7 +138,7 @@ module Mailgun
138
138
  # @param [Boolean] mode The boolean or string value (will fix itself)
139
139
  # @return [void]
140
140
  def test_mode(mode)
141
- simple_setter('o:testmode', bool_lookup(mode))
141
+ set_multi_simple('o:testmode', bool_lookup(mode))
142
142
  end
143
143
 
144
144
  # Deprecated: 'set_test_mode' is depreciated. Please use 'test_mode' instead.
@@ -152,7 +152,7 @@ module Mailgun
152
152
  # @param [Boolean] mode The boolean or string value(will fix itself)
153
153
  # @return [void]
154
154
  def dkim(mode)
155
- simple_setter('o:dkim', bool_lookup(mode))
155
+ set_multi_simple('o:dkim', bool_lookup(mode))
156
156
  end
157
157
 
158
158
  # Deprecated: 'set_dkim' is deprecated. Please use 'dkim' instead.
@@ -168,7 +168,7 @@ module Mailgun
168
168
  def add_campaign_id(campaign_id)
169
169
  fail(Mailgun::ParameterError, 'Too many campaigns added to message.', campaign_id) if @counters[:attributes][:campaign_id] >= Mailgun::Chains::MAX_CAMPAIGN_IDS
170
170
 
171
- complex_setter('o:campaign', campaign_id)
171
+ set_multi_complex('o:campaign', campaign_id)
172
172
  @counters[:attributes][:campaign_id] += 1
173
173
  end
174
174
 
@@ -180,7 +180,7 @@ module Mailgun
180
180
  if @counters[:attributes][:tag] >= Mailgun::Chains::MAX_TAGS
181
181
  fail Mailgun::ParameterError, 'Too many tags added to message.', tag
182
182
  end
183
- complex_setter('o:tag', tag)
183
+ set_multi_complex('o:tag', tag)
184
184
  @counters[:attributes][:tag] += 1
185
185
  end
186
186
 
@@ -189,7 +189,7 @@ module Mailgun
189
189
  # @param [Boolean] tracking Boolean true or false.
190
190
  # @return [void]
191
191
  def track_opens(mode)
192
- simple_setter('o:tracking-opens', bool_lookup(mode))
192
+ set_multi_simple('o:tracking-opens', bool_lookup(mode))
193
193
  end
194
194
 
195
195
  # Deprecated: 'set_open_tracking' is deprecated. Please use 'track_opens' instead.
@@ -203,7 +203,7 @@ module Mailgun
203
203
  # @param [String] mode True, False, or HTML (for HTML only tracking)
204
204
  # @return [void]
205
205
  def track_clicks(mode)
206
- simple_setter('o:tracking-clicks', bool_lookup(mode))
206
+ set_multi_simple('o:tracking-clicks', bool_lookup(mode))
207
207
  end
208
208
 
209
209
  # Depreciated: 'set_click_tracking. is deprecated. Please use 'track_clicks' instead.
@@ -221,7 +221,7 @@ module Mailgun
221
221
  # @return [void]
222
222
  def deliver_at(timestamp)
223
223
  time_str = DateTime.parse(timestamp)
224
- simple_setter('o:deliverytime', time_str.rfc2822)
224
+ set_multi_simple('o:deliverytime', time_str.rfc2822)
225
225
  end
226
226
 
227
227
  # Deprecated: 'set_delivery_time' is deprecated. Please use 'deliver_at' instead.
@@ -238,8 +238,12 @@ module Mailgun
238
238
  # @return [void]
239
239
  def header(name, data)
240
240
  fail(Mailgun::ParameterError, 'Header name for message must be specified') if name.to_s.empty?
241
- jsondata = make_json data
242
- simple_setter("v:#{name}", jsondata)
241
+ begin
242
+ jsondata = make_json data
243
+ set_single("h:#{name}", jsondata)
244
+ rescue Mailgun::ParameterError
245
+ set_single("h:#{name}", data)
246
+ end
243
247
  end
244
248
 
245
249
  # Deprecated: 'set_custom_data' is deprecated. Please use 'header' instead.
@@ -248,6 +252,19 @@ module Mailgun
248
252
  header name, data
249
253
  end
250
254
 
255
+ # Attaches custom JSON data to the message. See the following doc page for more info.
256
+ # https://documentation.mailgun.com/user_manual.html#attaching-data-to-messages
257
+ #
258
+ # @param [String] name A name for the custom variable block.
259
+ # @param [String|Hash] data Either a string or a hash. If it is not valid JSON or
260
+ # can not be converted to JSON, ParameterError will be raised.
261
+ # @return [void]
262
+ def variable(name, data)
263
+ fail(Mailgun::ParameterError, 'Variable name must be specified') if name.to_s.empty?
264
+ jsondata = make_json data
265
+ set_single("v:#{name}", jsondata)
266
+ end
267
+
251
268
  # Add custom parameter to the message. A custom parameter is any parameter that
252
269
  # is not yet supported by the SDK, but available at the API. Note: No validation
253
270
  # is performed. Don't forget to prefix the parameter with o, h, or v.
@@ -256,7 +273,7 @@ module Mailgun
256
273
  # @param [string] data A string of data for the parameter.
257
274
  # @return [void]
258
275
  def add_custom_parameter(name, data)
259
- complex_setter(name, data)
276
+ set_multi_complex(name, data)
260
277
  end
261
278
 
262
279
  # Set the Message-Id header to a custom value. Don't forget to enclose the
@@ -269,7 +286,7 @@ module Mailgun
269
286
  def message_id(data = nil)
270
287
  key = 'h:Message-Id'
271
288
  return @message.delete(key) if data.to_s.empty?
272
- @message[key] = data
289
+ set_single(key, data)
273
290
  end
274
291
 
275
292
  # Deprecated: 'set_message_id' is deprecated. Use 'message_id' instead.
@@ -280,13 +297,23 @@ module Mailgun
280
297
 
281
298
  private
282
299
 
300
+ # Sets a single value in the message hash where "multidict" features are not needed.
301
+ # Does *not* permit duplicate params.
302
+ #
303
+ # @param [String] parameter The message object parameter name.
304
+ # @param [String] value The value of the parameter.
305
+ # @return [void]
306
+ def set_single(parameter, value)
307
+ @message[parameter] = value ? value : ''
308
+ end
309
+
283
310
  # Sets values within the multidict, however, prevents
284
311
  # duplicate values for keys.
285
312
  #
286
313
  # @param [String] parameter The message object parameter name.
287
314
  # @param [String] value The value of the parameter.
288
315
  # @return [void]
289
- def simple_setter(parameter, value)
316
+ def set_multi_simple(parameter, value)
290
317
  @message[parameter] = value ? [value] : ['']
291
318
  end
292
319
 
@@ -296,7 +323,7 @@ module Mailgun
296
323
  # @param [String] parameter The message object parameter name.
297
324
  # @param [String] value The value of the parameter.
298
325
  # @return [void]
299
- def complex_setter(parameter, value)
326
+ def set_multi_complex(parameter, value)
300
327
  @message[parameter] << (value || '')
301
328
  end
302
329
 
@@ -327,9 +354,9 @@ module Mailgun
327
354
  #
328
355
  # Returns a JSON object or raises ParameterError
329
356
  def make_json(obj)
330
- return JSON.parse(obj).to_s if obj.is_a?(String)
331
- return obj.to_s if obj.is_a?(Hash)
332
- return JSON.generate(obj).to_s
357
+ return JSON.parse(obj).to_json if obj.is_a?(String)
358
+ return obj.to_json if obj.is_a?(Hash)
359
+ return JSON.generate(obj).to_json
333
360
  rescue
334
361
  raise Mailgun::ParameterError, 'Provided data could not be made into JSON. Try a JSON string or Hash.', obj
335
362
  end
@@ -371,7 +398,7 @@ module Mailgun
371
398
  attachment.instance_variable_set :@original_filename, filename
372
399
  attachment.instance_eval 'def original_filename; @original_filename; end'
373
400
  end
374
- complex_setter(disposition, attachment)
401
+ set_multi_complex(disposition, attachment)
375
402
  end
376
403
  end
377
404
 
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.1.3'
3
+ VERSION = '1.1.4'
4
4
  end
data/lib/railgun.rb CHANGED
@@ -1,6 +1,4 @@
1
- require 'action_mailer'
2
- require 'active_support/rescuable'
3
-
1
+ require 'railgun/railtie'
4
2
  require 'railgun/attachment'
5
3
  require 'railgun/errors'
6
4
  require 'railgun/mailer'
@@ -158,5 +158,3 @@ module Railgun
158
158
  end
159
159
 
160
160
  end
161
-
162
- ActionMailer::Base.add_delivery_method :mailgun, Railgun::Mailer
@@ -0,0 +1,9 @@
1
+ require 'railgun/mailer'
2
+
3
+ module Railgun
4
+ class Railtie < ::Rails::Railtie
5
+ config.before_configuration do
6
+ ActionMailer::Base.add_delivery_method :mailgun, Railgun::Mailer
7
+ end
8
+ end
9
+ end
data/mailgun.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = Mailgun::VERSION
10
10
  spec.homepage = 'http://www.mailgun.com'
11
11
  spec.platform = Gem::Platform::RUBY
12
- spec.license = 'Apache'
12
+ spec.license = 'Apache-2.0'
13
13
 
14
14
  spec.summary = "Mailgun's Official Ruby SDK"
15
15
  spec.description = "Mailgun's Official Ruby SDK for interacting with the Mailgun API."
@@ -485,19 +485,31 @@ describe 'The method header' do
485
485
  it 'accepts valid JSON and appends as data to the message.' do
486
486
  @mb_obj.header('my-data', '{"key":"value"}')
487
487
 
488
- expect(@mb_obj.message["v:my-data"][0]).to be_kind_of(String)
489
- expect(@mb_obj.message["v:my-data"][0].to_s).to eq('{"key"=>"value"}')
488
+ expect(@mb_obj.message["h:my-data"]).to be_kind_of(String)
489
+ expect(@mb_obj.message["h:my-data"].to_s).to eq('{"key":"value"}')
490
+ end
491
+ end
492
+
493
+ describe 'The method variable' do
494
+ before(:each) do
495
+ @mb_obj = Mailgun::MessageBuilder.new
496
+ end
497
+ it 'accepts valid JSON and stores it as message[param].' do
498
+ @mb_obj.variable('my-data', '{"key":"value"}')
499
+
500
+ expect(@mb_obj.message["v:my-data"]).to be_kind_of(String)
501
+ expect(@mb_obj.message["v:my-data"].to_s).to eq('{"key":"value"}')
490
502
  end
491
503
  it 'accepts a hash and appends as data to the message.' do
492
504
  data = {'key' => 'value'}
493
- @mb_obj.header('my-data', data)
505
+ @mb_obj.variable('my-data', data)
494
506
 
495
- expect(@mb_obj.message["v:my-data"][0]).to be_kind_of(String)
496
- expect(@mb_obj.message["v:my-data"][0].to_s).to eq('{"key"=>"value"}')
507
+ expect(@mb_obj.message["v:my-data"]).to be_kind_of(String)
508
+ expect(@mb_obj.message["v:my-data"].to_s).to eq('{"key":"value"}')
497
509
  end
498
510
  it 'throws an exception on broken JSON.' do
499
511
  data = 'This is some crappy JSON.'
500
- expect {@mb_obj.header('my-data', data)}.to raise_error(Mailgun::ParameterError)
512
+ expect {@mb_obj.variable('my-data', data)}.to raise_error(Mailgun::ParameterError)
501
513
  end
502
514
  end
503
515
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailgun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-30 00:00:00.000000000 Z
12
+ date: 2017-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -134,17 +134,17 @@ files:
134
134
  - ".rubocop_todo.yml"
135
135
  - ".ruby-env.yml.example"
136
136
  - ".travis.yml"
137
- - Domains.md
138
- - Events.md
139
137
  - Gemfile
140
138
  - LICENSE
141
- - MessageBuilder.md
142
- - Messages.md
143
- - OptInHandler.md
144
139
  - README.md
145
140
  - Rakefile
146
- - Snippets.md
147
- - Webhooks.md
141
+ - docs/Domains.md
142
+ - docs/Events.md
143
+ - docs/MessageBuilder.md
144
+ - docs/Messages.md
145
+ - docs/OptInHandler.md
146
+ - docs/Snippets.md
147
+ - docs/Webhooks.md
148
148
  - lib/mailgun-ruby.rb
149
149
  - lib/mailgun.rb
150
150
  - lib/mailgun/address.rb
@@ -165,6 +165,7 @@ files:
165
165
  - lib/railgun/errors.rb
166
166
  - lib/railgun/mailer.rb
167
167
  - lib/railgun/message.rb
168
+ - lib/railgun/railtie.rb
168
169
  - mailgun.gemspec
169
170
  - spec/integration/bounces_spec.rb
170
171
  - spec/integration/campaign_spec.rb
@@ -209,7 +210,7 @@ files:
209
210
  - vcr_cassettes/webhooks.yml
210
211
  homepage: http://www.mailgun.com
211
212
  licenses:
212
- - Apache
213
+ - Apache-2.0
213
214
  metadata: {}
214
215
  post_install_message:
215
216
  rdoc_options: []