govdelivery-tms 0.8.4 → 0.8.5

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
2
  SHA1:
3
- metadata.gz: 1ce657fa1b15b63c469d0356e957b7beabdbab35
4
- data.tar.gz: edd672408bcc95c5368e4e9aa16a951de9686ec7
3
+ metadata.gz: 520742183591839f3f51140b34e2d96e740c1171
4
+ data.tar.gz: f9ceb6d7d7fbd7a0ebb12ed4a9a16cc08e0c7833
5
5
  SHA512:
6
- metadata.gz: e838c311a8c1229cc2498530ad81bd64c5a21ce4df62dc972eb04a406ace9da875fcf5ca31a36258894250762fc91aefb525db38e50a979fead65e56d9db4f09
7
- data.tar.gz: 158553265ef2d84a8f0876e42cdad519000a58d9d10c616f172700817be252218fba587177f0336f9666d9cdc3d33a036071339c19319c07a289b3f5249c21d8
6
+ metadata.gz: 5db5dc48b49fc4f8ac19e031eebe91bb2fed6819a58c97935136f226c4e04141b59acf2e84b148b329d8e9d0d462f52ff46936d0165d9769afb0a873af2c0877
7
+ data.tar.gz: 81e2c0be20ad23096cd623b852e557545e37edcbe1ec7db633c81fda9b9f46794771cbe583a85abd0bc1ed26610a5bf96b89094788bd907ca16ccfa4bbca52c1
data/README.md CHANGED
@@ -238,7 +238,7 @@ You can use TMS from the mail gem or ActionMailer as a delivery method.
238
238
 
239
239
  Gemfile
240
240
  ```ruby
241
- gem 'govdelivery-tms', :require=>'govdelivery-tms/mail/delivery_method'
241
+ gem 'govdelivery-tms', :require=>'govdelivery/tms/mail/delivery_method'
242
242
  ```
243
243
 
244
244
  config/environment.rb
@@ -246,7 +246,7 @@ config/environment.rb
246
246
  config.action_mailer.delivery_method = :govdelivery_tms
247
247
  config.action_mailer.govdelivery_tms_settings = {
248
248
  :auth_token=>'auth_token',
249
- :api_root=>'https://stage-tms.govdelivery.com'
249
+ :api_root=>'https://tms.govdelivery.com'
250
250
  }
