sendgrid-ruby 5.3.0 → 6.0.4

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.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +22 -20
  3. data/CHANGELOG.md +55 -0
  4. data/CODE_OF_CONDUCT.md +57 -25
  5. data/CONTRIBUTING.md +18 -23
  6. data/ISSUE_TEMPLATE.md +26 -0
  7. data/LICENSE.md +21 -0
  8. data/Makefile +7 -0
  9. data/PULL_REQUEST_TEMPLATE.md +31 -0
  10. data/README.md +26 -13
  11. data/Rakefile +1 -1
  12. data/TROUBLESHOOTING.md +22 -16
  13. data/UPGRADE.md +5 -0
  14. data/USAGE.md +1103 -1101
  15. data/USE_CASES.md +248 -18
  16. data/examples/helpers/mail/example.rb +7 -7
  17. data/examples/ips/ips.rb +13 -0
  18. data/examples/mail/mail.rb +2 -2
  19. data/examples/scopes/scopes.rb +49 -3
  20. data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +27 -27
  21. data/examples/suppression/suppression.rb +10 -10
  22. data/lib/sendgrid/client.rb +12 -9
  23. data/lib/sendgrid/helpers/inbound/README.md +22 -5
  24. data/lib/sendgrid/helpers/inbound/app.rb +13 -1
  25. data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
  26. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +2 -2
  27. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +2 -2
  28. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +2 -2
  29. data/lib/sendgrid/helpers/inbound/send.rb +2 -2
  30. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  31. data/lib/sendgrid/helpers/mail/README.md +1 -1
  32. data/lib/sendgrid/helpers/mail/attachment.rb +24 -1
  33. data/lib/sendgrid/helpers/mail/category.rb +0 -8
  34. data/lib/sendgrid/helpers/mail/content.rb +3 -16
  35. data/lib/sendgrid/helpers/mail/email.rb +3 -16
  36. data/lib/sendgrid/helpers/mail/mail.rb +8 -40
  37. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  38. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  39. data/lib/sendgrid/helpers/settings/README.md +1 -1
  40. data/lib/sendgrid/helpers/stats/stats_response.rb +1 -1
  41. data/lib/sendgrid/version.rb +1 -1
  42. data/lib/sendgrid-ruby.rb +2 -0
  43. data/mail_helper_v3.md +9 -9
  44. data/sendgrid-ruby.gemspec +3 -3
  45. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  46. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  47. data/test/sendgrid/helpers/mail/test_mail.rb +29 -21
  48. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  49. data/test/sendgrid/test_sendgrid-ruby.rb +21 -13
  50. metadata +22 -11
  51. data/.github/ISSUE_TEMPLATE +0 -17
  52. data/.github/PULL_REQUEST_TEMPLATE +0 -24
  53. data/LICENSE.txt +0 -22
