sendgrid-actionmailer 2.0.0 → 2.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/.travis.yml +1 -0
- data/README.md +14 -0
- data/gemfiles/mail_2.7.gemfile +7 -0
- data/lib/sendgrid_actionmailer.rb +12 -4
- data/lib/sendgrid_actionmailer/version.rb +1 -1
- data/sendgrid-actionmailer.gemspec +1 -1
- data/spec/lib/sendgrid_actionmailer_spec.rb +33 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92aceed9d68cf14a3c461fef95478935b2d6abad
|
4
|
+
data.tar.gz: cda4360a31bddc4dbc8dd02b1ad6bf96519b1f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7687cc4ede183737d615e2892844f1ac538e8b629f74952fd584761a81207c32fdcc44cd031898bc00996edc8a2eb13dbe5c01cbaf4bf951c2f31532d99c553e
|
7
|
+
data.tar.gz: e63c5d2236e329ab7b7898875c0d87fa2ffa34565e9b0ddbd58aa70753be615a4ea22a428b20f4e879e9b97cb0ac50209f3b5dfff80a825863a51c084fc1fdfc
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,20 @@ Normal ActionMailer usage will now transparently be sent using SendGrid's Web AP
|
|
24
24
|
|
25
25
|
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body')```
|
26
26
|
|
27
|
+
### Dynamic API Key
|
28
|
+
|
29
|
+
If you need to send mail for a number of Sendgrid accounts, you can set the API key for these as follows:
|
30
|
+
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
mail(to: 'example@email.com',
|
34
|
+
subject: 'email subject',
|
35
|
+
body: 'email body',
|
36
|
+
delivery_method_options: {
|
37
|
+
api_key: 'SENDGRID_API_KEY'
|
38
|
+
})
|
39
|
+
```
|
40
|
+
|
27
41
|
## SendGrid Mail Extensions
|
28
42
|
|
29
43
|
The Mail functionality is extended to include additional attributes provided by the Sendgrid API.
|
@@ -10,10 +10,10 @@ module SendGridActionMailer
|
|
10
10
|
include SendGrid
|
11
11
|
|
12
12
|
DEFAULTS = {
|
13
|
-
raise_delivery_errors: false
|
14
|
-
}
|
13
|
+
raise_delivery_errors: false
|
14
|
+
}.freeze
|
15
15
|
|
16
|
-
attr_accessor :settings
|
16
|
+
attr_accessor :settings, :api_key
|
17
17
|
|
18
18
|
def initialize(**params)
|
19
19
|
self.settings = DEFAULTS.merge(params)
|
@@ -28,6 +28,7 @@ module SendGridActionMailer
|
|
28
28
|
m.add_personalization(to_personalizations(mail))
|
29
29
|
end
|
30
30
|
|
31
|
+
add_api_key(sendgrid_mail, mail)
|
31
32
|
add_content(sendgrid_mail, mail)
|
32
33
|
add_send_options(sendgrid_mail, mail)
|
33
34
|
add_mail_settings(sendgrid_mail, mail)
|
@@ -41,7 +42,7 @@ module SendGridActionMailer
|
|
41
42
|
private
|
42
43
|
|
43
44
|
def client
|
44
|
-
@client
|
45
|
+
@client = SendGrid::API.new(api_key: api_key).client
|
45
46
|
end
|
46
47
|
|
47
48
|
# type should be either :plain or :html
|
@@ -105,6 +106,13 @@ module SendGridActionMailer
|
|
105
106
|
content_disp.disposition_type
|
106
107
|
end
|
107
108
|
|
109
|
+
def add_api_key(sendgrid_mail, mail)
|
110
|
+
self.api_key = settings.fetch(:api_key)
|
111
|
+
if mail['delivery-method-options'] && mail['delivery-method-options'].value.include?('api_key')
|
112
|
+
self.api_key = JSON.parse(mail['delivery-method-options'].value.gsub('=>', ':'))['api_key']
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
108
116
|
def add_content(sendgrid_mail, mail)
|
109
117
|
case mail.mime_type
|
110
118
|
when 'text/plain'
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
spec.add_dependency 'mail', '~> 2.5'
|
23
|
-
spec.add_dependency 'sendgrid-ruby', '~> 5.
|
23
|
+
spec.add_dependency 'sendgrid-ruby', '~> 5.2'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'appraisal', '~> 2.1.0'
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
@@ -59,6 +59,8 @@ module SendGridActionMailer
|
|
59
59
|
|
60
60
|
describe '#deliver!' do
|
61
61
|
let(:client) { TestClient.new }
|
62
|
+
let(:client_parent) { double(client: client) }
|
63
|
+
|
62
64
|
let(:mail) do
|
63
65
|
Mail.new(
|
64
66
|
to: 'test@sendgrid.com',
|
@@ -71,6 +73,37 @@ module SendGridActionMailer
|
|
71
73
|
stub_request(:any, 'https://api.sendgrid.com/api/mail.send.json')
|
72
74
|
.to_return(body: {message: 'success'}.to_json, status: 200, headers: {'X-TEST' => 'yes'})
|
73
75
|
allow(SendGrid::Client).to receive(:new).and_return(client)
|
76
|
+
allow(SendGrid::API).to receive(:new).and_return(client_parent)
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with dynamic api_key' do
|
80
|
+
let(:default) do
|
81
|
+
Mail.new(
|
82
|
+
to: 'test@sendgrid.com',
|
83
|
+
from: 'taco@cat.limo',
|
84
|
+
subject: 'Hello, world!'
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:mail) do
|
89
|
+
Mail.new(
|
90
|
+
to: 'test@sendgrid.com',
|
91
|
+
from: 'taco@cat.limo',
|
92
|
+
subject: 'Hello, world!',
|
93
|
+
delivery_method_options: {
|
94
|
+
api_key: 'test_key'
|
95
|
+
}
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'sets dynamic api_key, but should revert to default settings api_key' do
|
100
|
+
expect(SendGrid::API).to receive(:new).with(api_key: 'key')
|
101
|
+
mailer.deliver!(default)
|
102
|
+
expect(SendGrid::API).to receive(:new).with(api_key: 'test_key')
|
103
|
+
mailer.deliver!(mail)
|
104
|
+
expect(SendGrid::API).to receive(:new).with(api_key: 'key')
|
105
|
+
mailer.deliver!(default)
|
106
|
+
end
|
74
107
|
end
|
75
108
|
|
76
109
|
it 'sets to' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-actionmailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eddie Zaneski
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-09
|
13
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mail
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '5.
|
35
|
+
version: '5.2'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '5.
|
42
|
+
version: '5.2'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: appraisal
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- Rakefile
|
131
131
|
- gemfiles/mail_2.5.gemfile
|
132
132
|
- gemfiles/mail_2.6.gemfile
|
133
|
+
- gemfiles/mail_2.7.gemfile
|
133
134
|
- lib/sendgrid-actionmailer.rb
|
134
135
|
- lib/sendgrid_actionmailer.rb
|
135
136
|
- lib/sendgrid_actionmailer/railtie.rb
|