251
251
  ```
252
252
 
@@ -1,12 +1,13 @@
1
1
  require 'govdelivery-tms'
2
2
  require 'mail'
3
3
  require 'mail/check_delivery_params'
4
+
4
5
  module GovDelivery::TMS
5
6
  module Mail
6
7
  # Use TMS from the mail gem or ActionMailer as a delivery method.
7
8
  #
8
9
  # # Gemfile
9
- # gem 'govdelivery-tms', :require=>'govdelivery-tms/mail/delivery_method'
10
+ # gem 'govdelivery-tms', :require=>'govdelivery/tms/mail/delivery_method'
10
11
  #
11
12
  # # config/environment.rb
12
13
  # config.action_mailer.delivery_method = :govdelivery_tms
@@ -27,19 +28,23 @@ module GovDelivery::TMS
27
28
  fail GovDelivery::TMS::Errors::NoRelation.new('email_messages', client) unless client.respond_to?(:email_messages)
28
29
 
29
30
  body = case
30
- when mail.html_part
31
- mail.html_part.body
32
- when mail.text_part
33
- mail.text_part.body
34
- else
35
- mail.body
31
+ when mail.html_part
32
+ mail.html_part.body
33
+ when mail.text_part
34
+ mail.text_part.body
35
+ else
36
+ mail.body
36
37
  end.decoded
37
38
 
38
- tms_message = client.email_messages.build(
39
- from_name: mail[:from].display_names.first,
39
+ message_params = {
40
40
  subject: mail.subject,
41
- body: body
42
- )
41
+ body: body
42
+ }
43
+ message_params[:from_email] = mail.from.first unless mail.from.blank?
44
+ message_params[:from_name] = mail[:from].display_names.first unless mail[:from].blank?
45
+
46
+ tms_message = client.email_messages.build(message_params)
47
+
43
48
 
44
49
  mail.to.each { |recip| tms_message.recipients.build(email: recip) }
45
50
  tms_message.post!
@@ -54,7 +59,7 @@ module GovDelivery::TMS
54
59
  end
55
60
 
56
61
  if defined?(ActionMailer)
57
- ActionMailer::Base.add_delivery_method :govdelivery_tms, GovDelivery::TMS::Mail::DeliveryMethod, auth_token: nil,
58
- logger: ActionMailer::Base.logger,
59
- api_root: GovDelivery::TMS::Client::DEFAULTS[:api_root]
62
+ ActionMailer::Base.add_delivery_method :govdelivery_tms, GovDelivery::TMS::Mail::DeliveryMethod, auth_token: nil,
63
+ logger: ActionMailer::Base.logger,
64
+ api_root: GovDelivery::TMS::Client::DEFAULTS[:api_root]
60
65
  end
@@ -1,5 +1,5 @@
1
1
  module GovDelivery
2
2
  module TMS #:nodoc:
3
- VERSION = '0.8.4'
3
+ VERSION = '0.8.5'
4
4
  end
5
5
  end
@@ -7,45 +7,78 @@ describe GovDelivery::TMS::Mail::DeliveryMethod do
7
7
  let(:email_messages) { double('email_messages') }
8
8
  let(:tms_message) { double('tms_message', recipients: double(build: GovDelivery::TMS::Recipient.new('href'))) }
9
9
 
10
- it 'should work with a basic Mail::Message' do
11
- mail = Mail.new do
12
- subject 'hi'
13
- from '"My mom" <my@mom.com>'
14
- to '"A Nice Fellow" <tyler@sink.govdelivery.com>'
15
- body '<blink>HI</blink>'
16
- end
10
+ before do
17
11
  allow(client).to receive(:email_messages).and_return(email_messages)
18
12
  allow(subject).to receive(:client).and_return(client)
19
- expect(email_messages).to receive(:build).with(
20
- from_name: mail[:from].display_names.first,
21
- subject: mail.subject,
22
- body: '<blink>HI</blink>'
23
- ).and_return(tms_message)
24
- expect(tms_message).to receive(:post!).and_return(true)
25
-
26
- subject.deliver!(mail)
27
13
  end
28
14
 
29
- it 'should work with a multipart Mail::Message' do
30
- mail = Mail.new do
31
- subject 'hi'
32
- from '"My mom" <my@mom.com>'
33
- to '"A Nice Fellow" <tyler@sink.govdelivery.com>'
15
+ context 'a basic Mail::Message with all options' do
16
+ let(:mail) {
17
+ Mail.new do
18
+ subject 'hi'
19
+ from '"My mom" <my@mom.com>'
20
+ to '"A Nice Fellow" <tyler@sink.govdelivery.com>'
21
+ body '<blink>HI</blink>'
22
+ end
23
+ }
24
+
25
+ it 'should get sent' do
26
+ expect(email_messages).to receive(:build).with(
27
+ from_name: mail[:from].display_names.first,
28
+ from_email: mail.from.first,
29
+ subject: mail.subject,
30
+ body: '<blink>HI</blink>'
31
+ ).and_return(tms_message)
32
+ expect(tms_message).to receive(:post!).and_return(true)
34
33
 
35
- html_part do
36
- content_type 'text/html; charset=UTF-8'
37
- body '<blink>HTML</blink>'
34
+ subject.deliver!(mail)
35
+ end
36
+ end
37
+
38
+ context 'a basic Mail::Message with minimal options' do
39
+ let(:mail) {
40
+ Mail.new do
41
+ subject 'hi'
42
+ to '"A Nice Fellow" <tyler@sink.govdelivery.com>'
43
+ body '<blink>HI</blink>'
38
44
  end
45
+ }
46
+
47
+ it 'should get sent' do
48
+ expect(email_messages).to receive(:build).with(
49
+ subject: mail.subject,
50
+ body: '<blink>HI</blink>'
51
+ ).and_return(tms_message)
52
+ expect(tms_message).to receive(:post!).and_return(true)
53
+
54
+ subject.deliver!(mail)
55
+ end
56
+ end
57
+
58
+ context "a multipart Mail::Message" do
59
+ let(:mail) {
60
+ Mail.new do
61
+ subject 'hi'
62
+ from '"My mom" <my@mom.com>'
63
+ to '"A Nice Fellow" <tyler@sink.govdelivery.com>'
64
+
65
+ html_part do
66
+ content_type 'text/html; charset=UTF-8'
67
+ body '<blink>HTML</blink>'
68
+ end
69
+ end
70
+ }
71
+
72
+ it 'should send' do
73
+ expect(email_messages).to receive(:build).with(
74
+ from_name: mail[:from].display_names.first,
75
+ from_email: mail.from.first,
76
+ subject: mail.subject,
77
+ body: '<blink>HTML</blink>'
78
+ ).and_return(tms_message)
79
+ expect(tms_message).to receive(:post!).and_return(true)
80
+
81
+ subject.deliver!(mail)
39
82
  end
40
- allow(client).to receive(:email_messages).and_return(email_messages)
41
- allow(subject).to receive(:client).and_return(client)
42
- expect(email_messages).to receive(:build).with(
43
- from_name: mail[:from].display_names.first,
44
- subject: mail.subject,
45
- body: '<blink>HTML</blink>'
46
- ).and_return(tms_message)
47
- expect(tms_message).to receive(:post!).and_return(true)
48
-
49
- subject.deliver!(mail)
50
83
  end
51
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govdelivery-tms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - GovDelivery