@@ -0,0 +1,309 @@
1
+ ---
2
+ :alerts:
3
+ :create:
4
+ - alerts.create
5
+ :delete:
6
+ - alerts.delete
7
+ :read:
8
+ - alerts.read
9
+ :update:
10
+ - alerts.update
11
+ :api_keys:
12
+ :create:
13
+ - api_keys.create
14
+ :delete:
15
+ - api_keys.delete
16
+ :read:
17
+ - api_keys.read
18
+ :update:
19
+ - api_keys.update
20
+ :asm_groups:
21
+ :create:
22
+ - asm.groups.create
23
+ :delete:
24
+ - asm.groups.delete
25
+ :read:
26
+ - asm.groups.read
27
+ :update:
28
+ - asm.groups.update
29
+ :billing:
30
+ :create:
31
+ - billing.create
32
+ :delete:
33
+ - billing.delete
34
+ :read:
35
+ - billing.read
36
+ :update:
37
+ - billing.update
38
+ :categories:
39
+ :create:
40
+ - categories.create
41
+ :delete:
42
+ - categories.delete
43
+ :read:
44
+ - categories.read
45
+ - categories.stats.read
46
+ - categories.stats.sums.read
47
+ :update:
48
+ - categories.update
49
+ :credentials:
50
+ :create:
51
+ - credentials.create
52
+ :delete:
53
+ - credentials.delete
54
+ :read:
55
+ - credentials.read
56
+ :update:
57
+ - credentials.update
58
+ :stats:
59
+ :create: []
60
+ :delete: []
61
+ :read:
62
+ - email_activity.read
63
+ - stats.read
64
+ - stats.global.read
65
+ - browsers.stats.read
66
+ - devices.stats.read
67
+ - geo.stats.read
68
+ - mailbox_providers.stats.read
69
+ - clients.desktop.stats.read
70
+ - clients.phone.stats.read
71
+ - clients.stats.read
72
+ - clients.tablet.stats.read
73
+ - clients.webmail.stats.read
74
+ :update: []
75
+ :ips:
76
+ :create:
77
+ - ips.pools.create
78
+ - ips.pools.ips.create
79
+ - ips.warmup.create
80
+ :delete:
81
+ - ips.pools.delete
82
+ - ips.pools.ips.delete
83
+ - ips.warmup.delete
84
+ :read:
85
+ - ips.assigned.read
86
+ - ips.read
87
+ - ips.pools.read
88
+ - ips.pools.ips.read
89
+ - ips.warmup.read
90
+ :update:
91
+ - ips.pools.update
92
+ - ips.pools.ips.update
93
+ - ips.warmup.update
94
+ :mail_settings:
95
+ :create: []
96
+ :delete: []
97
+ :read:
98
+ - mail_settings.address_whitelist.read
99
+ - mail_settings.bcc.read
100
+ - mail_settings.bounce_purge.read
101
+ - mail_settings.footer.read
102
+ - mail_settings.forward_bounce.read
103
+ - mail_settings.forward_spam.read
104
+ - mail_settings.plain_content.read
105
+ - mail_settings.read
106
+ - mail_settings.spam_check.read
107
+ - mail_settings.template.read
108
+ :update:
109
+ - mail_settings.address_whitelist.update
110
+ - mail_settings.bcc.update
111
+ - mail_settings.bounce_purge.update
112
+ - mail_settings.footer.update
113
+ - mail_settings.forward_bounce.update
114
+ - mail_settings.forward_spam.update
115
+ - mail_settings.plain_content.update
116
+ - mail_settings.spam_check.update
117
+ - mail_settings.template.update
118
+ :mail:
119
+ :create:
120
+ - mail.send
121
+ - mail.batch.create
122
+ :delete:
123
+ - mail.batch.delete
124
+ :read:
125
+ - mail.batch.read
126
+ :update:
127
+ - mail.batch.update
128
+ :marketing_campaigns:
129
+ :create:
130
+ - marketing_campaigns.create
131
+ :delete:
132
+ - marketing_campaigns.delete
133
+ :read:
134
+ - marketing_campaigns.read
135
+ :update:
136
+ - marketing_campaigns.update
137
+ :partner_settings:
138
+ :create: []
139
+ :delete: []
140
+ :read:
141
+ - partner_settings.new_relic.read
142
+ - partner_settings.read
143
+ - partner_settings.sendwithus.read
144
+ :update:
145
+ - partner_settings.new_relic.update
146
+ - partner_settings.sendwithus.update
147
+ :scheduled_sends:
148
+ :create:
149
+ - user.scheduled_sends.create
150
+ :delete:
151
+ - user.scheduled_sends.delete
152
+ :read:
153
+ - user.scheduled_sends.read
154
+ :update:
155
+ - user.scheduled_sends.update
156
+ :subusers:
157
+ :create:
158
+ - subusers.create
159
+ - subusers.credits.create
160
+ - subusers.credits.remaining.create
161
+ - subusers.monitor.create
162
+ :delete:
163
+ - subusers.delete
164
+ - subusers.credits.delete
165
+ - subusers.credits.remaining.delete
166
+ - subusers.monitor.delete
167
+ :read:
168
+ - subusers.read
169
+ - subusers.credits.read
170
+ - subusers.stats.read
171
+ - subusers.credits.remaining.read
172
+ - subusers.monitor.read
173
+ - subusers.reputations.read
174
+ - subusers.stats.monthly.read
175
+ - subusers.stats.sums.read
176
+ - subusers.summary.read
177
+ :update:
178
+ - subusers.update
179
+ - subusers.credits.update
180
+ - subusers.credits.remaining.update
181
+ - subusers.monitor.update
182
+ :suppression:
183
+ :create:
184
+ - suppression.create
185
+ - suppression.bounces.create
186
+ - suppression.blocks.create
187
+ - suppression.invalid_emails.create
188
+ - suppression.spam_reports.create
189
+ - suppression.unsubscribes.create
190
+ :delete:
191
+ - suppression.delete
192
+ - suppression.bounces.delete
193
+ - suppression.blocks.delete
194
+ - suppression.invalid_emails.delete
195
+ - suppression.spam_reports.delete
196
+ - suppression.unsubscribes.delete
197
+ :read:
198
+ - suppression.read
199
+ - suppression.bounces.read
200
+ - suppression.blocks.read
201
+ - suppression.invalid_emails.read
202
+ - suppression.spam_reports.read
203
+ - suppression.unsubscribes.read
204
+ :update:
205
+ - suppression.update
206
+ - suppression.bounces.update
207
+ - suppression.blocks.update
208
+ - suppression.invalid_emails.update
209
+ - suppression.spam_reports.update
210
+ - suppression.unsubscribes.update
211
+ :teammates:
212
+ :create:
213
+ - teammates.create
214
+ :delete:
215
+ - teammates.delete
216
+ :read:
217
+ - teammates.read
218
+ :update:
219
+ - teammates.update
220
+ :templates:
221
+ :create:
222
+ - templates.create
223
+ - templates.versions.activate.create
224
+ - templates.versions.create
225
+ :delete:
226
+ - templates.delete
227
+ - templates.versions.activate.delete
228
+ - templates.versions.delete
229
+ :read:
230
+ - templates.read
231
+ - templates.versions.activate.read
232
+ - templates.versions.read
233
+ :update:
234
+ - templates.update
235
+ - templates.versions.activate.update
236
+ - templates.versions.update
237
+ :tracking_settings:
238
+ :create: []
239
+ :delete: []
240
+ :read:
241
+ - tracking_settings.click.read
242
+ - tracking_settings.google_analytics.read
243
+ - tracking_settings.open.read
244
+ - tracking_settings.read
245
+ - tracking_settings.subscription.read
246
+ :update:
247
+ - tracking_settings.click.update
248
+ - tracking_settings.google_analytics.update
249
+ - tracking_settings.open.update
250
+ - tracking_settings.subscription.update
251
+ :user_settings:
252
+ :create:
253
+ - user.email.create
254
+ - user.multifactor_authentication.create
255
+ :delete:
256
+ - user.email.delete
257
+ - user.multifactor_authentication.delete
258
+ :read:
259
+ - user.account.read
260
+ - user.credits.read
261
+ - user.email.read
262
+ - user.multifactor_authentication.read
263
+ - user.password.read
264
+ - user.profile.read
265
+ - user.timezone.read
266
+ - user.settings.enforced_tls.read
267
+ - user.username.read
268
+ :update:
269
+ - user.email.update
270
+ - user.multifactor_authentication.update
271
+ - user.password.update
272
+ - user.profile.update
273
+ - user.settings.enforced_tls.update
274
+ - user.timezone.update
275
+ - user.username.update
276
+ :webhooks:
277
+ :create:
278
+ - user.webhooks.event.test.create
279
+ - user.webhooks.parse.settings.create
280
+ :delete:
281
+ - user.webhooks.parse.settings.delete
282
+ :read:
283
+ - user.webhooks.event.settings.read
284
+ - user.webhooks.event.test.read
285
+ - user.webhooks.parse.settings.read
286
+ - user.webhooks.parse.stats.read
287
+ :update:
288
+ - user.webhooks.event.settings.update
289
+ - user.webhooks.event.test.update
290
+ - user.webhooks.parse.settings.update
291
+ :whitelabel:
292
+ :create:
293
+ - whitelabel.create
294
+ :delete:
295
+ - whitelabel.delete
296
+ :read:
297
+ - whitelabel.read
298
+ :update:
299
+ - whitelabel.update
300
+ :access_settings:
301
+ :create:
302
+ - access_settings.whitelist.create
303
+ :delete:
304
+ - access_settings.whitelist.delete
305
+ :read:
306
+ - access_settings.activity.read
307
+ - access_settings.whitelist.read
308
+ :update:
309
+ - access_settings.whitelist.update
@@ -1,4 +1,4 @@
1
- **This module allows you to quickly and easily build a Settings object for retrieving or updating you SendGrid Settings.**
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
 
