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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92aceed9d68cf14a3c461fef95478935b2d6abad
4
- data.tar.gz: cda4360a31bddc4dbc8dd02b1ad6bf96519b1f84
3
+ metadata.gz: bd39b2edccaafaa5842c9ce058a3cb454c128e6c
4
+ data.tar.gz: 23f300c8fb257f9f06983eaebcb54504fcb2fbcf
5
5
  SHA512:
6
- metadata.gz: 7687cc4ede183737d615e2892844f1ac538e8b629f74952fd584761a81207c32fdcc44cd031898bc00996edc8a2eb13dbe5c01cbaf4bf951c2f31532d99c553e
7
- data.tar.gz: e63c5d2236e329ab7b7898875c0d87fa2ffa34565e9b0ddbd58aa70753be615a4ea22a428b20f4e879e9b97cb0ac50209f3b5dfff80a825863a51c084fc1fdfc
6
+ metadata.gz: 272cd434acac86b4a069c6d53ab0a9462021d4550cd4f24c2659258ceddf30f10d7c30c42de558d064400f676bd1a7107149ac34c92fb7a8cd115656c307fa2d
7
+ data.tar.gz: cfeabef756e01eaf744ba91401650495e591f0f1d224d3ac4eca0b6ece405a9629937c86aa1fbdb9fb376a2da798f38a929c65611d3d0ea154265acec3855494
data/.travis.yml CHANGED
@@ -5,8 +5,8 @@ rvm:
5
5
  - 2.4.4
6
6
  - 2.3.4
7
7
  - 2.3.7
8
- - 2.2.10
9
8
  before_install:
9
+ - gem update --system
10
10
  - gem install bundler
11
11
  gemfile:
12
12
  - gemfiles/mail_2.5.gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.4.0 - 2019-07-9
4
+
5
+ ### Changed
6
+
7
+ - Compatibility with `sendgrid-ruby` v6.0.
8
+
9
+
3
10
  ## 2.0.0 - 2018-08-15
4
11
 
5
12
  ### 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', github: 'eddiezane/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 and content (either text or html), you do not need to specify those at the personalizations nor message level.
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.
@@ -1,3 +1,3 @@
1
1
  module SendGridActionMailer
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.4.0'.freeze
3
3
  end
@@ -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
- p.add_substitution(Substitution.new(key: "%asm_group_unsubscribe_raw_url%", value: "<%asm_group_unsubscribe_raw_url%>"))
83
- p.add_substitution(Substitution.new(key: "%asm_global_unsubscribe_raw_url%", value: "<%asm_global_unsubscribe_raw_url%>"))
84
- p.add_substitution(Substitution.new(key: "%asm_preferences_raw_url%", value: "<%asm_preferences_raw_url%>"))
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'] && mail['batch_id']
166
+ if mail['send_at']
161
167
  sendgrid_mail.send_at = mail['send_at'].value.to_i
162
- sendgrid_mail.batch_id= mail['batch_id'].to_s
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', '~> 5.2'
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', '~> 1.6'
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 eq(File.read(__FILE__))
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 eq(File.read(__FILE__))
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.1
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: 2018-10-09 00:00:00.000000000 Z
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: '5.2'
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: '5.2'
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: '1.6'
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: '1.6'
70
+ version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rake
73
73
  requirement: !ruby/object:Gem::Requirement