mailgun-ruby 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 03bb73706b0d179b3f48cfa58f68acc8b0d716e7
4
- data.tar.gz: 3fc860e152511f367033a5954ba95720a474fd01
2
+ SHA256:
3
+ metadata.gz: a161608ec972823219220afcff04f3f8ddf959190ab747a03983ebe108ccaba5
4
+ data.tar.gz: 21f81c2a51f0b4e2c18f7ad309cd884561cb60120787d3cbe7140962d5fc717a
5
5
  SHA512:
6
- metadata.gz: 0d1f7e536083087eb9c2423c8cb3cd54624b5d0a7fbfb96eb8740b06c2947c14d94542e6ef22439d0f0711d9627b5219e09b9ccab7408b454e20ad1531a07d56
7
- data.tar.gz: 9e03a0244f385c15497856fe9c421d3d330a38309798313c88f3139a86b6fc163cf6234654e15a1c1faceca40b70ad590ff5caf02c3cefc2d225a4eb3bc2b852
6
+ metadata.gz: d24993f138c611967f0cf77498fedb464858e93afddb7d6e7e1288ca5351aee6902bd7bb4c449a738f55a775f1fd1849aec91323145a068e64b0bca79ca6db1e
7
+ data.tar.gz: ea24ee662ee9c4dd91f5b73609cc4ae884c692a4876dfd96c30e4b1fdd18c213d37088db96936d3aba493e5eecf5fad66a73d1eb53fcee9831bfeeca4f6fefa0
@@ -31,7 +31,7 @@ hook.create 'my.perfect.domain', 'deliver', 'https://the.webhook.url/'
31
31
  hook.remove 'my.perfect.domain', 'deliver'
32
32
 
33
33
  # Remove all webhooks for a domain
34
- hook.remove 'my.perfect.domain'
34
+ hook.remove_all 'my.perfect.domain'
35
35
  ```
36
36
 
37
37
  More Documentation
@@ -379,8 +379,15 @@ module Mailgun
379
379
  def parse_address(address, vars)
380
380
  return address unless vars.is_a? Hash
381
381
  fail(Mailgun::ParameterError, 'Email address not specified') unless address.is_a? String
382
+ if vars['full_name'] != nil && (vars['first'] != nil || vars['last'] != nil)
383
+ fail(Mailgun::ParameterError, 'Must specify at most one of full_name or first/last. Vars passed: #{vars}')
384
+ end
382
385
 
383
- full_name = "#{vars['first']} #{vars['last']}".strip
386
+ if vars['full_name']
387
+ full_name = vars['full_name']
388
+ elsif vars['first'] || vars['last']
389
+ full_name = "#{vars['first']} #{vars['last']}".strip
390
+ end
384
391
 
385
392
  return "'#{full_name}' <#{address}>" if defined?(full_name)
386
393
  address
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.1.8'
3
+ VERSION = '1.1.9'
4
4
  end
@@ -46,7 +46,7 @@ module Mailgun
46
46
  # Returns a Boolean of whether the webhook was created
47
47
  def create(domain, action, url = '')
48
48
  res = @client.post("domains/#{domain}/webhooks", id: action, url: url)
49
- res.to_h['webhook']['url'] == url && res.to_h[message] == 'Webhook has been created'
49
+ res.to_h['webhook']['url'] == url && res.to_h['message'] == 'Webhook has been created'
50
50
  end
51
51
  alias_method :add, :create
52
52
  alias_method :add_webhook, :create
@@ -23,7 +23,7 @@ module Railgun
23
23
  raise Railgun::ConfigurationError.new("Config requires `#{k}` key", @config) unless @config.has_key?(k)
24
24
  end
25
25
 
26
- @mg_client = Mailgun::Client.new(config[:api_key])
26
+ @mg_client = Mailgun::Client.new(config[:api_key], config[:api_host] || 'api.mailgun.net', config[:api_version] || 'v3', config[:api_ssl].nil? ? true : config[:api_ssl])
27
27
  @domain = @config[:domain]
28
28
 
29
29
  # To avoid exception in mail gem v2.6
@@ -138,7 +138,7 @@ module Railgun
138
138
  # @return [String]
139
139
  def extract_body_html(mail)
140
140
  begin
141
- (mail.html_part || mail).body.decoded || nil
141
+ retrieve_html_part(mail).body.decoded || nil
142
142
  rescue
143
143
  nil
144
144
  end
@@ -152,10 +152,34 @@ module Railgun
152
152
  # @return [String]
153
153
  def extract_body_text(mail)
154
154
  begin
155
- (mail.text_part || mail).body.decoded || nil
155
+ retrieve_text_part(mail).body.decoded || nil
156
156
  rescue
157
157
  nil
158
158
  end
159
159
  end
160
160
 
161
+ # Returns the mail object from the Mail::Message object if text part exists,
162
+ # (decomposing multipart into individual format if necessary)
163
+ # otherwise nil.
164
+ #
165
+ # @param [Mail::Message] mail message to transform
166
+ #
167
+ # @return [Mail::Message] mail message with its content-type = text/plain
168
+ def retrieve_text_part(mail)
169
+ return mail.text_part if mail.multipart?
170
+ (mail.mime_type =~ /^text\/plain$/i) && mail
171
+ end
172
+
173
+ # Returns the mail object from the Mail::Message object if html part exists,
174
+ # (decomposing multipart into individual format if necessary)
175
+ # otherwise nil.
176
+ #
177
+ # @param [Mail::Message] mail message to transform
178
+ #
179
+ # @return [Mail::Message] mail message with its content-type = text/html
180
+ def retrieve_html_part(mail)
181
+ return mail.html_part if mail.multipart?
182
+ (mail.mime_type =~ /^text\/html$/i) && mail
183
+ end
184
+
161
185
  end
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'pry', '~> 0.9'
32
32
  spec.add_development_dependency 'vcr', '~> 3.0'