@@ -22,7 +22,7 @@ module SendGrid
22
22
  starting_date = stat['date']
23
23
  all_stats_for_date = stat['stats']
24
24
 
25
- metrics = all_stats_for_date.map do |metric|
25
+ all_stats_for_date.map do |metric|
26
26
  Metrics.new(metric['metrics'].merge('date' => starting_date))
27
27
  end
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module SendGrid
2
- VERSION = '5.3.0'
2
+ VERSION = '6.0.4'
3
3
  end
data/lib/sendgrid-ruby.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'sendgrid/client'
2
2
  require_relative 'sendgrid/version'
3
+ require_relative 'sendgrid/helpers/ip_management/ip_management'
3
4
  require_relative 'sendgrid/helpers/mail/asm'
4
5
  require_relative 'sendgrid/helpers/mail/attachment'
5
6
  require_relative 'sendgrid/helpers/mail/bcc_settings'
@@ -25,3 +26,4 @@ require_relative 'sendgrid/helpers/settings/settings'
25
26
  require_relative 'sendgrid/helpers/stats/email_stats'
26
27
  require_relative 'sendgrid/helpers/stats/stats_response'
27
28
  require_relative 'sendgrid/helpers/stats/metrics'
29
+ require_relative 'sendgrid/helpers/permissions/scope'
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)
@@ -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.add_dependency 'sinatra', '>= 1.4.7', '< 3'
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 Python Library"
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 Python Library"
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 Python 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 SendGrid Python 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 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"}}}'))
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