sendgrid-ruby 5.3.0 → 6.7.0
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 +5 -5
- data/.github/workflows/pr-lint.yml +15 -0
- data/.github/workflows/test-and-deploy.yml +120 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +127 -0
- data/CHANGELOG.md +261 -8
- data/CODE_OF_CONDUCT.md +57 -25
- data/CONTRIBUTING.md +24 -71
- data/Dockerfile +14 -0
- data/FIRST_TIMERS.md +53 -0
- data/Gemfile +0 -1
- data/LICENSE +21 -0
- data/Makefile +14 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +39 -43
- data/Rakefile +3 -4
- data/TROUBLESHOOTING.md +41 -21
- data/UPGRADE.md +5 -0
- data/USAGE.md +1231 -1122
- data/examples/accesssettings/accesssettings.rb +9 -12
- data/examples/alerts/alerts.rb +8 -11
- data/examples/apikeys/apikeys.rb +12 -15
- data/examples/asm/asm.rb +27 -30
- data/examples/browsers/browsers.rb +0 -3
- data/examples/campaigns/campaigns.rb +29 -32
- data/examples/categories/categories.rb +0 -3
- data/examples/clients/clients.rb +1 -4
- data/examples/contactdb/contactdb.rb +63 -66
- data/examples/dataresidency/setregion.rb +48 -0
- data/examples/devices/devices.rb +0 -3
- data/examples/emailactivity/emailactivity.rb +52 -0
- data/examples/geo/geo.rb +0 -3
- data/examples/helpers/eventwebhook/example.rb +16 -0
- data/examples/helpers/mail/example.rb +30 -19
- data/examples/helpers/settings/example.rb +1 -1
- data/examples/helpers/stats/example.rb +4 -4
- data/examples/ips/ips.rb +31 -21
- data/examples/mail/mail.rb +73 -76
- data/examples/mailboxproviders/mailboxproviders.rb +0 -3
- data/examples/mailsettings/mailsettings.rb +21 -24
- data/examples/partnersettings/partnersettings.rb +3 -6
- data/examples/scopes/scopes.rb +49 -5
- data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +68 -71
- data/examples/senders/senders.rb +28 -31
- data/examples/stats/stats.rb +0 -3
- data/examples/subusers/subusers.rb +17 -20
- data/examples/suppression/suppression.rb +23 -26
- data/examples/templates/templates.rb +29 -31
- data/examples/trackingsettings/trackingsettings.rb +14 -17
- data/examples/user/user.rb +41 -44
- data/lib/rack/sendgrid_webhook_verification.rb +55 -0
- data/lib/sendgrid/base_interface.rb +57 -0
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
- data/lib/sendgrid/helpers/inbound/README.md +26 -9
- data/lib/sendgrid/helpers/inbound/app.rb +15 -3
- data/lib/sendgrid/helpers/inbound/public/index.html +2 -2
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +2 -2
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +2 -2
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +2 -2
- data/lib/sendgrid/helpers/inbound/send.rb +5 -5
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +4 -4
- data/lib/sendgrid/helpers/mail/asm.rb +4 -18
- data/lib/sendgrid/helpers/mail/attachment.rb +30 -38
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +4 -18
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +6 -18
- data/lib/sendgrid/helpers/mail/category.rb +2 -12
- data/lib/sendgrid/helpers/mail/click_tracking.rb +4 -18
- data/lib/sendgrid/helpers/mail/content.rb +4 -18
- data/lib/sendgrid/helpers/mail/custom_arg.rb +4 -10
- data/lib/sendgrid/helpers/mail/email.rb +10 -20
- data/lib/sendgrid/helpers/mail/footer.rb +5 -27
- data/lib/sendgrid/helpers/mail/ganalytics.rb +9 -55
- data/lib/sendgrid/helpers/mail/header.rb +4 -10
- data/lib/sendgrid/helpers/mail/mail.rb +37 -87
- data/lib/sendgrid/helpers/mail/mail_settings.rb +7 -25
- data/lib/sendgrid/helpers/mail/open_tracking.rb +4 -18
- data/lib/sendgrid/helpers/mail/personalization.rb +38 -27
- data/lib/sendgrid/helpers/mail/section.rb +4 -10
- data/lib/sendgrid/helpers/mail/spam_check.rb +5 -27
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +6 -36
- data/lib/sendgrid/helpers/mail/substitution.rb +4 -10
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +6 -20
- data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
- data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
- data/lib/sendgrid/helpers/settings/README.md +3 -3
- data/lib/sendgrid/helpers/settings/settings.rb +1 -1
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +3 -5
- data/lib/sendgrid/helpers/stats/metrics.rb +5 -7
- data/lib/sendgrid/helpers/stats/stats_response.rb +1 -3
- data/lib/sendgrid/sendgrid.rb +21 -0
- data/lib/sendgrid/twilio_email.rb +21 -0
- data/lib/sendgrid/version.rb +1 -1
- data/lib/sendgrid-ruby.rb +7 -1
- data/mail_helper_v3.md +21 -21
- data/sendgrid-ruby.gemspec +12 -12
- data/spec/fixtures/event_webhook.rb +22 -0
- data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +3 -3
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +3 -3
- data/spec/sendgrid/helpers/settings/settings_spec.rb +2 -2
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +3 -3
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +3 -3
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +22 -23
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +19 -20
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +22 -23
- data/spec/sendgrid/sendgrid_spec.rb +11 -0
- data/spec/sendgrid/twilio_email_spec.rb +11 -0
- data/spec/spec_helper.rb +3 -1
- data/static/img/github-fork.png +0 -0
- data/static/img/github-sign-up.png +0 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +33 -0
- data/test/sendgrid/helpers/mail/test_category.rb +0 -2
- data/test/sendgrid/helpers/mail/test_data_residency.rb +44 -0
- data/test/sendgrid/helpers/mail/test_email.rb +17 -10
- data/test/sendgrid/helpers/mail/test_mail.rb +126 -119
- data/test/sendgrid/helpers/mail/test_personalizations.rb +145 -92
- data/test/sendgrid/permissions/test_scopes.rb +36 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +1961 -1979
- data/twilio_sendgrid_logo.png +0 -0
- data/use-cases/README.md +17 -0
- data/use-cases/domain-authentication.md +5 -0
- data/use-cases/email-statistics.md +52 -0
- data/use-cases/legacy-templates.md +98 -0
- data/use-cases/personalizations.md +34 -0
- data/use-cases/sms.md +39 -0
- data/use-cases/transactional-templates.md +111 -0
- data/use-cases/twilio-email.md +13 -0
- data/use-cases/twilio-setup.md +54 -0
- metadata +99 -45
- data/.codeclimate.yml +0 -21
- data/.github/ISSUE_TEMPLATE +0 -17
- data/.github/PULL_REQUEST_TEMPLATE +0 -24
- data/.travis.yml +0 -29
- data/LICENSE.txt +0 -22
- data/USE_CASES.md +0 -147
- data/docker/Dockerfile +0 -12
- data/docker/README.md +0 -30
- data/lib/sendgrid/client.rb +0 -35
- data/test/prism.sh +0 -42
|
@@ -3,23 +3,23 @@ require 'spec_helper'
|
|
|
3
3
|
describe SendGrid::Metrics do
|
|
4
4
|
let(:params) do
|
|
5
5
|
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
'date' => '2017-10-01',
|
|
7
|
+
'blocks' => 101,
|
|
8
|
+
'bounce_drops' => 102,
|
|
9
|
+
'bounces' => 103,
|
|
10
|
+
'clicks' => 104,
|
|
11
|
+
'deferred' => 105,
|
|
12
|
+
'delivered' => 106,
|
|
13
|
+
'invalid_emails' => 107,
|
|
14
|
+
'opens' => 108,
|
|
15
|
+
'processed' => 109,
|
|
16
|
+
'requests' => 110,
|
|
17
|
+
'spam_report_drops' => 111,
|
|
18
|
+
'spam_reports' => 112,
|
|
19
|
+
'unique_clicks' => 113,
|
|
20
|
+
'unique_opens' => 114,
|
|
21
|
+
'unsubscribe_drops' => 115,
|
|
22
|
+
'unsubscribes' => 116
|
|
23
23
|
}
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -33,14 +33,13 @@ describe SendGrid::Metrics do
|
|
|
33
33
|
expect(subject.date).to be_a Date
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
%w
|
|
36
|
+
%w[
|
|
37
37
|
blocks bounce_drops bounces clicks deferred delivered invalid_emails
|
|
38
38
|
opens processed requests spam_report_drops spam_reports unique_clicks
|
|
39
39
|
unique_opens unsubscribe_drops unsubscribes
|
|
40
|
-
|
|
40
|
+
].each do |attribute|
|
|
41
41
|
it "responds to #{attribute}" do
|
|
42
42
|
expect(subject).to respond_to(attribute.to_sym)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
-
|
|
46
45
|
end
|
|
@@ -3,28 +3,27 @@ require 'spec_helper'
|
|
|
3
3
|
describe SendGrid::StatsResponse do
|
|
4
4
|
let(:params) do
|
|
5
5
|
[{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{
|
|
6
|
+
'date' => '2017-10-01',
|
|
7
|
+
'stats' => [
|
|
8
|
+
{ 'metrics' =>
|
|
9
9
|
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
10
|
+
'blocks' => 101,
|
|
11
|
+
'bounce_drops' => 102,
|
|
12
|
+
'bounces' => 103,
|
|
13
|
+
'clicks' => 104,
|
|
14
|
+
'deferred' => 105,
|
|
15
|
+
'delivered' => 106,
|
|
16
|
+
'invalid_emails' => 107,
|
|
17
|
+
'opens' => 108,
|
|
18
|
+
'processed' => 109,
|
|
19
|
+
'requests' => 110,
|
|
20
|
+
'spam_report_drops' => 111,
|
|
21
|
+
'spam_reports' => 112,
|
|
22
|
+
'unique_clicks' => 113,
|
|
23
|
+
'unique_opens' => 114,
|
|
24
|
+
'unsubscribe_drops' => 115,
|
|
25
|
+
'unsubscribes' => 116
|
|
26
|
+
} }
|
|
28
27
|
]
|
|
29
28
|
}]
|
|
30
29
|
end
|
|
@@ -51,9 +50,9 @@ describe SendGrid::StatsResponse do
|
|
|
51
50
|
context 'errors' do
|
|
52
51
|
let(:error_params) do
|
|
53
52
|
{
|
|
54
|
-
|
|
53
|
+
'errors' => [
|
|
55
54
|
{
|
|
56
|
-
|
|
55
|
+
'message' => 'end_date should be a YYYY-MM-DD formatted date'
|
|
57
56
|
}
|
|
58
57
|
]
|
|
59
58
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::API do
|
|
4
|
+
describe '.new' do
|
|
5
|
+
it 'initializes correctly' do
|
|
6
|
+
mail_client = SendGrid::API.new(api_key: 'fake_key')
|
|
7
|
+
expect(mail_client.request_headers['Authorization']).to eq('Bearer fake_key')
|
|
8
|
+
expect(mail_client.host).to eq('https://api.sendgrid.com')
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TwilioEmail::API do
|
|
4
|
+
describe '.new' do
|
|
5
|
+
it 'initializes correctly' do
|
|
6
|
+
mail_client = TwilioEmail::API.new(username: 'username', password: 'password')
|
|
7
|
+
expect(mail_client.request_headers['Authorization']).to eq('Basic dXNlcm5hbWU6cGFzc3dvcmQ=')
|
|
8
|
+
expect(mail_client.host).to eq('https://email.twilio.com')
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'simplecov'
|
|
2
|
+
SimpleCov.start
|
|
1
3
|
require 'rubygems'
|
|
2
4
|
require 'bundler/setup'
|
|
3
5
|
require 'pry'
|
|
@@ -7,4 +9,4 @@ RSpec.configure do |config|
|
|
|
7
9
|
Dir["#{File.dirname(__FILE__)}/../lib/sendgrid-ruby.rb"].sort.each { |ext| require ext }
|
|
8
10
|
|
|
9
11
|
config.color = true
|
|
10
|
-
end
|
|
12
|
+
end
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require_relative "../../../../lib/sendgrid/helpers/mail/attachment"
|
|
2
|
+
include SendGrid
|
|
3
|
+
require "json"
|
|
4
|
+
require "minitest/autorun"
|
|
5
|
+
|
|
6
|
+
class TestAttachment < Minitest::Test
|
|
7
|
+
SAMPLE_INPUT = "Es blüht so grün wie Blüten blüh'n im Frühling
|
|
8
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
9
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
10
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
11
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
12
|
+
".force_encoding('UTF-8').encode
|
|
13
|
+
|
|
14
|
+
def setup; end
|
|
15
|
+
|
|
16
|
+
def test_io_enocding
|
|
17
|
+
attachment = Attachment.new
|
|
18
|
+
attachment.content = StringIO.new(SAMPLE_INPUT)
|
|
19
|
+
|
|
20
|
+
expected = {
|
|
21
|
+
"content" => "RXMgYmzDvGh0IHNvIGdyw7xuIHdpZSBCbMO8dGVuIGJsw7xoJ24gaW0gRnLD\nvGhsaW5nCkVzIGJsw7xodCBzbyBncsO8biB3aWUgQmzDvHRlbiBibMO8aCdu\nIGltIEZyw7xobGluZwpFcyBibMO8aHQgc28gZ3LDvG4gd2llIEJsw7x0ZW4g\nYmzDvGgnbiBpbSBGcsO8aGxpbmcKRXMgYmzDvGh0IHNvIGdyw7xuIHdpZSBC\nbMO8dGVuIGJsw7xoJ24gaW0gRnLDvGhsaW5nCkVzIGJsw7xodCBzbyBncsO8\nbiB3aWUgQmzDvHRlbiBibMO8aCduIGltIEZyw7xobGluZwo=\n"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
json = attachment.to_json
|
|
25
|
+
|
|
26
|
+
# Double check that the decoded json matches original input.
|
|
27
|
+
decoded = Base64.decode64(json["content"]).force_encoding('UTF-8').encode
|
|
28
|
+
|
|
29
|
+
assert_equal(decoded, SAMPLE_INPUT)
|
|
30
|
+
|
|
31
|
+
assert_equal(json, expected)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -2,7 +2,6 @@ require_relative '../../../../lib/sendgrid/helpers/mail/mail'
|
|
|
2
2
|
require 'minitest/autorun'
|
|
3
3
|
|
|
4
4
|
class TestCategory < Minitest::Test
|
|
5
|
-
|
|
6
5
|
include SendGrid
|
|
7
6
|
|
|
8
7
|
def setup
|
|
@@ -23,5 +22,4 @@ class TestCategory < Minitest::Test
|
|
|
23
22
|
}
|
|
24
23
|
assert_equal @category.to_json, expected_json
|
|
25
24
|
end
|
|
26
|
-
|
|
27
25
|
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require_relative '../../../../lib/sendgrid-ruby'
|
|
2
|
+
require 'minitest/autorun'
|
|
3
|
+
|
|
4
|
+
class TestDataResidency < Minitest::Test
|
|
5
|
+
include SendGrid
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@global_email = 'https://api.sendgrid.com'
|
|
9
|
+
@eu_email = 'https://api.eu.sendgrid.com'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_with_global_data_residency
|
|
13
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
14
|
+
sg.sendgrid_data_residency(region: 'global')
|
|
15
|
+
assert_equal @global_email, sg.host
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_with_global_eu_residency
|
|
19
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
20
|
+
sg.sendgrid_data_residency(region: 'eu')
|
|
21
|
+
assert_equal @eu_email, sg.host
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_with_global_nil_residency
|
|
25
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
26
|
+
assert_raises(ArgumentError) do
|
|
27
|
+
sg.sendgrid_data_residency(region: nil)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_with_global_invalid_residency
|
|
32
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
33
|
+
assert_raises(ArgumentError) do
|
|
34
|
+
sg.sendgrid_data_residency(region: "abc")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_with_global_empty_residency
|
|
39
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
40
|
+
assert_raises(ArgumentError) do
|
|
41
|
+
sg.sendgrid_data_residency(region: "")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -2,33 +2,40 @@ require_relative '../../../../lib/sendgrid/helpers/mail/email'
|
|
|
2
2
|
require 'minitest/autorun'
|
|
3
3
|
|
|
4
4
|
class TestEmail < Minitest::Test
|
|
5
|
-
|
|
6
5
|
include SendGrid
|
|
7
6
|
|
|
8
7
|
def test_split_email_full_email
|
|
9
|
-
@email = Email.new(email:
|
|
8
|
+
@email = Email.new(email: 'Example User <test1@example.com>')
|
|
10
9
|
expected_json = {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
'email' => 'test1@example.com',
|
|
11
|
+
'name' => 'Example User'
|
|
13
12
|
}
|
|
14
13
|
assert_equal @email.to_json, expected_json
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def test_split_email_only_email
|
|
18
|
-
@email = Email.new(email:
|
|
17
|
+
@email = Email.new(email: 'test1@example.com')
|
|
19
18
|
expected_json = {
|
|
20
|
-
|
|
19
|
+
'email' => 'test1@example.com'
|
|
21
20
|
}
|
|
22
21
|
assert_equal @email.to_json, expected_json
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
def test_split_email_name_and_email
|
|
26
|
-
@email = Email.new(name:
|
|
25
|
+
@email = Email.new(name: 'Example User', email: 'test1@example.com')
|
|
27
26
|
expected_json = {
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
'email' => 'test1@example.com',
|
|
28
|
+
'name' => 'Example User'
|
|
30
29
|
}
|
|
31
30
|
assert_equal @email.to_json, expected_json
|
|
32
31
|
end
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
def test_mandatory_email_missing
|
|
34
|
+
assert_raises(ArgumentError) { Email.new(email: nil) }
|
|
35
|
+
assert_raises(ArgumentError) { Email.new(email: "") }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_invalid_email
|
|
39
|
+
assert_raises(ArgumentError) { Email.new(email: "some-invalid-string") }
|
|
40
|
+
end
|
|
41
|
+
end
|