sendgrid-ruby 6.4.0 → 6.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/config.yml +10 -0
- data/.travis.yml +15 -14
- data/CHANGELOG.md +24 -0
- data/README.md +0 -1
- data/TROUBLESHOOTING.md +12 -0
- data/examples/helpers/mail/example.rb +5 -0
- data/lib/sendgrid/helpers/mail/personalization.rb +7 -1
- data/lib/sendgrid/version.rb +1 -1
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +2 -2
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +2 -2
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +2 -2
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +2 -2
- data/test/sendgrid/helpers/mail/test_personalizations.rb +13 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +1 -1
- data/use-cases/README.md +1 -0
- data/use-cases/personalizations.md +34 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24757e772b52f0b9e130a824d65bea991c3fe5966f705cd3c2b67fdb8b1ade0e
|
4
|
+
data.tar.gz: 972ea7b52d490fce2ddb97315356965fab0001e1511087834979620cbeb118a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af9a46c70ff25fadfce7458b64a75e0255063d7f082ff8b9d9f4bbff9f0aa3136969864b717f6f01666ee1c04c354a3bb03afc9dc3620de26ffb4b63e0011002
|
7
|
+
data.tar.gz: 7992f9c04da91c16f76eee4cfd6860df83584046c00cff6a3b3f1b5ac0318e2bde8c8f2ee1329016bc28d0fd7c62a0c92d56bedf71805bfb86a5a6436f85035a
|
@@ -0,0 +1,10 @@
|
|
1
|
+
contact_links:
|
2
|
+
- name: Twilio SendGrid Support
|
3
|
+
url: https://support.sendgrid.com
|
4
|
+
about: Get Support
|
5
|
+
- name: Stack Overflow
|
6
|
+
url: https://stackoverflow.com/questions/tagged/sendgrid-ruby+or+sendgrid+ruby
|
7
|
+
about: Ask questions on Stack Overflow
|
8
|
+
- name: Documentation
|
9
|
+
url: https://sendgrid.com/docs/for-developers/
|
10
|
+
about: View Reference Documentation
|
data/.travis.yml
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
language: ruby
|
2
2
|
env:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
- version=ruby:3.0
|
4
|
+
- version=ruby:2.7
|
5
|
+
- version=ruby:2.6
|
6
|
+
- version=ruby:2.5
|
7
|
+
- version=ruby:2.4
|
8
|
+
- version=jruby:9.2
|
9
9
|
gemfile:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
- gemfiles/Sinatra_1.gemfile
|
11
|
+
- gemfiles/Sinatra_2.gemfile
|
12
|
+
script:
|
13
|
+
- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
14
|
+
echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin;
|
15
|
+
fi
|
16
|
+
- make test-docker
|
15
17
|
deploy:
|
16
18
|
provider: rubygems
|
17
|
-
api_key: $RUBYGEMS_API_KEY
|
19
|
+
api_key: "$RUBYGEMS_API_KEY"
|
18
20
|
gem: sendgrid-ruby
|
19
21
|
on:
|
20
22
|
tags: true
|
21
23
|
condition: $version = ruby:2.4 && $BUNDLE_GEMFILE = *"gemfiles/Sinatra_1.gemfile"
|
22
|
-
|
23
24
|
notifications:
|
24
25
|
slack:
|
25
26
|
if: branch = main
|
@@ -27,4 +28,4 @@ notifications:
|
|
27
28
|
on_success: never
|
28
29
|
on_failure: change
|
29
30
|
rooms:
|
30
|
-
|
31
|
+
secure: oSeohwM+ernyiRYSRLpNlICk0wgj0lku3y5LuouJLRHs45tCAzLZLbgxsor18wCSJkmhfn2vg4Rn969VnskFuj70OhJSLBKL4UXBnR1Ji0ClpfJlGojcbY/5Z8N/eGDrvf5ofA0Jc+L/ut+oSCMXnstEGbx4wBpPTajHuRtvb34=
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
[2021-11-03] Version 6.6.0
|
5
|
+
--------------------------
|
6
|
+
**Library - Feature**
|
7
|
+
- [PR #473](https://github.com/sendgrid/sendgrid-ruby/pull/473): update tests, use-cases, examples and implementation for From personalization. Thanks to [@beebzz](https://github.com/beebzz)!
|
8
|
+
|
9
|
+
|
10
|
+
[2021-10-18] Version 6.5.2
|
11
|
+
--------------------------
|
12
|
+
**Library - Docs**
|
13
|
+
- [PR #472](https://github.com/sendgrid/sendgrid-ruby/pull/472): improve signed webhook event validation docs. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)!
|
14
|
+
|
15
|
+
|
16
|
+
[2021-09-08] Version 6.5.1
|
17
|
+
--------------------------
|
18
|
+
**Library - Chore**
|
19
|
+
- [PR #470](https://github.com/sendgrid/sendgrid-ruby/pull/470): add support for ruby 3.0. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)!
|
20
|
+
|
21
|
+
|
22
|
+
[2021-08-11] Version 6.5.0
|
23
|
+
--------------------------
|
24
|
+
**Library - Feature**
|
25
|
+
- [PR #466](https://github.com/sendgrid/sendgrid-ruby/pull/466): Add From address to personalization. Thanks to [@grin](https://github.com/grin)!
|
26
|
+
|
27
|
+
|
4
28
|
[2021-02-10] Version 6.4.0
|
5
29
|
--------------------------
|
6
30
|
**Library - Feature**
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Travis Badge](https://travis-ci.com/sendgrid/sendgrid-ruby.svg?branch=main)](https://travis-ci.com/sendgrid/sendgrid-ruby)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby)
|
5
|
-
[![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby)
|
6
5
|
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
|
7
6
|
[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
|
8
7
|
[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-ruby.svg)](https://github.com/sendgrid/sendgrid-ruby/graphs/contributors)
|
data/TROUBLESHOOTING.md
CHANGED
@@ -17,6 +17,7 @@ If you can't find a solution below, please open an [issue](https://github.com/se
|
|
17
17
|
* [Rails Specifics](#rails-specifics)
|
18
18
|
* [Ruby Versions](#ruby-versions)
|
19
19
|
* [Viewing the Request Body](#viewing-the-request-body)
|
20
|
+
* [Verifying Event Webhooks](#signed-webhooks)
|
20
21
|
|
21
22
|
<a name="migrating"></a>
|
22
23
|
## Migrating from v2 to v3
|
@@ -137,3 +138,14 @@ You can do this before `response = sg.client.mail._('send').post(request_body: m
|
|
137
138
|
```ruby
|
138
139
|
puts mail.to_json
|
139
140
|
```
|
141
|
+
|
142
|
+
<a name="signed-webhooks"></a>
|
143
|
+
## Signed Webhook Verification
|
144
|
+
|
145
|
+
Twilio SendGrid's Event Webhook will notify a URL via HTTP POST with information about events that occur as your mail is processed. [This](https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features) article covers all you need to know to secure the Event Webhook, allowing you to verify that incoming requests originate from Twilio SendGrid. The sendgrid-ruby library can help you verify these Signed Event Webhooks.
|
146
|
+
|
147
|
+
You can find the usage example [here](examples/helpers/eventwebhook/example.rb) and the tests [here](spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb).
|
148
|
+
If you are still having trouble getting the validation to work, follow the following instructions:
|
149
|
+
- Be sure to use the *raw* payload for validation
|
150
|
+
- Be sure to include a trailing carriage return and newline in your payload
|
151
|
+
- In case of multi-event webhooks, make sure you include the trailing newline and carriage return after *each* event
|
@@ -18,6 +18,7 @@ def hello_world
|
|
18
18
|
puts response.headers
|
19
19
|
end
|
20
20
|
|
21
|
+
# rubocop:disable Metrics/AbcSize
|
21
22
|
def kitchen_sink
|
22
23
|
mail = SendGrid::Mail.new
|
23
24
|
mail.from = Email.new(email: 'test@example.com')
|
@@ -29,6 +30,9 @@ def kitchen_sink
|
|
29
30
|
personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
|
30
31
|
personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
|
31
32
|
personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
|
33
|
+
# Note, the domain of the from email property specified in any personalization must
|
34
|
+
# match the domain of the from email property specified at root level
|
35
|
+
personalization.add_from(Email.new(email: 'alias@example.com', name: "My alias"))
|
32
36
|
personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
|
33
37
|
personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
|
34
38
|
personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
|
@@ -124,6 +128,7 @@ def kitchen_sink
|
|
124
128
|
puts response.body
|
125
129
|
puts response.headers
|
126
130
|
end
|
131
|
+
# rubocop:enable Metrics/AbcSize
|
127
132
|
|
128
133
|
def dynamic_template_data_hello_world
|
129
134
|
mail = Mail.new
|
@@ -2,13 +2,14 @@ require 'json'
|
|
2
2
|
|
3
3
|
module SendGrid
|
4
4
|
class Personalization
|
5
|
-
attr_reader :tos, :ccs, :bccs, :headers, :substitutions, :custom_args,
|
5
|
+
attr_reader :tos, :from, :ccs, :bccs, :headers, :substitutions, :custom_args,
|
6
6
|
:dynamic_template_data
|
7
7
|
|
8
8
|
attr_accessor :send_at, :subject
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@tos = []
|
12
|
+
@from = nil
|
12
13
|
@ccs = []
|
13
14
|
@bccs = []
|
14
15
|
@subject = nil
|
@@ -25,6 +26,10 @@ module SendGrid
|
|
25
26
|
@tos << to.to_json
|
26
27
|
end
|
27
28
|
|
29
|
+
def add_from(from)
|
30
|
+
@from = from.to_json
|
31
|
+
end
|
32
|
+
|
28
33
|
def add_cc(cc)
|
29
34
|
raise DuplicatePersonalizationError if duplicate?(cc)
|
30
35
|
|
@@ -59,6 +64,7 @@ module SendGrid
|
|
59
64
|
def to_json(*)
|
60
65
|
{
|
61
66
|
'to' => tos,
|
67
|
+
'from' => from,
|
62
68
|
'cc' => ccs,
|
63
69
|
'bcc' => bccs,
|
64
70
|
'subject' => subject,
|
data/lib/sendgrid/version.rb
CHANGED
@@ -19,14 +19,14 @@ describe SendGrid::MailSettingsDto do
|
|
19
19
|
describe '.fetch' do
|
20
20
|
it 'calls get on sendgrid_client' do
|
21
21
|
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
22
|
-
expect(mail_settings.fetch(args)).to be_a SendGrid::Response
|
22
|
+
expect(mail_settings.fetch(**args)).to be_a SendGrid::Response
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '.update' do
|
27
27
|
it 'calls patch on sendgrid_client' do
|
28
28
|
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
29
|
-
expect(mail_settings.update(args)).to be_a SendGrid::Response
|
29
|
+
expect(mail_settings.update(**args)).to be_a SendGrid::Response
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -11,14 +11,14 @@ describe SendGrid::PartnerSettingsDto do
|
|
11
11
|
describe '.fetch' do
|
12
12
|
it 'calls get on sendgrid_client' do
|
13
13
|
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
14
|
-
expect(partner_settings.fetch(args)).to be_a SendGrid::Response
|
14
|
+
expect(partner_settings.fetch(**args)).to be_a SendGrid::Response
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '.update' do
|
19
19
|
it 'calls patch on sendgrid_client' do
|
20
20
|
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
21
|
-
expect(partner_settings.update(args)).to be_a SendGrid::Response
|
21
|
+
expect(partner_settings.update(**args)).to be_a SendGrid::Response
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -14,14 +14,14 @@ describe SendGrid::TrackingSettingsDto do
|
|
14
14
|
describe '.fetch' do
|
15
15
|
it 'calls get on sendgrid_client' do
|
16
16
|
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
17
|
-
expect(tracking_settings.fetch(args)).to be_a SendGrid::Response
|
17
|
+
expect(tracking_settings.fetch(**args)).to be_a SendGrid::Response
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '.update' do
|
22
22
|
it 'calls patch on sendgrid_client' do
|
23
23
|
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
24
|
-
expect(tracking_settings.update(args)).to be_a SendGrid::Response
|
24
|
+
expect(tracking_settings.update(**args)).to be_a SendGrid::Response
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -11,14 +11,14 @@ describe SendGrid::UserSettingsDto do
|
|
11
11
|
describe '.fetch' do
|
12
12
|
it 'calls get on sendgrid_client' do
|
13
13
|
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
14
|
-
expect(user_settings.fetch(args)).to be_a SendGrid::Response
|
14
|
+
expect(user_settings.fetch(**args)).to be_a SendGrid::Response
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '.update' do
|
19
19
|
it 'calls patch on sendgrid_client' do
|
20
20
|
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
21
|
-
expect(user_settings.update(args)).to be_a SendGrid::Response
|
21
|
+
expect(user_settings.update(**args)).to be_a SendGrid::Response
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -45,6 +45,19 @@ class TestPersonalization < Minitest::Test
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def test_add_from
|
49
|
+
@personalization = Personalization.new
|
50
|
+
@personalization.add_from(Email.new(email: 'from1@example.com', name: 'Example Sender'))
|
51
|
+
expected_json = {
|
52
|
+
'from' => {
|
53
|
+
'email' => 'from1@example.com',
|
54
|
+
'name' => 'Example Sender'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
assert_equal @personalization.to_json, expected_json
|
59
|
+
end
|
60
|
+
|
48
61
|
def test_add_cc
|
49
62
|
@personalization = Personalization.new
|
50
63
|
@personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Example User'))
|
@@ -33,7 +33,7 @@ class TestAPI < MiniTest::Test
|
|
33
33
|
assert_equal(test_headers, sg.request_headers)
|
34
34
|
assert_equal('v3', sg.version)
|
35
35
|
assert_equal(subuser, sg.impersonate_subuser)
|
36
|
-
assert_equal('6.
|
36
|
+
assert_equal('6.6.0', SendGrid::VERSION)
|
37
37
|
assert_instance_of(SendGrid::Client, sg.client)
|
38
38
|
assert_equal({}, sg.http_options)
|
39
39
|
end
|
data/use-cases/README.md
CHANGED
@@ -5,6 +5,7 @@ Please [open an issue](https://github.com/sendgrid/sendgrid-ruby/issues) or [mak
|
|
5
5
|
# Email Use Cases
|
6
6
|
* [Transactional Templates](transactional-templates.md)
|
7
7
|
* [Legacy Templates](legacy-templates.md)
|
8
|
+
* [Personalizations](personalizations.md)
|
8
9
|
|
9
10
|
# Twilio Use Cases
|
10
11
|
* [Twilio Setup](twilio-setup.md)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Personalizations
|
2
|
+
|
3
|
+
This example demonstrates how to send multiple emails with personalizations. For further documentation, refer to [the SendGrid docs](https://docs.sendgrid.com/for-developers/sending-email/personalizations).
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'sendgrid-ruby'
|
7
|
+
include SendGrid
|
8
|
+
|
9
|
+
# Note that the domain for all From addresses must match
|
10
|
+
mail = Mail.new
|
11
|
+
mail.from = Email.new(email: 'test@example.com')
|
12
|
+
mail.add_content(Content.new(type: 'text/plain', value: 'Some test text'))
|
13
|
+
mail.subject = 'Personalized Test Email'
|
14
|
+
|
15
|
+
personalization = Personalization.new
|
16
|
+
personalization.add_to(Email.new(email: 'test1@example.com'))
|
17
|
+
mail.add_personalization(personalization)
|
18
|
+
|
19
|
+
personalization2 = Personalization.new
|
20
|
+
personalization2.add_to(Email.new(email: 'test2@example.com'))
|
21
|
+
personalization2.add_from(Email.new(email: 'test3@example.com'))
|
22
|
+
mail.add_personalization(personalization2)
|
23
|
+
|
24
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
25
|
+
begin
|
26
|
+
response = sg.client.mail._("send").post(request_body: mail.to_json)
|
27
|
+
rescue Exception => e
|
28
|
+
puts e.message
|
29
|
+
end
|
30
|
+
|
31
|
+
puts response.status_code
|
32
|
+
puts response.body
|
33
|
+
puts response.headers
|
34
|
+
```
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elmer Thomas
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-11-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_http_client
|
@@ -167,6 +167,7 @@ extra_rdoc_files: []
|
|
167
167
|
files:
|
168
168
|
- ".codeclimate.yml"
|
169
169
|
- ".env_sample"
|
170
|
+
- ".github/ISSUE_TEMPLATE/config.yml"
|
170
171
|
- ".gitignore"
|
171
172
|
- ".rubocop.yml"
|
172
173
|
- ".rubocop_todo.yml"
|
@@ -299,6 +300,7 @@ files:
|
|
299
300
|
- use-cases/domain-authentication.md
|
300
301
|
- use-cases/email-statistics.md
|
301
302
|
- use-cases/legacy-templates.md
|
303
|
+
- use-cases/personalizations.md
|
302
304
|
- use-cases/sms.md
|
303
305
|
- use-cases/transactional-templates.md
|
304
306
|
- use-cases/twilio-email.md
|