33
33
  spec.add_development_dependency 'simplecov', '~> 0.11'
34
-
34
+ spec.add_development_dependency "rails"
35
35
  spec.add_dependency 'rest-client', '~> 2.0'
36
36
 
37
37
  end
@@ -196,7 +196,7 @@ describe 'The method from' do
196
196
  expect(@mb_obj.message[:from]).to eq([the_from_address])
197
197
  end
198
198
 
199
- it 'sets the from address with metadata' do
199
+ it 'sets the from address with first/last metadata' do
200
200
  the_from_address = 'test@mailgun.com'
201
201
  the_first_name = 'Magilla'
202
202
  the_last_name = 'Gorilla'
@@ -204,6 +204,21 @@ describe 'The method from' do
204
204
 
205
205
  expect(@mb_obj.message[:from]).to eq(["'#{the_first_name} #{the_last_name}' <#{the_from_address}>"])
206
206
  end
207
+
208
+ it 'sets the from address with full name metadata' do
209
+ the_from_address = 'test@mailgun.com'
210
+ full_name = 'Magilla Gorilla'
211
+ @mb_obj.from(the_from_address, {'full_name' => full_name})
212
+
213
+ expect(@mb_obj.message[:from]).to eq(["'#{full_name}' <#{the_from_address}>"])
214
+ end
215
+
216
+ it 'fails when first/last and full_name are used' do
217
+ the_from_address = 'test@mailgun.com'
218
+ full_name = 'Magilla Gorilla'
219
+ first_name = 'Magilla'
220
+ expect{@mb_obj.from(the_from_address, {'full_name' => full_name, 'first' => first_name})}.to raise_error(Mailgun::ParameterError)
221
+ end
207
222
  end
208
223
 
209
224
  describe 'The method add_attachment' do
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'mailgun'
3
+ require 'railgun'
4
+
5
+ describe 'extract_body' do
6
+
7
+ let(:text_mail_option) {
8
+ {
9
+ from: 'bob@example.com',
10
+ to: 'sally@example.com',
11
+ subject: 'RAILGUN TEST SAMPLE',
12
+ body: text_content,
13
+ content_type: 'text/plain',
14
+ }
15
+ }
16
+ let(:text_content) { '[TEST] Hello, world.' }
17
+
18
+ let(:html_mail_option) {
19
+ {
20
+ from: 'bob@example.com',
21
+ to: 'sally@example.com',
22
+ subject: 'RAILGUN TEST SAMPLE',
23
+ body: html_content,
24
+ content_type: 'text/html',
25
+ }
26
+ }
27
+ let(:html_content) { '<h3> [TEST] </h3> <br/> Hello, world!' }
28
+
29
+ context 'with <Content-Type: text/plain>' do
30
+ let(:sample_mail) { Mail.new(text_mail_option) }
31
+
32
+ it 'should return body text' do
33
+ expect(Railgun.extract_body_text(sample_mail)).to eq(text_content)
34
+ end
35
+
36
+ it 'should not return body html' do
37
+ expect(Railgun.extract_body_html(sample_mail)).to be_nil
38
+ end
39
+ end
40
+
41
+ context 'with <Content-Type: text/html>' do
42
+ let(:sample_mail) { Mail.new(html_mail_option) }
43
+
44
+ it 'should not return body text' do
45
+ expect(Railgun.extract_body_text(sample_mail)).to be_nil
46
+ end
47
+
48
+ it 'should return body html' do
49
+ expect(Railgun.extract_body_html(sample_mail)).to eq(html_content)
50
+ end
51
+ end
52
+
53
+ context 'with <Content-Type: multipart/alternative>' do
54
+ let(:text_mail) { Mail.new(text_mail_option) }
55
+ let(:html_mail) { Mail.new(html_mail_option) }
56
+
57
+ before do
58
+ @sample_mail = Mail::Part.new(content_type: "multipart/alternative")
59
+ @sample_mail.add_part text_mail
60
+ @sample_mail.add_part html_mail
61
+ end
62
+
63
+ it 'should return body text' do
64
+ expect(Railgun.extract_body_text(@sample_mail)).to eq(text_content)
65
+ end
66
+
67
+ it 'should return body html' do
68
+ expect(Railgun.extract_body_html(@sample_mail)).to eq(html_content)
69
+ end
70
+ end
71
+ end
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.8
4
+ version: 1.1.9
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-09-27 00:00:00.000000000 Z
12
+ date: 2018-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0.11'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rails
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: rest-client
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +208,7 @@ files:
194
208
  - spec/unit/messages/sample_data/mailgun_icon.png
195
209
  - spec/unit/messages/sample_data/mime.txt
196
210
  - spec/unit/messages/sample_data/rackspace_logo.jpg
211
+ - spec/unit/railgun_spec.rb
197
212
  - vcr_cassettes/bounces.yml
198
213
  - vcr_cassettes/complaints.yml
199
214
  - vcr_cassettes/domains.todo.yml
@@ -230,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
245
  version: '0'
231
246
  requirements: []
232
247
  rubyforge_project:
233
- rubygems_version: 2.6.13
248
+ rubygems_version: 2.7.5
234
249
  signing_key:
235
250
  specification_version: 4
236
251
  summary: Mailgun's Official Ruby SDK
@@ -260,3 +275,4 @@ test_files:
260
275
  - spec/unit/messages/sample_data/mailgun_icon.png
261
276
  - spec/unit/messages/sample_data/mime.txt
262
277
  - spec/unit/messages/sample_data/rackspace_logo.jpg
278
+ - spec/unit/railgun_spec.rb