-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: geolocation setter in sendgrid-ruby for GDPR compliance (#496)
* feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance * feat: geolocation setter in sendgrid-ruby for GDPR compliance
- Loading branch information
1 parent
e17be75
commit 780e7a0
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'sendgrid-ruby' | ||
|
||
# Example 1 | ||
# Sending using "global" data residency | ||
|
||
from = SendGrid::Email.new(email: '[email protected]') | ||
to = SendGrid::Email.new(email: '[email protected]') | ||
subject = 'Sending with Twilio SendGrid is Fun' | ||
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') | ||
mail = SendGrid::Mail.new(from, subject, to, content) | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
sg.sendgrid_data_residency(region: "global") | ||
puts sg.host | ||
response = sg.client.mail._('send').post(request_body: mail.to_json) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
|
||
# Example 2 | ||
# Sending using "eu" data residency | ||
|
||
from = SendGrid::Email.new(email: '[email protected]') | ||
to = SendGrid::Email.new(email: '[email protected]') | ||
subject = 'Sending with Twilio SendGrid is Fun' | ||
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') | ||
mail = SendGrid::Mail.new(from, subject, to, content) | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY_EU']) | ||
sg.sendgrid_data_residency(region: 'eu') | ||
puts sg.host | ||
response = sg.client.mail._('send').post(request_body: mail.to_json) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
|
||
# Example 3 | ||
# Sending using no data residency | ||
|
||
from = SendGrid::Email.new(email: '[email protected]') | ||
to = SendGrid::Email.new(email: '[email protected]') | ||
subject = 'Sending with Twilio SendGrid is Fun' | ||
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') | ||
mail = SendGrid::Mail.new(from, subject, to, content) | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
puts sg.host | ||
response = sg.client.mail._('send').post(request_body: mail.to_json) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require_relative '../../../../lib/sendgrid-ruby' | ||
require 'minitest/autorun' | ||
|
||
class TestDataResidency < Minitest::Test | ||
include SendGrid | ||
|
||
def setup | ||
@global_email = 'https://api.sendgrid.com' | ||
@eu_email = 'https://api.eu.sendgrid.com' | ||
end | ||
|
||
def test_with_global_data_residency | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
sg.sendgrid_data_residency(region: 'global') | ||
assert_equal @global_email, sg.host | ||
end | ||
|
||
def test_with_global_eu_residency | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
sg.sendgrid_data_residency(region: 'eu') | ||
assert_equal @eu_email, sg.host | ||
end | ||
|
||
def test_with_global_nil_residency | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
assert_raises(ArgumentError) do | ||
sg.sendgrid_data_residency(region: nil) | ||
end | ||
end | ||
|
||
def test_with_global_invalid_residency | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
assert_raises(ArgumentError) do | ||
sg.sendgrid_data_residency(region: "abc") | ||
end | ||
end | ||
|
||
def test_with_global_empty_residency | ||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
assert_raises(ArgumentError) do | ||
sg.sendgrid_data_residency(region: "") | ||
end | ||
end | ||
end |