sendgrid-actionmailer 2.0.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/README.md +10 -2
- data/lib/sendgrid_actionmailer/version.rb +1 -1
- data/lib/sendgrid_actionmailer.rb +15 -7
- data/sendgrid-actionmailer.gemspec +2 -2
- data/spec/lib/sendgrid_actionmailer_spec.rb +23 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd39b2edccaafaa5842c9ce058a3cb454c128e6c
|
4
|
+
data.tar.gz: 23f300c8fb257f9f06983eaebcb54504fcb2fbcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 272cd434acac86b4a069c6d53ab0a9462021d4550cd4f24c2659258ceddf30f10d7c30c42de558d064400f676bd1a7107149ac34c92fb7a8cd115656c307fa2d
|
7
|
+
data.tar.gz: cfeabef756e01eaf744ba91401650495e591f0f1d224d3ac4eca0b6ece405a9629937c86aa1fbdb9fb376a2da798f38a929c65611d3d0ea154265acec3855494
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ An ActionMailer adapter to send email using SendGrid's HTTPS Web API (instead of
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'sendgrid-actionmailer'
|
9
|
+
gem 'sendgrid-actionmailer'
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
@@ -45,7 +45,7 @@ The Mail functionality is extended to include additional attributes provided by
|
|
45
45
|
[Sendgrid v3 API Documentation](https://sendgrid.com/docs/API_Reference/api_v3.html)
|
46
46
|
|
47
47
|
### template_id (string)
|
48
|
-
The id of a template that you would like to use. If you use a template that contains a subject
|
48
|
+
The id of a template that you would like to use. If you use a template that contains a subject, you do not need to specify a subject at the personalizations nor message level. However, because of the way ActionMailer works, a body is required, even if the template contains one. If all your emails use templates with a body, you can add `default body: "not used"` to the top of your mailer.
|
49
49
|
|
50
50
|
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', template_id: 'template_1')```
|
51
51
|
|
@@ -215,6 +215,12 @@ The name of the campaign.
|
|
215
215
|
|
216
216
|
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', tracking_settings:{ enable: true, utm_source: 'some source', utm_medium: 'some medium', utm_term: 'some term', utm_content: 'some content', utm_campaign: 'some campaign' }})```
|
217
217
|
|
218
|
+
### dynamic_template_data (json)
|
219
|
+
|
220
|
+
Data to provide for feeding the new dynamic templates in Sendgrid with valueable data. This also disables the following Unsubscribe links because of deprecation of substitutions in the new template implementaiton.
|
221
|
+
|
222
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', dynamic_template_data:{ variable_1: 'foo', variable_2: 'bar'})```
|
223
|
+
|
218
224
|
### Unsubscribe Links
|
219
225
|
|
220
226
|
Sendgrid unfortunately uses <% %> for their default substitution syntax, which makes it incompatible with Rails templates. Their proposed solution is to use Personalization Substitutions with the v3 Mail Send Endpoint. This gem makes that modification to make the following Rails friendly unsubscribe urls.
|
@@ -222,3 +228,5 @@ Sendgrid unfortunately uses <% %> for their default substitution syntax, which m
|
|
222
228
|
* `<a href="%asm_group_unsubscribe_raw_url%">Unsubscribe</a>`
|
223
229
|
* `<a href="%asm_global_unsubscribe_raw_url%">Unsubscribe from List</a>`
|
224
230
|
* `<a href="%asm_preferences_raw_url%">Manage Email Preferences</a>`
|
231
|
+
|
232
|
+
Note: This feature, and substitutions in general, do not work in combination with dynamic templates.
|
@@ -23,7 +23,7 @@ module SendGridActionMailer
|
|
23
23
|
sendgrid_mail = Mail.new.tap do |m|
|
24
24
|
m.from = to_email(mail.from)
|
25
25
|
m.reply_to = to_email(mail.reply_to)
|
26
|
-
m.subject = mail.subject
|
26
|
+
m.subject = mail.subject || ""
|
27
27
|
# https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html
|
28
28
|
m.add_personalization(to_personalizations(mail))
|
29
29
|
end
|
@@ -34,6 +34,7 @@ module SendGridActionMailer
|
|
34
34
|
add_mail_settings(sendgrid_mail, mail)
|
35
35
|
add_tracking_settings(sendgrid_mail, mail)
|
36
36
|
|
37
|
+
|
37
38
|
response = perform_send_request(sendgrid_mail)
|
38
39
|
|
39
40
|
settings[:return_response] ? response : self
|
@@ -79,9 +80,14 @@ module SendGridActionMailer
|
|
79
80
|
to_emails(mail.to).each { |to| p.add_to(to) }
|
80
81
|
to_emails(mail.cc).each { |cc| p.add_cc(cc) }
|
81
82
|
to_emails(mail.bcc).each { |bcc| p.add_bcc(bcc) }
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
|
84
|
+
if mail['dynamic_template_data']
|
85
|
+
p.add_dynamic_template_data(json_parse(mail['dynamic_template_data'].value))
|
86
|
+
elsif mail['template_id'].nil?
|
87
|
+
p.add_substitution(Substitution.new(key: "%asm_group_unsubscribe_raw_url%", value: "<%asm_group_unsubscribe_raw_url%>"))
|
88
|
+
p.add_substitution(Substitution.new(key: "%asm_global_unsubscribe_raw_url%", value: "<%asm_global_unsubscribe_raw_url%>"))
|
89
|
+
p.add_substitution(Substitution.new(key: "%asm_preferences_raw_url%", value: "<%asm_preferences_raw_url%>"))
|
90
|
+
end
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
@@ -130,7 +136,7 @@ module SendGridActionMailer
|
|
130
136
|
end
|
131
137
|
|
132
138
|
def json_parse(text, symbolize=true)
|
133
|
-
JSON.parse(text.gsub(/:*\"*([\%a-zA-Z0-9_-]*)\"*(( *)=>\ *)/) { "\"#{$1}\":" }, symbolize_names: symbolize)
|
139
|
+
JSON.parse(text.empty? ? '{}' : text.gsub(/:*\"*([\%a-zA-Z0-9_-]*)\"*(( *)=>\ *)/) { "\"#{$1}\":" }, symbolize_names: symbolize)
|
134
140
|
end
|
135
141
|
|
136
142
|
def add_send_options(sendgrid_mail, mail)
|
@@ -157,9 +163,11 @@ module SendGridActionMailer
|
|
157
163
|
sendgrid_mail.add_custom_arg(CustomArg.new(key: key, value: value))
|
158
164
|
end
|
159
165
|
end
|
160
|
-
if mail['send_at']
|
166
|
+
if mail['send_at']
|
161
167
|
sendgrid_mail.send_at = mail['send_at'].value.to_i
|
162
|
-
|
168
|
+
end
|
169
|
+
if mail['batch_id']
|
170
|
+
sendgrid_mail.batch_id = mail['batch_id'].to_s
|
163
171
|
end
|
164
172
|
if mail['asm']
|
165
173
|
asm = json_parse(mail['asm'].value)
|
@@ -20,10 +20,10 @@ 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', '~>
|
23
|
+
spec.add_dependency 'sendgrid-ruby', '~> 6.0'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'appraisal', '~> 2.1.0'
|
26
|
-
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'bundler'
|
27
27
|
spec.add_development_dependency 'rake'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
29
29
|
spec.add_development_dependency 'webmock'
|
@@ -384,6 +384,27 @@ module SendGridActionMailer
|
|
384
384
|
expect(client.sent_mail['tracking_settings']).to eq(tracking)
|
385
385
|
end
|
386
386
|
end
|
387
|
+
|
388
|
+
context 'dynamic template data' do
|
389
|
+
it 'sets dynamic_template_data' do
|
390
|
+
template_data = { variable_1: '1', variable_2: '2' }
|
391
|
+
mail['dynamic_template_data'] = template_data
|
392
|
+
mailer.deliver!(mail)
|
393
|
+
expect(client.sent_mail['personalizations'].first['dynamic_template_data']).to eq(template_data)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'sets dynamic template data and sandbox_mode' do
|
398
|
+
mail['mail_settings'] = '{}'
|
399
|
+
mailer.deliver!(mail)
|
400
|
+
expect(client.sent_mail['mail_settings']).to eq(nil)
|
401
|
+
end
|
402
|
+
|
403
|
+
it 'sets dynamic template data and sandbox_mode' do
|
404
|
+
mail['mail_settings'] = {}
|
405
|
+
mailer.deliver!(mail)
|
406
|
+
expect(client.sent_mail['mail_settings']).to eq(nil)
|
407
|
+
end
|
387
408
|
end
|
388
409
|
|
389
410
|
context 'multipart/alternative' do
|
@@ -443,7 +464,7 @@ module SendGridActionMailer
|
|
443
464
|
end
|
444
465
|
|
445
466
|
it 'adds the attachment' do
|
446
|
-
expect(mail.attachments.first.read).to
|
467
|
+
expect(mail.attachments.first.read).to include("it 'adds the attachment' do")
|
447
468
|
mailer.deliver!(mail)
|
448
469
|
attachment = client.sent_mail['attachments'].first
|
449
470
|
expect(attachment['filename']).to eq('specs.rb')
|
@@ -480,7 +501,7 @@ module SendGridActionMailer
|
|
480
501
|
end
|
481
502
|
|
482
503
|
it 'adds the inline attachment' do
|
483
|
-
expect(mail.attachments.first.read).to
|
504
|
+
expect(mail.attachments.first.read).to include("it 'adds the inline attachment' do")
|
484
505
|
mailer.deliver!(mail)
|
485
506
|
content = client.sent_mail['attachments'].first
|
486
507
|
expect(content['filename']).to eq('specs.rb')
|
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.4.0
|
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:
|
13
|
+
date: 2019-07-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: '
|
35
|
+
version: '6.0'
|
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: '
|
42
|
+
version: '6.0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: appraisal
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,16 +58,16 @@ dependencies:
|
|
58
58
|
name: bundler
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - "
|
61
|
+
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
63
|
+
version: '0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - "
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
70
|
+
version: '0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rake
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|