sendgrid-ruby 5.3.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE +3 -1
- data/CHANGELOG.md +25 -0
- data/CODE_OF_CONDUCT.md +11 -11
- data/CONTRIBUTING.md +17 -22
- data/LICENSE.txt +1 -1
- data/README.md +25 -12
- data/Rakefile +1 -1
- data/TROUBLESHOOTING.md +21 -15
- data/UPGRADE.md +5 -0
- data/USAGE.md +1103 -1101
- data/USE_CASES.md +248 -18
- data/examples/helpers/mail/example.rb +7 -7
- data/examples/ips/ips.rb +13 -0
- data/examples/mail/mail.rb +2 -2
- data/examples/scopes/scopes.rb +49 -3
- data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +27 -27
- data/examples/suppression/suppression.rb +10 -10
- data/lib/sendgrid-ruby.rb +2 -0
- data/lib/sendgrid/client.rb +12 -9
- data/lib/sendgrid/helpers/inbound/README.md +22 -5
- data/lib/sendgrid/helpers/inbound/app.rb +13 -1
- data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
- 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 +2 -2
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +1 -1
- data/lib/sendgrid/helpers/mail/attachment.rb +24 -1
- data/lib/sendgrid/helpers/mail/category.rb +0 -8
- data/lib/sendgrid/helpers/mail/content.rb +3 -16
- data/lib/sendgrid/helpers/mail/email.rb +3 -16
- data/lib/sendgrid/helpers/mail/mail.rb +8 -40
- 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 +1 -1
- data/lib/sendgrid/helpers/stats/stats_response.rb +1 -1
- data/lib/sendgrid/version.rb +1 -1
- data/mail_helper_v3.md +9 -9
- data/sendgrid-ruby.gemspec +3 -3
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +29 -21
- data/test/sendgrid/permissions/test_scopes.rb +38 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +15 -7
- metadata +17 -6
@@ -1,4 +1,4 @@
|
|
1
|
-
**This module allows you to quickly and easily build a Settings object for retrieving or updating
|
1
|
+
**This module allows you to quickly and easily build a Settings object for retrieving or updating your Twilio SendGrid Settings.**
|
2
2
|
|
3
3
|
# Quick Start
|
4
4
|
|
data/lib/sendgrid/version.rb
CHANGED
data/mail_helper_v3.md
CHANGED
@@ -13,7 +13,7 @@ require 'sendgrid-ruby'
|
|
13
13
|
|
14
14
|
from = SendGrid::Email.new('test@example.com', 'Example User')
|
15
15
|
to = SendGrid::Email.new('test@example.com', 'Example User')
|
16
|
-
subject = 'Sending with SendGrid is Fun'
|
16
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
17
17
|
plain_text_content = 'and easy to do anywhere, even with Ruby'
|
18
18
|
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
|
19
19
|
msg = SendGrid::Mail.create(from: from,
|
@@ -48,7 +48,7 @@ tos = [
|
|
48
48
|
SendGrid::Email.new('test2@example.com', 'Example User2'),
|
49
49
|
SendGrid::Email.new('test3@example.com', 'Example User3')
|
50
50
|
];
|
51
|
-
subject = 'Sending with SendGrid is Fun'
|
51
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
52
52
|
plain_text_content = 'and easy to do anywhere, even with Ruby'
|
53
53
|
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
|
54
54
|
msg = SendGrid::Mail.create(from: from,
|
@@ -84,9 +84,9 @@ tos = [
|
|
84
84
|
SendGrid::Email.new('test3@example.com', 'Example User3')
|
85
85
|
];
|
86
86
|
subjects = [
|
87
|
-
'Sending with SendGrid is Fun',
|
88
|
-
'Sending with SendGrid is Super Fun',
|
89
|
-
'Sending with SendGrid is Super Duper Fun'
|
87
|
+
'Sending with Twilio SendGrid is Fun',
|
88
|
+
'Sending with Twilio SendGrid is Super Fun',
|
89
|
+
'Sending with Twilio SendGrid is Super Duper Fun'
|
90
90
|
];
|
91
91
|
plain_text_content = 'and easy to do anywhere, even with Ruby'
|
92
92
|
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
|
@@ -126,7 +126,7 @@ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
126
126
|
|
127
127
|
from = SendGrid::Email.new('test@example.com', 'Example User')
|
128
128
|
to = SendGrid::Email.new('test@example.com', 'Example User')
|
129
|
-
subject = 'Sending with SendGrid is Fun'
|
129
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
130
130
|
plain_text_content = 'and easy to do anywhere, even with Ruby'
|
131
131
|
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
|
132
132
|
msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)
|
@@ -237,7 +237,7 @@ msg.set_subject('this subject overrides the Global Subject on the second Persona
|
|
237
237
|
|
238
238
|
msg.set_from(SendGrid::Email.new('test0@example.com', 'Example User0'))
|
239
239
|
|
240
|
-
msg.set_global_subject('Sending with SendGrid is Fun');
|
240
|
+
msg.set_global_subject('Sending with Twilio SendGrid is Fun');
|
241
241
|
|
242
242
|
msg.add_content(MimeType::Text, 'and easy to do anywhere, even with Ruby')
|
243
243
|
msg.add_content(MimeType::Html, '<strong>and easy to do anywhere, even with Ruby</strong>')
|
@@ -302,7 +302,7 @@ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
302
302
|
|
303
303
|
from = SendGrid::Email.new('test@example.com', 'Example User')
|
304
304
|
to = SendGrid::Email.new('test@example.com', 'Example User')
|
305
|
-
subject = 'Sending with SendGrid is Fun'
|
305
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
306
306
|
plain_text_content = 'and easy to do anywhere, even with Ruby'
|
307
307
|
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
|
308
308
|
msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)
|
@@ -367,7 +367,7 @@ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
367
367
|
|
368
368
|
from = SendGrid::Email.new('test@example.com', 'Example User')
|
369
369
|
to = SendGrid::Email.new('test@example.com', 'Example User')
|
370
|
-
subject = 'Sending with SendGrid is Fun'
|
370
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
371
371
|
plain_text_content = 'and easy to do anywhere, even with Ruby'
|
372
372
|
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
|
373
373
|
msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)
|
data/sendgrid-ruby.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SendGrid::VERSION
|
9
9
|
spec.authors = ['Elmer Thomas', 'Robin Johnson', 'Eddie Zaneski']
|
10
10
|
spec.email = 'dx@sendgrid.com'
|
11
|
-
spec.summary = 'Official SendGrid Gem'
|
12
|
-
spec.description = 'Official SendGrid Gem to Interact with SendGrids API in native Ruby'
|
11
|
+
spec.summary = 'Official Twilio SendGrid Gem'
|
12
|
+
spec.description = 'Official Twilio SendGrid Gem to Interact with Twilio SendGrids API in native Ruby'
|
13
13
|
spec.homepage = 'http://github.com/sendgrid/sendgrid-ruby'
|
14
14
|
|
15
15
|
spec.required_ruby_version = '>= 2.2'
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(/^(test|spec|features)/)
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
spec.add_dependency 'ruby_http_client', '~> 3.3.0'
|
23
|
-
spec.
|
23
|
+
spec.add_development_dependency 'sinatra', '>= 1.4.7', '< 3'
|
24
24
|
spec.add_development_dependency 'rake', '~> 0'
|
25
25
|
spec.add_development_dependency 'rspec'
|
26
26
|
spec.add_development_dependency 'pry'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SendGrid::IpManagement do
|
4
|
+
let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
|
5
|
+
let(:ip_management) { SendGrid::IpManagement.new(sendgrid_client: sendgrid_client) }
|
6
|
+
|
7
|
+
describe '.new' do
|
8
|
+
it 'initializes correctly' do
|
9
|
+
expect(ip_management).to be_a SendGrid::IpManagement
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative "../../../../lib/sendgrid/helpers/mail/attachment"
|
3
|
+
include SendGrid
|
4
|
+
require "json"
|
5
|
+
require "minitest/autorun"
|
6
|
+
|
7
|
+
class TestAttachment < Minitest::Test
|
8
|
+
SAMPLE_INPUT = """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
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
13
|
+
""".force_encoding('UTF-8').encode
|
14
|
+
|
15
|
+
def setup
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_io_enocding
|
19
|
+
attachment = Attachment.new
|
20
|
+
attachment.content = StringIO.new(SAMPLE_INPUT)
|
21
|
+
|
22
|
+
expected = {
|
23
|
+
"content" => "RXMgYmzDvGh0IHNvIGdyw7xuIHdpZSBCbMO8dGVuIGJsw7xoJ24gaW0gRnLD\nvGhsaW5nCkVzIGJsw7xodCBzbyBncsO8biB3aWUgQmzDvHRlbiBibMO8aCdu\nIGltIEZyw7xobGluZwpFcyBibMO8aHQgc28gZ3LDvG4gd2llIEJsw7x0ZW4g\nYmzDvGgnbiBpbSBGcsO8aGxpbmcKRXMgYmzDvGh0IHNvIGdyw7xuIHdpZSBC\nbMO8dGVuIGJsw7xoJ24gaW0gRnLDvGhsaW5nCkVzIGJsw7xodCBzbyBncsO8\nbiB3aWUgQmzDvHRlbiBibMO8aCduIGltIEZyw7xobGluZwo=\n"
|
24
|
+
}
|
25
|
+
|
26
|
+
json = attachment.to_json
|
27
|
+
|
28
|
+
# Double check that the decoded json matches original input.
|
29
|
+
decoded = Base64.decode64(json["content"]).force_encoding('UTF-8').encode
|
30
|
+
|
31
|
+
assert_equal(decoded, SAMPLE_INPUT)
|
32
|
+
|
33
|
+
assert_equal(json, expected)
|
34
|
+
end
|
35
|
+
end
|
@@ -11,17 +11,17 @@ class TestMail < Minitest::Test
|
|
11
11
|
def test_hello_world
|
12
12
|
from = Email.new(email: 'test@example.com')
|
13
13
|
to = Email.new(email: 'test@example.com')
|
14
|
-
subject = 'Sending with SendGrid is Fun'
|
14
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
15
15
|
content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
|
16
|
-
mail = Mail.new(from, subject, to, content)
|
16
|
+
mail = SendGrid::Mail.new(from, subject, to, content)
|
17
17
|
|
18
|
-
assert_equal(mail.to_json, JSON.parse('{"from":{"email":"test@example.com"}, "subject":"Sending with SendGrid is Fun", "personalizations":[{"to":[{"email":"test@example.com"}]}], "content":[{"type":"text/plain", "value":"and easy to do anywhere, even with Ruby"}]}'))
|
18
|
+
assert_equal(mail.to_json, JSON.parse('{"from":{"email":"test@example.com"}, "subject":"Sending with Twilio SendGrid is Fun", "personalizations":[{"to":[{"email":"test@example.com"}]}], "content":[{"type":"text/plain", "value":"and easy to do anywhere, even with Ruby"}]}'))
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_kitchen_sink
|
22
|
-
mail = Mail.new
|
22
|
+
mail = SendGrid::Mail.new
|
23
23
|
mail.from = Email.new(email: "test@example.com")
|
24
|
-
mail.subject = "Hello World from the SendGrid Ruby Library"
|
24
|
+
mail.subject = "Hello World from the Twilio SendGrid Ruby Library"
|
25
25
|
personalization = Personalization.new
|
26
26
|
personalization.add_to(Email.new(email: "test@example.com", name: "Example User"))
|
27
27
|
personalization.add_to(Email.new(email: "test@example.com", name: "Example User"))
|
@@ -29,7 +29,7 @@ class TestMail < Minitest::Test
|
|
29
29
|
personalization.add_cc(Email.new(email: "test@example.com", name: "Example User"))
|
30
30
|
personalization.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
|
31
31
|
personalization.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
|
32
|
-
personalization.subject = "Hello World from the Personalized SendGrid
|
32
|
+
personalization.subject = "Hello World from the Personalized Twilio SendGrid Ruby Library"
|
33
33
|
personalization.add_header(Header.new(key: "X-Test", value: "True"))
|
34
34
|
personalization.add_header(Header.new(key: "X-Mock", value: "False"))
|
35
35
|
personalization.add_substitution(Substitution.new(key: "%name%", value: "Example User"))
|
@@ -46,7 +46,7 @@ class TestMail < Minitest::Test
|
|
46
46
|
personalization2.add_cc(Email.new(email: "test@example.com", name: "Example User"))
|
47
47
|
personalization2.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
|
48
48
|
personalization2.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
|
49
|
-
personalization2.subject = "Hello World from the Personalized SendGrid
|
49
|
+
personalization2.subject = "Hello World from the Personalized Twilio SendGrid Ruby Library"
|
50
50
|
personalization2.add_header(Header.new(key: "X-Test", value: "True"))
|
51
51
|
personalization2.add_header(Header.new(key: "X-Mock", value: "False"))
|
52
52
|
personalization2.add_substitution(Substitution.new(key: "%name%", value: "Example User"))
|
@@ -115,43 +115,43 @@ class TestMail < Minitest::Test
|
|
115
115
|
|
116
116
|
mail.reply_to = Email.new(email: "test@example.com")
|
117
117
|
|
118
|
-
assert_equal(mail.to_json, JSON.parse('{"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","content_id":"Balance Sheet","disposition":"attachment","filename":"balance_001.pdf","type":"application/pdf"},{"content":"BwdW","content_id":"Banner","disposition":"inline","filename":"banner.png","type":"image/png"}],"batch_id":"sendgrid_batch_id","categories":["May","2016"],"content":[{"type":"text/plain","value":"some text here"},{"type":"text/html","value":"<html><body>some text here</body></html>"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"test@example.com"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"test@example.com","enable":true},"bypass_list_management":{"enable":true},"footer":{"enable":true,"html":"<html><body>Footer Text</body></html>","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"cc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized SendGrid
|
118
|
+
assert_equal(mail.to_json, JSON.parse('{"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","content_id":"Balance Sheet","disposition":"attachment","filename":"balance_001.pdf","type":"application/pdf"},{"content":"BwdW","content_id":"Banner","disposition":"inline","filename":"banner.png","type":"image/png"}],"batch_id":"sendgrid_batch_id","categories":["May","2016"],"content":[{"type":"text/plain","value":"some text here"},{"type":"text/html","value":"<html><body>some text here</body></html>"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"test@example.com"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"test@example.com","enable":true},"bypass_list_management":{"enable":true},"footer":{"enable":true,"html":"<html><body>Footer Text</body></html>","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"cc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}]},{"bcc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"cc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}]}],"reply_to":{"email":"test@example.com"},"sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"send_at":1443636842,"subject":"Hello World from the Twilio SendGrid Ruby Library","template_id":"13b8f94f-bcae-4ec6-b752-70d6cb59f932","tracking_settings":{"click_tracking":{"enable":false,"enable_text":false},"ganalytics":{"enable":true,"utm_campaign":"some campaign","utm_content":"some content","utm_medium":"some medium","utm_source":"some source","utm_term":"some term"},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"html":"html to insert into the text/html portion of the message","substitution_tag":"Optional tag to replace with the open image in the body of the message","text":"text to insert into the text/plain portion of the message"}}}'))
|
119
119
|
end
|
120
120
|
|
121
121
|
def test_that_personalizations_is_empty_initially
|
122
|
-
mail = Mail.new
|
122
|
+
mail = SendGrid::Mail.new
|
123
123
|
assert_equal([], mail.personalizations)
|
124
124
|
end
|
125
125
|
|
126
126
|
def test_that_contents_is_empty_initially
|
127
|
-
mail = Mail.new
|
127
|
+
mail = SendGrid::Mail.new
|
128
128
|
assert_equal([], mail.contents)
|
129
129
|
end
|
130
130
|
|
131
131
|
def test_that_attachments_is_empty_initially
|
132
|
-
mail = Mail.new
|
132
|
+
mail = SendGrid::Mail.new
|
133
133
|
assert_equal([], mail.attachments)
|
134
134
|
end
|
135
135
|
|
136
136
|
def test_that_categories_is_empty_initially
|
137
|
-
mail = Mail.new
|
137
|
+
mail = SendGrid::Mail.new
|
138
138
|
assert_equal([], mail.categories)
|
139
139
|
end
|
140
140
|
|
141
141
|
def test_add_personalization
|
142
|
-
mail = Mail.new
|
142
|
+
mail = SendGrid::Mail.new
|
143
143
|
mail.add_personalization('foo')
|
144
144
|
assert_equal(['foo'.to_json], mail.personalizations)
|
145
145
|
end
|
146
146
|
|
147
147
|
def test_add_content
|
148
|
-
mail = Mail.new
|
148
|
+
mail = SendGrid::Mail.new
|
149
149
|
mail.add_content('foo')
|
150
150
|
assert_equal(['foo'.to_json], mail.contents)
|
151
151
|
end
|
152
152
|
|
153
153
|
def test_add_section
|
154
|
-
mail = Mail.new
|
154
|
+
mail = SendGrid::Mail.new
|
155
155
|
mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1'))
|
156
156
|
expected_json = {
|
157
157
|
"sections"=>{
|
@@ -170,7 +170,7 @@ class TestMail < Minitest::Test
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_add_header
|
173
|
-
mail = Mail.new
|
173
|
+
mail = SendGrid::Mail.new
|
174
174
|
mail.add_header(Header.new(key: 'X-Test3', value: 'test3'))
|
175
175
|
expected_json = {
|
176
176
|
"headers"=>{
|
@@ -189,7 +189,7 @@ class TestMail < Minitest::Test
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def test_add_custom_arg
|
192
|
-
mail = Mail.new
|
192
|
+
mail = SendGrid::Mail.new
|
193
193
|
mail.add_custom_arg(CustomArg.new(key: 'campaign 1', value: 'welcome 1'))
|
194
194
|
expected_json = {
|
195
195
|
"custom_args"=>{
|
@@ -223,20 +223,20 @@ class TestMail < Minitest::Test
|
|
223
223
|
end
|
224
224
|
|
225
225
|
def test_add_attachment
|
226
|
-
mail = Mail.new
|
226
|
+
mail = SendGrid::Mail.new
|
227
227
|
mail.add_attachment('foo')
|
228
228
|
assert_equal(['foo'.to_json], mail.attachments)
|
229
229
|
end
|
230
230
|
|
231
231
|
def test_add_valid_category
|
232
|
-
mail = Mail.new
|
232
|
+
mail = SendGrid::Mail.new
|
233
233
|
category = Category.new(name: 'foo')
|
234
234
|
mail.add_category(category)
|
235
235
|
assert_equal(['foo'], mail.categories)
|
236
236
|
end
|
237
237
|
|
238
238
|
def test_add_more_than_1_valid_category
|
239
|
-
mail = Mail.new
|
239
|
+
mail = SendGrid::Mail.new
|
240
240
|
category_1 = Category.new(name: 'foo')
|
241
241
|
category_2 = Category.new(name: 'bar')
|
242
242
|
mail.add_category(category_1)
|
@@ -245,9 +245,17 @@ class TestMail < Minitest::Test
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def test_add_invalid_category
|
248
|
-
mail = Mail.new
|
248
|
+
mail = SendGrid::Mail.new
|
249
249
|
assert_raises(NoMethodError) do
|
250
250
|
mail.add_category('foo')
|
251
251
|
end
|
252
252
|
end
|
253
|
+
|
254
|
+
def test_check_for_secrets
|
255
|
+
mail = Mail.new
|
256
|
+
mail.add_content(Content.new(type: 'text/plain', value: 'Sensitive information: SG.a123b456'))
|
257
|
+
assert_raises(SecurityError) do
|
258
|
+
mail.check_for_secrets([/SG.[a-zA-Z0-9_-]*/])
|
259
|
+
end
|
260
|
+
end
|
253
261
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../../../lib/sendgrid/helpers/permissions/scope'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestCategory < Minitest::Test
|
5
|
+
|
6
|
+
include SendGrid
|
7
|
+
|
8
|
+
# usecases
|
9
|
+
# 1. test admin scopes
|
10
|
+
# 2. test read only scopes
|
11
|
+
# 3. test read only and full access scopes for a method by hardcoding
|
12
|
+
# 4. test read only and full access scopes by loading scopes.yaml
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@scopes_from_yaml = YAML.load_file(File.dirname(__FILE__) + '/../../../lib/sendgrid/helpers/permissions/scopes.yml').freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_admin_scopes
|
19
|
+
assert_equal Scope.admin_permissions, @scopes_from_yaml.values.map(&:values).flatten
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_read_only_scopes
|
23
|
+
assert_equal Scope.read_only_permissions, @scopes_from_yaml.map { |_, v| v[:read] }.flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_read_only_and_full_access_for_mail_hardcoded
|
27
|
+
assert_equal Scope.mail_read_only_permissions, ["mail.batch.read"]
|
28
|
+
assert_equal Scope.mail_full_access_permissions, ["mail.send", "mail.batch.create", "mail.batch.delete", "mail.batch.read", "mail.batch.update"]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_read_only_and_full_access_from_file
|
32
|
+
@scopes_from_yaml.each_key do |endpoint|
|
33
|
+
assert_equal Scope.send("#{endpoint}_read_only_permissions"), @scopes_from_yaml[endpoint][:read]
|
34
|
+
assert_equal Scope.send("#{endpoint}_full_access_permissions"), @scopes_from_yaml[endpoint].values.flatten
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -41,7 +41,8 @@ class TestAPI < MiniTest::Test
|
|
41
41
|
"X-Test": "test"
|
42
42
|
}
|
43
43
|
')
|
44
|
-
|
44
|
+
subuser = 'test_user'
|
45
|
+
sg = SendGrid::API.new(api_key: "SENDGRID_API_KEY", host: "https://api.test.com", request_headers: headers, version: "v3", impersonate_subuser: subuser)
|
45
46
|
|
46
47
|
assert_equal("https://api.test.com", sg.host)
|
47
48
|
user_agent = "sendgrid/#{SendGrid::VERSION};ruby"
|
@@ -50,15 +51,22 @@ class TestAPI < MiniTest::Test
|
|
50
51
|
"Authorization": "Bearer SENDGRID_API_KEY",
|
51
52
|
"Accept": "application/json",
|
52
53
|
"X-Test": "test",
|
53
|
-
"User-agent": "' + user_agent + '"
|
54
|
+
"User-agent": "' + user_agent + '",
|
55
|
+
"On-Behalf-Of": "' + subuser + '"
|
54
56
|
}
|
55
57
|
')
|
56
58
|
assert_equal(test_headers, sg.request_headers)
|
57
59
|
assert_equal("v3", sg.version)
|
58
|
-
assert_equal(
|
60
|
+
assert_equal(subuser, sg.impersonate_subuser)
|
61
|
+
assert_equal("6.0.0", SendGrid::VERSION)
|
59
62
|
assert_instance_of(SendGrid::Client, sg.client)
|
60
63
|
end
|
61
64
|
|
65
|
+
def test_init_when_impersonate_subuser_is_not_given
|
66
|
+
sg = SendGrid::API.new(api_key: "SENDGRID_API_KEY", host: "https://api.test.com", version: "v3")
|
67
|
+
refute_includes(sg.request_headers, 'On-Behalf-Of')
|
68
|
+
end
|
69
|
+
|
62
70
|
def test_access_settings_activity_get
|
63
71
|
params = JSON.parse('{"limit": 1}')
|
64
72
|
headers = JSON.parse('{"X-Mock": 200}')
|
@@ -1176,8 +1184,8 @@ class TestAPI < MiniTest::Test
|
|
1176
1184
|
},
|
1177
1185
|
"footer": {
|
1178
1186
|
"enable": true,
|
1179
|
-
"html": "<p>Thanks</br>The SendGrid Team</p>",
|
1180
|
-
"text": "Thanks,/n The SendGrid Team"
|
1187
|
+
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
|
1188
|
+
"text": "Thanks,/n The Twilio SendGrid Team"
|
1181
1189
|
},
|
1182
1190
|
"sandbox_mode": {
|
1183
1191
|
"enable": false
|
@@ -1883,7 +1891,7 @@ class TestAPI < MiniTest::Test
|
|
1883
1891
|
email = "test_url_param"
|
1884
1892
|
headers = JSON.parse('{"X-Mock": 204}')
|
1885
1893
|
|
1886
|
-
response = @sg.client.suppression.
|
1894
|
+
response = @sg.client.suppression.spam_reports._(email).delete(request_headers: headers)
|
1887
1895
|
|
1888
1896
|
self.assert_equal('204', response.status_code)
|
1889
1897
|
end
|
@@ -2678,7 +2686,7 @@ class TestAPI < MiniTest::Test
|
|
2678
2686
|
end
|
2679
2687
|
|
2680
2688
|
def test_docker_exists
|
2681
|
-
assert(File.file?('./
|
2689
|
+
assert(File.file?('./Docker') || File.file?('./docker/Dockerfile'))
|
2682
2690
|
end
|
2683
2691
|
|
2684
2692
|
# def test_docker_compose_exists
|
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:
|
4
|
+
version: 6.0.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:
|
13
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_http_client
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
- - "<"
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '3'
|
39
|
-
type: :
|
39
|
+
type: :development
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
@@ -130,7 +130,8 @@ dependencies:
|
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '5.9'
|
133
|
-
description: Official SendGrid Gem to Interact with SendGrids API in
|
133
|
+
description: Official Twilio SendGrid Gem to Interact with Twilio SendGrids API in
|
134
|
+
native Ruby
|
134
135
|
email: dx@sendgrid.com
|
135
136
|
executables: []
|
136
137
|
extensions: []
|
@@ -150,6 +151,7 @@ files:
|
|
150
151
|
- README.md
|
151
152
|
- Rakefile
|
152
153
|
- TROUBLESHOOTING.md
|
154
|
+
- UPGRADE.md
|
153
155
|
- USAGE.md
|
154
156
|
- USE_CASES.md
|
155
157
|
- config.ru
|
@@ -175,6 +177,7 @@ files:
|
|
175
177
|
- examples/mailsettings/mailsettings.rb
|
176
178
|
- examples/partnersettings/partnersettings.rb
|
177
179
|
- examples/scopes/scopes.rb
|
180
|
+
- examples/senderauthentication/senderauthentication.rb
|
178
181
|
- examples/senders/senders.rb
|
179
182
|
- examples/stats/stats.rb
|
180
183
|
- examples/subusers/subusers.rb
|
@@ -182,7 +185,6 @@ files:
|
|
182
185
|
- examples/templates/templates.rb
|
183
186
|
- examples/trackingsettings/trackingsettings.rb
|
184
187
|
- examples/user/user.rb
|
185
|
-
- examples/whitelabel/whitelabel.rb
|
186
188
|
- gemfiles/Sinatra_1.gemfile
|
187
189
|
- gemfiles/Sinatra_2.gemfile
|
188
190
|
- lib/sendgrid-ruby.rb
|
@@ -195,6 +197,7 @@ files:
|
|
195
197
|
- lib/sendgrid/helpers/inbound/sample_data/raw_data.txt
|
196
198
|
- lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt
|
197
199
|
- lib/sendgrid/helpers/inbound/send.rb
|
200
|
+
- lib/sendgrid/helpers/ip_management/ip_management.rb
|
198
201
|
- lib/sendgrid/helpers/mail/README.md
|
199
202
|
- lib/sendgrid/helpers/mail/asm.rb
|
200
203
|
- lib/sendgrid/helpers/mail/attachment.rb
|
@@ -217,6 +220,8 @@ files:
|
|
217
220
|
- lib/sendgrid/helpers/mail/subscription_tracking.rb
|
218
221
|
- lib/sendgrid/helpers/mail/substitution.rb
|
219
222
|
- lib/sendgrid/helpers/mail/tracking_settings.rb
|
223
|
+
- lib/sendgrid/helpers/permissions/scope.rb
|
224
|
+
- lib/sendgrid/helpers/permissions/scopes.yml
|
220
225
|
- lib/sendgrid/helpers/settings/README.md
|
221
226
|
- lib/sendgrid/helpers/settings/mail_settings_dto.rb
|
222
227
|
- lib/sendgrid/helpers/settings/partner_settings_dto.rb
|
@@ -229,6 +234,7 @@ files:
|
|
229
234
|
- lib/sendgrid/version.rb
|
230
235
|
- mail_helper_v3.md
|
231
236
|
- sendgrid-ruby.gemspec
|
237
|
+
- spec/sendgrid/helpers/ip_management/ip_management_spec.rb
|
232
238
|
- spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb
|
233
239
|
- spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb
|
234
240
|
- spec/sendgrid/helpers/settings/settings_spec.rb
|
@@ -239,10 +245,12 @@ files:
|
|
239
245
|
- spec/sendgrid/helpers/stats/stats_response_spec.rb
|
240
246
|
- spec/spec_helper.rb
|
241
247
|
- test/prism.sh
|
248
|
+
- test/sendgrid/helpers/mail/test_attachment.rb
|
242
249
|
- test/sendgrid/helpers/mail/test_category.rb
|
243
250
|
- test/sendgrid/helpers/mail/test_email.rb
|
244
251
|
- test/sendgrid/helpers/mail/test_mail.rb
|
245
252
|
- test/sendgrid/helpers/mail/test_personalizations.rb
|
253
|
+
- test/sendgrid/permissions/test_scopes.rb
|
246
254
|
- test/sendgrid/test_sendgrid-ruby.rb
|
247
255
|
homepage: http://github.com/sendgrid/sendgrid-ruby
|
248
256
|
licenses:
|
@@ -267,8 +275,9 @@ rubyforge_project:
|
|
267
275
|
rubygems_version: 2.6.10
|
268
276
|
signing_key:
|
269
277
|
specification_version: 4
|
270
|
-
summary: Official SendGrid Gem
|
278
|
+
summary: Official Twilio SendGrid Gem
|
271
279
|
test_files:
|
280
|
+
- spec/sendgrid/helpers/ip_management/ip_management_spec.rb
|
272
281
|
- spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb
|
273
282
|
- spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb
|
274
283
|
- spec/sendgrid/helpers/settings/settings_spec.rb
|
@@ -279,8 +288,10 @@ test_files:
|
|
279
288
|
- spec/sendgrid/helpers/stats/stats_response_spec.rb
|
280
289
|
- spec/spec_helper.rb
|
281
290
|
- test/prism.sh
|
291
|
+
- test/sendgrid/helpers/mail/test_attachment.rb
|
282
292
|
- test/sendgrid/helpers/mail/test_category.rb
|
283
293
|
- test/sendgrid/helpers/mail/test_email.rb
|
284
294
|
- test/sendgrid/helpers/mail/test_mail.rb
|
285
295
|
- test/sendgrid/helpers/mail/test_personalizations.rb
|
296
|
+
- test/sendgrid/permissions/test_scopes.rb
|
286
297
|
- test/sendgrid/test_sendgrid-ruby.rb
|