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 +4 -4
- data/README.md +2 -2
- data/lib/govdelivery/tms/mail/delivery_method.rb +19 -14
- data/lib/govdelivery/tms/version.rb +1 -1
- data/spec/mail/delivery_method_spec.rb +66 -33
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 520742183591839f3f51140b34e2d96e740c1171
|
4
|
+
data.tar.gz: f9ceb6d7d7fbd7a0ebb12ed4a9a16cc08e0c7833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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://
|
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
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
39
|
-
from_name: mail[:from].display_names.first,
|
39
|
+
message_params = {
|
40
40
|
subject: mail.subject,
|
41
|
-
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,
|
58
|
-
|
59
|
-
|
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
|
@@ -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
|
-
|
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
|
-
|
30
|
-
mail
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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
|