sendgrid-ruby 5.3.0 → 6.7.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -2,160 +2,213 @@ require_relative '../../../../lib/sendgrid/helpers/mail/personalization'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
4
|
class TestPersonalization < Minitest::Test
|
5
|
-
|
6
5
|
include SendGrid
|
7
6
|
|
8
7
|
def test_add_to
|
9
|
-
@personalization = Personalization.new
|
8
|
+
@personalization = Personalization.new
|
10
9
|
@personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
10
|
+
@personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User 2'))
|
11
11
|
expected_json = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
'to' => [
|
13
|
+
{
|
14
|
+
'email' => 'test1@example.com',
|
15
|
+
'name' => 'Example User'
|
16
|
+
},
|
17
|
+
{
|
18
|
+
'email' => 'test2@example.com',
|
19
|
+
'name' => 'Example User 2'
|
20
|
+
}
|
21
|
+
]
|
18
22
|
}
|
19
|
-
@personalization.
|
23
|
+
assert_equal @personalization.to_json, expected_json
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_duplicate_add_to
|
27
|
+
@personalization = Personalization.new
|
28
|
+
@personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
29
|
+
@personalization.add_to(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Example User 2'))
|
30
|
+
|
31
|
+
assert_raises(DuplicatePersonalizationError) do
|
32
|
+
@personalization.add_to(Email.new(email: 'test1@example.com', name: 'Duplicate User'))
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_raises(DuplicatePersonalizationError) do
|
36
|
+
@personalization.add_to(Email.new(email: 'TEST1@EXAMPLE.COM', name: 'Duplicate User'))
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_raises(DuplicatePersonalizationError) do
|
40
|
+
@personalization.add_to(Email.new(email: 'test2@example.com', name: 'Duplicate User 2'))
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_raises(DuplicatePersonalizationError) do
|
44
|
+
@personalization.add_to(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Duplicate User 2'))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_add_from
|
49
|
+
@personalization = Personalization.new
|
50
|
+
@personalization.add_from(Email.new(email: 'from1@example.com', name: 'Example Sender'))
|
20
51
|
expected_json = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
},
|
26
|
-
{
|
27
|
-
"email"=>"test2@example.com",
|
28
|
-
"name"=>"Example User 2"
|
29
|
-
}
|
30
|
-
]
|
52
|
+
'from' => {
|
53
|
+
'email' => 'from1@example.com',
|
54
|
+
'name' => 'Example Sender'
|
55
|
+
}
|
31
56
|
}
|
57
|
+
|
32
58
|
assert_equal @personalization.to_json, expected_json
|
33
59
|
end
|
34
60
|
|
35
61
|
def test_add_cc
|
36
|
-
@personalization = Personalization.new
|
62
|
+
@personalization = Personalization.new
|
37
63
|
@personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Example User'))
|
38
|
-
expected_json = {
|
39
|
-
"cc"=>[
|
40
|
-
{
|
41
|
-
"email"=>"test1@example.com",
|
42
|
-
"name"=>"Example User"
|
43
|
-
}
|
44
|
-
]
|
45
|
-
}
|
46
64
|
@personalization.add_cc(Email.new(email: 'test2@example.com', name: 'Example User 2'))
|
47
65
|
expected_json = {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
66
|
+
'cc' => [
|
67
|
+
{
|
68
|
+
'email' => 'test1@example.com',
|
69
|
+
'name' => 'Example User'
|
70
|
+
},
|
71
|
+
{
|
72
|
+
'email' => 'test2@example.com',
|
73
|
+
'name' => 'Example User 2'
|
74
|
+
}
|
75
|
+
]
|
58
76
|
}
|
59
77
|
assert_equal @personalization.to_json, expected_json
|
60
78
|
end
|
61
79
|
|
80
|
+
def test_duplicate_add_cc
|
81
|
+
@personalization = Personalization.new
|
82
|
+
@personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Example User'))
|
83
|
+
@personalization.add_cc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Example User 2'))
|
84
|
+
|
85
|
+
assert_raises(DuplicatePersonalizationError) do
|
86
|
+
@personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Duplicate User'))
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_raises(DuplicatePersonalizationError) do
|
90
|
+
@personalization.add_cc(Email.new(email: 'TEST1@EXAMPLE.COM', name: 'Duplicate User'))
|
91
|
+
end
|
92
|
+
|
93
|
+
assert_raises(DuplicatePersonalizationError) do
|
94
|
+
@personalization.add_cc(Email.new(email: 'test2@example.com', name: 'Duplicate User 2'))
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_raises(DuplicatePersonalizationError) do
|
98
|
+
@personalization.add_cc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Duplicate User 2'))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
62
102
|
def test_add_bcc
|
63
|
-
@personalization = Personalization.new
|
103
|
+
@personalization = Personalization.new
|
64
104
|
@personalization.add_bcc(Email.new(email: 'test1@example.com', name: 'Example User'))
|
65
|
-
expected_json = {
|
66
|
-
"bcc"=>[
|
67
|
-
{
|
68
|
-
"email"=>"test1@example.com",
|
69
|
-
"name"=>"Example User"
|
70
|
-
}
|
71
|
-
]
|
72
|
-
}
|
73
105
|
@personalization.add_bcc(Email.new(email: 'test2@example.com', name: 'Example User 2'))
|
74
106
|
expected_json = {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
107
|
+
'bcc' => [
|
108
|
+
{
|
109
|
+
'email' => 'test1@example.com',
|
110
|
+
'name' => 'Example User'
|
111
|
+
},
|
112
|
+
{
|
113
|
+
'email' => 'test2@example.com',
|
114
|
+
'name' => 'Example User 2'
|
115
|
+
}
|
116
|
+
]
|
85
117
|
}
|
86
118
|
assert_equal @personalization.to_json, expected_json
|
87
119
|
end
|
88
120
|
|
121
|
+
def test_duplicate_add_bcc
|
122
|
+
@personalization = Personalization.new
|
123
|
+
@personalization.add_bcc(Email.new(email: 'test1@example.com', name: 'Example User'))
|
124
|
+
@personalization.add_bcc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Example User 2'))
|
125
|
+
|
126
|
+
assert_raises(DuplicatePersonalizationError) do
|
127
|
+
@personalization.add_bcc(Email.new(email: 'test1@example.com', name: 'Duplicate User'))
|
128
|
+
end
|
129
|
+
|
130
|
+
assert_raises(DuplicatePersonalizationError) do
|
131
|
+
@personalization.add_bcc(Email.new(email: 'TEST1@EXAMPLE.COM', name: 'Duplicate User'))
|
132
|
+
end
|
133
|
+
|
134
|
+
assert_raises(DuplicatePersonalizationError) do
|
135
|
+
@personalization.add_bcc(Email.new(email: 'test2@example.com', name: 'Duplicate User 2'))
|
136
|
+
end
|
137
|
+
|
138
|
+
assert_raises(DuplicatePersonalizationError) do
|
139
|
+
@personalization.add_bcc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Duplicate User 2'))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
89
143
|
def test_add_header
|
90
|
-
@personalization = Personalization.new
|
144
|
+
@personalization = Personalization.new
|
91
145
|
@personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
|
92
146
|
expected_json = {
|
93
|
-
|
94
|
-
|
95
|
-
|
147
|
+
'headers' => {
|
148
|
+
'X-Test' => 'True'
|
149
|
+
}
|
96
150
|
}
|
97
151
|
assert_equal @personalization.to_json, expected_json
|
98
152
|
@personalization.add_header(Header.new(key: 'X-Test 1', value: 'False'))
|
99
153
|
expected_json = {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
154
|
+
'headers' => {
|
155
|
+
'X-Test' => 'True',
|
156
|
+
'X-Test 1' => 'False'
|
157
|
+
}
|
104
158
|
}
|
105
159
|
assert_equal @personalization.to_json, expected_json
|
106
160
|
end
|
107
161
|
|
108
162
|
def test_add_substitution
|
109
|
-
@personalization = Personalization.new
|
163
|
+
@personalization = Personalization.new
|
110
164
|
@personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
|
111
165
|
expected_json = {
|
112
|
-
|
113
|
-
|
114
|
-
|
166
|
+
'substitutions' => {
|
167
|
+
'%name%' => 'Example User'
|
168
|
+
}
|
115
169
|
}
|
116
170
|
assert_equal @personalization.to_json, expected_json
|
117
171
|
@personalization.add_substitution(Substitution.new(key: '%name 1%', value: 'Example User 1'))
|
118
172
|
expected_json = {
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
173
|
+
'substitutions' => {
|
174
|
+
'%name%' => 'Example User',
|
175
|
+
'%name 1%' => 'Example User 1'
|
176
|
+
}
|
123
177
|
}
|
124
178
|
assert_equal @personalization.to_json, expected_json
|
125
179
|
end
|
126
180
|
|
127
181
|
def test_add_custom_arg
|
128
|
-
@personalization = Personalization.new
|
182
|
+
@personalization = Personalization.new
|
129
183
|
@personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
|
130
184
|
expected_json = {
|
131
|
-
|
132
|
-
|
133
|
-
|
185
|
+
'custom_args' => {
|
186
|
+
'user_id' => '343'
|
187
|
+
}
|
134
188
|
}
|
135
189
|
assert_equal @personalization.to_json, expected_json
|
136
190
|
@personalization.add_custom_arg(CustomArg.new(key: 'city', value: 'denver'))
|
137
191
|
expected_json = {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
192
|
+
'custom_args' => {
|
193
|
+
'user_id' => '343',
|
194
|
+
'city' => 'denver'
|
195
|
+
}
|
142
196
|
}
|
143
197
|
assert_equal @personalization.to_json, expected_json
|
144
198
|
end
|
145
199
|
|
146
200
|
def test_add_dynamic_template_data
|
147
|
-
@personalization = Personalization.new
|
148
|
-
@personalization.add_dynamic_template_data(
|
149
|
-
|
150
|
-
|
151
|
-
|
201
|
+
@personalization = Personalization.new
|
202
|
+
@personalization.add_dynamic_template_data(
|
203
|
+
'name' => 'Example User',
|
204
|
+
'city' => 'Denver'
|
205
|
+
)
|
152
206
|
expected_json = {
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
207
|
+
'dynamic_template_data' => {
|
208
|
+
'name' => 'Example User',
|
209
|
+
'city' => 'Denver'
|
210
|
+
}
|
157
211
|
}
|
158
212
|
assert_equal @personalization.to_json, expected_json
|
159
213
|
end
|
160
|
-
|
161
|
-
end
|
214
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative '../../../lib/sendgrid/helpers/permissions/scope'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestCategory < Minitest::Test
|
5
|
+
include SendGrid
|
6
|
+
|
7
|
+
# usecases
|
8
|
+
# 1. test admin scopes
|
9
|
+
# 2. test read only scopes
|
10
|
+
# 3. test read only and full access scopes for a method by hardcoding
|
11
|
+
# 4. test read only and full access scopes by loading scopes.yaml
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@scopes_from_yaml = YAML.load_file("#{File.dirname(__FILE__)}/../../../lib/sendgrid/helpers/permissions/scopes.yml").freeze
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_admin_scopes
|
18
|
+
assert_equal Scope.admin_permissions, @scopes_from_yaml.values.map(&:values).flatten
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_read_only_scopes
|
22
|
+
assert_equal Scope.read_only_permissions, @scopes_from_yaml.map { |_, v| v[:read] }.flatten
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_read_only_and_full_access_for_mail_hardcoded
|
26
|
+
assert_equal Scope.mail_read_only_permissions, ["mail.batch.read"]
|
27
|
+
assert_equal Scope.mail_full_access_permissions, ["mail.send", "mail.batch.create", "mail.batch.delete", "mail.batch.read", "mail.batch.update"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_read_only_and_full_access_from_file
|
31
|
+
@scopes_from_yaml.each_key do |endpoint|
|
32
|
+
assert_equal Scope.send("#{endpoint}_read_only_permissions"), @scopes_from_yaml[endpoint][:read]
|
33
|
+
assert_equal Scope.send("#{endpoint}_full_access_permissions"), @scopes_from_yaml[endpoint].values.flatten
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|