sendgrid-ruby 1.1.6 → 6.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +21 -0
- data/.env_sample +1 -3
- data/.gitignore +1 -0
- data/.travis.yml +28 -17
- data/CHANGELOG.md +231 -1
- data/CODE_OF_CONDUCT.md +73 -0
- data/CONTRIBUTING.md +214 -0
- data/Gemfile +5 -4
- data/ISSUE_TEMPLATE.md +26 -0
- data/LICENSE.md +21 -0
- data/Makefile +7 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +161 -225
- data/Rakefile +9 -2
- data/TROUBLESHOOTING.md +137 -0
- data/UPGRADE.md +5 -0
- data/USAGE.md +5037 -0
- data/USE_CASES.md +377 -0
- data/config.ru +4 -0
- data/docker/Dockerfile +12 -0
- data/docker/README.md +30 -0
- data/examples/accesssettings/accesssettings.rb +83 -0
- data/examples/alerts/alerts.rb +62 -0
- data/examples/apikeys/apikeys.rb +84 -0
- data/examples/asm/asm.rb +173 -0
- data/examples/browsers/browsers.rb +16 -0
- data/examples/campaigns/campaigns.rb +153 -0
- data/examples/categories/categories.rb +36 -0
- data/examples/clients/clients.rb +27 -0
- data/examples/contactdb/contactdb.rb +395 -0
- data/examples/devices/devices.rb +16 -0
- data/examples/geo/geo.rb +16 -0
- data/examples/helpers/mail/example.rb +147 -0
- data/examples/helpers/settings/example.rb +23 -0
- data/examples/helpers/stats/example.rb +42 -0
- data/examples/ips/ips.rb +167 -0
- data/examples/mail/mail.rb +173 -0
- data/examples/mailboxproviders/mailboxproviders.rb +16 -0
- data/examples/mailsettings/mailsettings.rb +219 -0
- data/examples/partnersettings/partnersettings.rb +39 -0
- data/examples/scopes/scopes.rb +61 -0
- data/examples/senderauthentication/senderauthentication.rb +310 -0
- data/examples/senders/senders.rb +98 -0
- data/examples/stats/stats.rb +16 -0
- data/examples/subusers/subusers.rb +169 -0
- data/examples/suppression/suppression.rb +201 -0
- data/examples/templates/templates.rb +129 -0
- data/examples/trackingsettings/trackingsettings.rb +110 -0
- data/examples/user/user.rb +293 -0
- data/gemfiles/Sinatra_1.gemfile +6 -0
- data/gemfiles/Sinatra_2.gemfile +6 -0
- data/lib/sendgrid/client.rb +33 -57
- data/lib/sendgrid/helpers/inbound/README.md +98 -0
- data/lib/sendgrid/helpers/inbound/app.rb +32 -0
- data/lib/sendgrid/helpers/inbound/config.yml +26 -0
- data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
- data/lib/sendgrid/helpers/inbound/send.rb +26 -0
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +14 -0
- data/lib/sendgrid/helpers/mail/asm.rb +33 -0
- data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
- data/lib/sendgrid/helpers/mail/category.rb +20 -0
- data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/content.rb +20 -0
- data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
- data/lib/sendgrid/helpers/mail/email.rb +29 -0
- data/lib/sendgrid/helpers/mail/footer.rb +43 -0
- data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
- data/lib/sendgrid/helpers/mail/header.rb +24 -0
- data/lib/sendgrid/helpers/mail/mail.rb +140 -0
- data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
- data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
- data/lib/sendgrid/helpers/mail/section.rb +24 -0
- data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
- data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
- 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 +14 -0
- data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/settings.rb +28 -0
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
- data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
- data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
- data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
- data/lib/sendgrid/version.rb +1 -1
- data/lib/sendgrid-ruby.rb +27 -6
- data/mail_helper_v3.md +390 -0
- data/sendgrid-ruby.gemspec +13 -17
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
- data/spec/spec_helper.rb +10 -1
- data/test/prism.sh +42 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
- data/test/sendgrid/helpers/mail/test_category.rb +27 -0
- data/test/sendgrid/helpers/mail/test_email.rb +34 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +261 -0
- data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
- data/test/sendgrid/permissions/test_scopes.rb +38 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +2751 -0
- metadata +149 -115
- data/.rspec +0 -2
- data/.rubocop.yml +0 -30
- data/FETCH_HEAD +0 -0
- data/Guardfile +0 -10
- data/LICENSE.txt +0 -22
- data/example.rb +0 -41
- data/lib/sendgrid/exceptions.rb +0 -7
- data/lib/sendgrid/mail.rb +0 -182
- data/lib/sendgrid/recipient.rb +0 -29
- data/lib/sendgrid/response.rb +0 -14
- data/lib/sendgrid/template.rb +0 -26
- data/lib/sendgrid/template_mailer.rb +0 -59
- data/spec/lib/sendgrid/client_spec.rb +0 -87
- data/spec/lib/sendgrid/mail_spec.rb +0 -151
- data/spec/lib/sendgrid/recipient_spec.rb +0 -91
- data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
- data/spec/lib/sendgrid/template_spec.rb +0 -61
- data/spec/lib/sendgrid_spec.rb +0 -7
@@ -0,0 +1,161 @@
|
|
1
|
+
require_relative '../../../../lib/sendgrid/helpers/mail/personalization'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestPersonalization < Minitest::Test
|
5
|
+
|
6
|
+
include SendGrid
|
7
|
+
|
8
|
+
def test_add_to
|
9
|
+
@personalization = Personalization.new()
|
10
|
+
@personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
11
|
+
expected_json = {
|
12
|
+
"to"=>[
|
13
|
+
{
|
14
|
+
"email"=>"test1@example.com",
|
15
|
+
"name"=>"Example User"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
@personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User 2'))
|
20
|
+
expected_json = {
|
21
|
+
"to"=>[
|
22
|
+
{
|
23
|
+
"email"=>"test1@example.com",
|
24
|
+
"name"=>"Example User"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"email"=>"test2@example.com",
|
28
|
+
"name"=>"Example User 2"
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
assert_equal @personalization.to_json, expected_json
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_add_cc
|
36
|
+
@personalization = Personalization.new()
|
37
|
+
@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
|
+
@personalization.add_cc(Email.new(email: 'test2@example.com', name: 'Example User 2'))
|
47
|
+
expected_json = {
|
48
|
+
"cc"=>[
|
49
|
+
{
|
50
|
+
"email"=>"test1@example.com",
|
51
|
+
"name"=>"Example User"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"email"=>"test2@example.com",
|
55
|
+
"name"=>"Example User 2"
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
assert_equal @personalization.to_json, expected_json
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_add_bcc
|
63
|
+
@personalization = Personalization.new()
|
64
|
+
@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
|
+
@personalization.add_bcc(Email.new(email: 'test2@example.com', name: 'Example User 2'))
|
74
|
+
expected_json = {
|
75
|
+
"bcc"=>[
|
76
|
+
{
|
77
|
+
"email"=>"test1@example.com",
|
78
|
+
"name"=>"Example User"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"email"=>"test2@example.com",
|
82
|
+
"name"=>"Example User 2"
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
assert_equal @personalization.to_json, expected_json
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_add_header
|
90
|
+
@personalization = Personalization.new()
|
91
|
+
@personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
|
92
|
+
expected_json = {
|
93
|
+
"headers"=>{
|
94
|
+
"X-Test"=>"True"
|
95
|
+
}
|
96
|
+
}
|
97
|
+
assert_equal @personalization.to_json, expected_json
|
98
|
+
@personalization.add_header(Header.new(key: 'X-Test 1', value: 'False'))
|
99
|
+
expected_json = {
|
100
|
+
"headers"=>{
|
101
|
+
"X-Test"=>"True",
|
102
|
+
"X-Test 1"=>"False"
|
103
|
+
}
|
104
|
+
}
|
105
|
+
assert_equal @personalization.to_json, expected_json
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_add_substitution
|
109
|
+
@personalization = Personalization.new()
|
110
|
+
@personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
|
111
|
+
expected_json = {
|
112
|
+
"substitutions"=>{
|
113
|
+
"%name%"=>"Example User"
|
114
|
+
}
|
115
|
+
}
|
116
|
+
assert_equal @personalization.to_json, expected_json
|
117
|
+
@personalization.add_substitution(Substitution.new(key: '%name 1%', value: 'Example User 1'))
|
118
|
+
expected_json = {
|
119
|
+
"substitutions"=>{
|
120
|
+
"%name%"=>"Example User",
|
121
|
+
"%name 1%"=>"Example User 1"
|
122
|
+
}
|
123
|
+
}
|
124
|
+
assert_equal @personalization.to_json, expected_json
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_add_custom_arg
|
128
|
+
@personalization = Personalization.new()
|
129
|
+
@personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
|
130
|
+
expected_json = {
|
131
|
+
"custom_args"=>{
|
132
|
+
"user_id"=>"343"
|
133
|
+
}
|
134
|
+
}
|
135
|
+
assert_equal @personalization.to_json, expected_json
|
136
|
+
@personalization.add_custom_arg(CustomArg.new(key: 'city', value: 'denver'))
|
137
|
+
expected_json = {
|
138
|
+
"custom_args"=>{
|
139
|
+
"user_id"=>"343",
|
140
|
+
"city"=>"denver"
|
141
|
+
}
|
142
|
+
}
|
143
|
+
assert_equal @personalization.to_json, expected_json
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_add_dynamic_template_data
|
147
|
+
@personalization = Personalization.new()
|
148
|
+
@personalization.add_dynamic_template_data({
|
149
|
+
"name"=>"Example User",
|
150
|
+
"city"=> "Denver"
|
151
|
+
})
|
152
|
+
expected_json = {
|
153
|
+
"dynamic_template_data"=>{
|
154
|
+
"name"=>"Example User",
|
155
|
+
"city"=>"Denver"
|
156
|
+
}
|
157
|
+
}
|
158
|
+
assert_equal @personalization.to_json, expected_json
|
159
|
+
end
|
160
|
+
|
161
|
+
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
|