sendgrid-ruby 5.3.0 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/pr-lint.yml +15 -0
  3. data/.github/workflows/test-and-deploy.yml +120 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +8 -0
  6. data/.rubocop_todo.yml +127 -0
  7. data/CHANGELOG.md +261 -8
  8. data/CODE_OF_CONDUCT.md +57 -25
  9. data/CONTRIBUTING.md +24 -71
  10. data/Dockerfile +14 -0
  11. data/FIRST_TIMERS.md +53 -0
  12. data/Gemfile +0 -1
  13. data/LICENSE +21 -0
  14. data/Makefile +14 -0
  15. data/PULL_REQUEST_TEMPLATE.md +31 -0
  16. data/README.md +39 -43
  17. data/Rakefile +3 -4
  18. data/TROUBLESHOOTING.md +41 -21
  19. data/UPGRADE.md +5 -0
  20. data/USAGE.md +1231 -1122
  21. data/examples/accesssettings/accesssettings.rb +9 -12
  22. data/examples/alerts/alerts.rb +8 -11
  23. data/examples/apikeys/apikeys.rb +12 -15
  24. data/examples/asm/asm.rb +27 -30
  25. data/examples/browsers/browsers.rb +0 -3
  26. data/examples/campaigns/campaigns.rb +29 -32
  27. data/examples/categories/categories.rb +0 -3
  28. data/examples/clients/clients.rb +1 -4
  29. data/examples/contactdb/contactdb.rb +63 -66
  30. data/examples/dataresidency/setregion.rb +48 -0
  31. data/examples/devices/devices.rb +0 -3
  32. data/examples/emailactivity/emailactivity.rb +52 -0
  33. data/examples/geo/geo.rb +0 -3
  34. data/examples/helpers/eventwebhook/example.rb +16 -0
  35. data/examples/helpers/mail/example.rb +30 -19
  36. data/examples/helpers/settings/example.rb +1 -1
  37. data/examples/helpers/stats/example.rb +4 -4
  38. data/examples/ips/ips.rb +31 -21
  39. data/examples/mail/mail.rb +73 -76
  40. data/examples/mailboxproviders/mailboxproviders.rb +0 -3
  41. data/examples/mailsettings/mailsettings.rb +21 -24
  42. data/examples/partnersettings/partnersettings.rb +3 -6
  43. data/examples/scopes/scopes.rb +49 -5
  44. data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +68 -71
  45. data/examples/senders/senders.rb +28 -31
  46. data/examples/stats/stats.rb +0 -3
  47. data/examples/subusers/subusers.rb +17 -20
  48. data/examples/suppression/suppression.rb +23 -26
  49. data/examples/templates/templates.rb +29 -31
  50. data/examples/trackingsettings/trackingsettings.rb +14 -17
  51. data/examples/user/user.rb +41 -44
  52. data/lib/rack/sendgrid_webhook_verification.rb +55 -0
  53. data/lib/sendgrid/base_interface.rb +57 -0
  54. data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
  55. data/lib/sendgrid/helpers/inbound/README.md +26 -9
  56. data/lib/sendgrid/helpers/inbound/app.rb +15 -3
  57. data/lib/sendgrid/helpers/inbound/public/index.html +2 -2
  58. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +2 -2
  59. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +2 -2
  60. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +2 -2
  61. data/lib/sendgrid/helpers/inbound/send.rb +5 -5
  62. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  63. data/lib/sendgrid/helpers/mail/README.md +4 -4
  64. data/lib/sendgrid/helpers/mail/asm.rb +4 -18
  65. data/lib/sendgrid/helpers/mail/attachment.rb +30 -38
  66. data/lib/sendgrid/helpers/mail/bcc_settings.rb +4 -18
  67. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +6 -18
  68. data/lib/sendgrid/helpers/mail/category.rb +2 -12
  69. data/lib/sendgrid/helpers/mail/click_tracking.rb +4 -18
  70. data/lib/sendgrid/helpers/mail/content.rb +4 -18
  71. data/lib/sendgrid/helpers/mail/custom_arg.rb +4 -10
  72. data/lib/sendgrid/helpers/mail/email.rb +10 -20
  73. data/lib/sendgrid/helpers/mail/footer.rb +5 -27
  74. data/lib/sendgrid/helpers/mail/ganalytics.rb +9 -55
  75. data/lib/sendgrid/helpers/mail/header.rb +4 -10
  76. data/lib/sendgrid/helpers/mail/mail.rb +37 -87
  77. data/lib/sendgrid/helpers/mail/mail_settings.rb +7 -25
  78. data/lib/sendgrid/helpers/mail/open_tracking.rb +4 -18
  79. data/lib/sendgrid/helpers/mail/personalization.rb +38 -27
  80. data/lib/sendgrid/helpers/mail/section.rb +4 -10
  81. data/lib/sendgrid/helpers/mail/spam_check.rb +5 -27
  82. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +6 -36
  83. data/lib/sendgrid/helpers/mail/substitution.rb +4 -10
  84. data/lib/sendgrid/helpers/mail/tracking_settings.rb +6 -20
  85. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  86. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  87. data/lib/sendgrid/helpers/settings/README.md +3 -3
  88. data/lib/sendgrid/helpers/settings/settings.rb +1 -1
  89. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +3 -5
  90. data/lib/sendgrid/helpers/stats/metrics.rb +5 -7
  91. data/lib/sendgrid/helpers/stats/stats_response.rb +1 -3
  92. data/lib/sendgrid/sendgrid.rb +21 -0
  93. data/lib/sendgrid/twilio_email.rb +21 -0
  94. data/lib/sendgrid/version.rb +1 -1
  95. data/lib/sendgrid-ruby.rb +7 -1
  96. data/mail_helper_v3.md +21 -21
  97. data/sendgrid-ruby.gemspec +12 -12
  98. data/spec/fixtures/event_webhook.rb +22 -0
  99. data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
  100. data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
  101. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  102. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +3 -3
  103. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +3 -3
  104. data/spec/sendgrid/helpers/settings/settings_spec.rb +2 -2
  105. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +3 -3
  106. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +3 -3
  107. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +22 -23
  108. data/spec/sendgrid/helpers/stats/metrics_spec.rb +19 -20
  109. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +22 -23
  110. data/spec/sendgrid/sendgrid_spec.rb +11 -0
  111. data/spec/sendgrid/twilio_email_spec.rb +11 -0
  112. data/spec/spec_helper.rb +3 -1
  113. data/static/img/github-fork.png +0 -0
  114. data/static/img/github-sign-up.png +0 -0
  115. data/test/sendgrid/helpers/mail/test_attachment.rb +33 -0
  116. data/test/sendgrid/helpers/mail/test_category.rb +0 -2
  117. data/test/sendgrid/helpers/mail/test_data_residency.rb +44 -0
  118. data/test/sendgrid/helpers/mail/test_email.rb +17 -10
  119. data/test/sendgrid/helpers/mail/test_mail.rb +126 -119
  120. data/test/sendgrid/helpers/mail/test_personalizations.rb +145 -92
  121. data/test/sendgrid/permissions/test_scopes.rb +36 -0
  122. data/test/sendgrid/test_sendgrid-ruby.rb +1961 -1979
  123. data/twilio_sendgrid_logo.png +0 -0
  124. data/use-cases/README.md +17 -0
  125. data/use-cases/domain-authentication.md +5 -0
  126. data/use-cases/email-statistics.md +52 -0
  127. data/use-cases/legacy-templates.md +98 -0
  128. data/use-cases/personalizations.md +34 -0
  129. data/use-cases/sms.md +39 -0
  130. data/use-cases/transactional-templates.md +111 -0
  131. data/use-cases/twilio-email.md +13 -0
  132. data/use-cases/twilio-setup.md +54 -0
  133. metadata +99 -45
  134. data/.codeclimate.yml +0 -21
  135. data/.github/ISSUE_TEMPLATE +0 -17
  136. data/.github/PULL_REQUEST_TEMPLATE +0 -24
  137. data/.travis.yml +0 -29
  138. data/LICENSE.txt +0 -22
  139. data/USE_CASES.md +0 -147
  140. data/docker/Dockerfile +0 -12
  141. data/docker/README.md +0 -30
  142. data/lib/sendgrid/client.rb +0 -35
  143. data/test/prism.sh +0 -42
@@ -1,253 +1,260 @@
1
- require_relative "../../../../lib/sendgrid/helpers/mail/mail"
2
- require_relative "../../../../lib/sendgrid/client"
1
+ require_relative '../../../../lib/sendgrid/helpers/mail/mail'
2
+ require_relative '../../../../lib/sendgrid/sendgrid'
3
3
  include SendGrid
4
- require "json"
4
+ require 'json'
5
5
  require 'minitest/autorun'
6
6
 
7
7
  class TestMail < Minitest::Test
8
- def setup
9
- end
8
+ def setup; end
10
9
 
11
10
  def test_hello_world
12
11
  from = Email.new(email: 'test@example.com')
13
12
  to = Email.new(email: 'test@example.com')
14
- subject = 'Sending with SendGrid is Fun'
13
+ subject = 'Sending with Twilio SendGrid is Fun'
15
14
  content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
16
- mail = Mail.new(from, subject, to, content)
15
+ mail = SendGrid::Mail.new(from, subject, to, content)
17
16
 
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"}]}'))
17
+ 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
18
  end
20
19
 
21
20
  def test_kitchen_sink
22
- mail = Mail.new
23
- mail.from = Email.new(email: "test@example.com")
24
- mail.subject = "Hello World from the SendGrid Ruby Library"
21
+ mail = SendGrid::Mail.new
22
+ mail.from = Email.new(email: 'test@example.com')
23
+ mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
25
24
  personalization = Personalization.new
26
- personalization.add_to(Email.new(email: "test@example.com", name: "Example User"))
27
- personalization.add_to(Email.new(email: "test@example.com", name: "Example User"))
28
- personalization.add_cc(Email.new(email: "test@example.com", name: "Example User"))
29
- personalization.add_cc(Email.new(email: "test@example.com", name: "Example User"))
30
- personalization.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
31
- personalization.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
32
- personalization.subject = "Hello World from the Personalized SendGrid Python Library"
33
- personalization.add_header(Header.new(key: "X-Test", value: "True"))
34
- personalization.add_header(Header.new(key: "X-Mock", value: "False"))
35
- personalization.add_substitution(Substitution.new(key: "%name%", value: "Example User"))
36
- personalization.add_substitution(Substitution.new(key: "%city%", value: "Denver"))
37
- personalization.add_custom_arg(CustomArg.new(key: "user_id", value: "343"))
38
- personalization.add_custom_arg(CustomArg.new(key: "type", value: "marketing"))
39
- personalization.send_at = 1443636843
25
+ personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User 1'))
26
+ personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User 2'))
27
+ personalization.add_cc(Email.new(email: 'test3@example.com', name: 'Example User 3'))
28
+ personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User 4'))
29
+ personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User 5'))
30
+ personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User 6'))
31
+ personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
32
+ personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
33
+ personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
34
+ personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
35
+ personalization.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
36
+ personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
37
+ personalization.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
38
+ personalization.send_at = 1_443_636_843
40
39
  mail.add_personalization(personalization)
41
40
 
42
41
  personalization2 = Personalization.new
43
- personalization2.add_to(Email.new(email: "test@example.com", name: "Example User"))
44
- personalization2.add_to(Email.new(email: "test@example.com", name: "Example User"))
45
- personalization2.add_cc(Email.new(email: "test@example.com", name: "Example User"))
46
- personalization2.add_cc(Email.new(email: "test@example.com", name: "Example User"))
47
- personalization2.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
48
- personalization2.add_bcc(Email.new(email: "test@example.com", name: "Example User"))
49
- personalization2.subject = "Hello World from the Personalized SendGrid Python Library"
50
- personalization2.add_header(Header.new(key: "X-Test", value: "True"))
51
- personalization2.add_header(Header.new(key: "X-Mock", value: "False"))
52
- personalization2.add_substitution(Substitution.new(key: "%name%", value: "Example User"))
53
- personalization2.add_substitution(Substitution.new(key: "%city%", value: "Denver"))
54
- personalization2.add_custom_arg(CustomArg.new(key: "user_id", value: "343"))
55
- personalization2.add_custom_arg(CustomArg.new(key: "type", value: "marketing"))
56
- personalization2.send_at = 1443636843
42
+ personalization2.add_to(Email.new(email: 'test1@example.com', name: 'Example User 1'))
43
+ personalization2.add_to(Email.new(email: 'test2@example.com', name: 'Example User 2'))
44
+ personalization2.add_cc(Email.new(email: 'test3@example.com', name: 'Example User 3'))
45
+ personalization2.add_cc(Email.new(email: 'test4@example.com', name: 'Example User 4'))
46
+ personalization2.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User 5'))
47
+ personalization2.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User 6'))
48
+ personalization2.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
49
+ personalization2.add_header(Header.new(key: 'X-Test', value: 'True'))
50
+ personalization2.add_header(Header.new(key: 'X-Mock', value: 'False'))
51
+ personalization2.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
52
+ personalization2.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
53
+ personalization2.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
54
+ personalization2.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
55
+ personalization2.send_at = 1_443_636_843
57
56
  mail.add_personalization(personalization2)
58
57
 
59
- mail.add_content(Content.new(type: "text/plain", value: "some text here"))
60
- mail.add_content(Content.new(type: "text/html", value: "<html><body>some text here</body></html>"))
58
+ mail.add_content(Content.new(type: 'text/plain', value: 'some text here'))
59
+ mail.add_content(Content.new(type: 'text/html', value: '<html><body>some text here</body></html>'))
61
60
 
62
61
  attachment = Attachment.new
63
- attachment.content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"
64
- attachment.type = "application/pdf"
65
- attachment.filename = "balance_001.pdf"
66
- attachment.disposition = "attachment"
67
- attachment.content_id = "Balance Sheet"
62
+ attachment.content = 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12'
63
+ attachment.type = 'application/pdf'
64
+ attachment.filename = 'balance_001.pdf'
65
+ attachment.disposition = 'attachment'
66
+ attachment.content_id = 'Balance Sheet'
68
67
 
69
68
  mail.add_attachment(attachment)
70
69
 
71
70
  attachment2 = Attachment.new
72
- attachment2.content = "BwdW"
73
- attachment2.type = "image/png"
74
- attachment2.filename = "banner.png"
75
- attachment2.disposition = "inline"
76
- attachment2.content_id = "Banner"
71
+ attachment2.content = 'BwdW'
72
+ attachment2.type = 'image/png'
73
+ attachment2.filename = 'banner.png'
74
+ attachment2.disposition = 'inline'
75
+ attachment2.content_id = 'Banner'
77
76
  mail.add_attachment(attachment2)
78
77
 
79
- mail.template_id = "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
78
+ mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
80
79
 
81
- mail.add_section(Section.new(key: "%section1%", value: "Substitution Text for Section 1"))
82
- mail.add_section(Section.new(key: "%section2%", value: "Substitution Text for Section 2"))
80
+ mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1'))
81
+ mail.add_section(Section.new(key: '%section2%', value: 'Substitution Text for Section 2'))
83
82
 
84
- mail.add_header(Header.new(key: "X-Test3", value: "test3"))
85
- mail.add_header(Header.new(key: "X-Test4", value: "test4"))
83
+ mail.add_header(Header.new(key: 'X-Test3', value: 'test3'))
84
+ mail.add_header(Header.new(key: 'X-Test4', value: 'test4'))
86
85
 
87
- mail.add_category(Category.new(name: "May"))
88
- mail.add_category(Category.new(name: "2016"))
86
+ mail.add_category(Category.new(name: 'May'))
87
+ mail.add_category(Category.new(name: '2016'))
89
88
 
90
- mail.add_custom_arg(CustomArg.new(key: "campaign", value: "welcome"))
91
- mail.add_custom_arg(CustomArg.new(key: "weekday", value: "morning"))
89
+ mail.add_custom_arg(CustomArg.new(key: 'campaign', value: 'welcome'))
90
+ mail.add_custom_arg(CustomArg.new(key: 'weekday', value: 'morning'))
92
91
 
93
- mail.send_at = 1443636842
92
+ mail.send_at = 1_443_636_842
94
93
 
95
- mail.batch_id = "sendgrid_batch_id"
94
+ mail.batch_id = 'sendgrid_batch_id'
96
95
 
97
- mail.asm = ASM.new(group_id: 99, groups_to_display: [4,5,6,7,8])
96
+ mail.asm = ASM.new(group_id: 99, groups_to_display: [4, 5, 6, 7, 8])
98
97
 
99
- mail.ip_pool_name = "23"
98
+ mail.ip_pool_name = '23'
100
99
 
101
100
  mail_settings = MailSettings.new
102
- mail_settings.bcc = BccSettings.new(enable: true, email: "test@example.com")
101
+ mail_settings.bcc = BccSettings.new(enable: true, email: 'test@example.com')
103
102
  mail_settings.bypass_list_management = BypassListManagement.new(enable: true)
104
- mail_settings.footer = Footer.new(enable: true, text: "Footer Text", html: "<html><body>Footer Text</body></html>")
103
+ mail_settings.footer = Footer.new(enable: true, text: 'Footer Text', html: '<html><body>Footer Text</body></html>')
105
104
  mail_settings.sandbox_mode = SandBoxMode.new(enable: true)
106
- mail_settings.spam_check = SpamCheck.new(enable: true, threshold: 1, post_to_url: "https://spamcatcher.sendgrid.com")
105
+ mail_settings.spam_check = SpamCheck.new(enable: true, threshold: 1, post_to_url: 'https://spamcatcher.sendgrid.com')
107
106
  mail.mail_settings = mail_settings
108
107
 
109
108
  tracking_settings = TrackingSettings.new
110
109
  tracking_settings.click_tracking = ClickTracking.new(enable: false, enable_text: false)
111
- tracking_settings.open_tracking = OpenTracking.new(enable: true, substitution_tag: "Optional tag to replace with the open image in the body of the message")
112
- tracking_settings.subscription_tracking = SubscriptionTracking.new(enable: true, text: "text to insert into the text/plain portion of the message", 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")
113
- tracking_settings.ganalytics = Ganalytics.new(enable: true, utm_source: "some source", utm_medium: "some medium", utm_term: "some term", utm_content: "some content", utm_campaign: "some campaign")
110
+ tracking_settings.open_tracking = OpenTracking.new(enable: true, substitution_tag: 'Optional tag to replace with the open image in the body of the message')
111
+ tracking_settings.subscription_tracking = SubscriptionTracking.new(enable: true, text: 'text to insert into the text/plain portion of the message', 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')
112
+ tracking_settings.ganalytics = Ganalytics.new(enable: true, utm_source: 'some source', utm_medium: 'some medium', utm_term: 'some term', utm_content: 'some content', utm_campaign: 'some campaign')
114
113
  mail.tracking_settings = tracking_settings
115
114
 
116
- mail.reply_to = Email.new(email: "test@example.com")
115
+ mail.reply_to = Email.new(email: 'test@example.com')
117
116
 
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"}}}'))
117
+ # rubocop:disable Layout/LineLength
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":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","name":"Example User 4"}],"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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]},{"bcc":[{"email":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","name":"Example User 4"}],"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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]}],"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
+ # rubocop:enable all
119
120
  end
120
121
 
121
122
  def test_that_personalizations_is_empty_initially
122
- mail = Mail.new
123
+ mail = SendGrid::Mail.new
123
124
  assert_equal([], mail.personalizations)
124
125
  end
125
126
 
126
127
  def test_that_contents_is_empty_initially
127
- mail = Mail.new
128
+ mail = SendGrid::Mail.new
128
129
  assert_equal([], mail.contents)
129
130
  end
130
131
 
131
132
  def test_that_attachments_is_empty_initially
132
- mail = Mail.new
133
+ mail = SendGrid::Mail.new
133
134
  assert_equal([], mail.attachments)
134
135
  end
135
136
 
136
137
  def test_that_categories_is_empty_initially
137
- mail = Mail.new
138
+ mail = SendGrid::Mail.new
138
139
  assert_equal([], mail.categories)
139
140
  end
140
141
 
141
142
  def test_add_personalization
142
- mail = Mail.new
143
+ mail = SendGrid::Mail.new
143
144
  mail.add_personalization('foo')
144
145
  assert_equal(['foo'.to_json], mail.personalizations)
145
146
  end
146
147
 
147
148
  def test_add_content
148
- mail = Mail.new
149
+ mail = SendGrid::Mail.new
149
150
  mail.add_content('foo')
150
151
  assert_equal(['foo'.to_json], mail.contents)
151
152
  end
152
153
 
153
154
  def test_add_section
154
- mail = Mail.new
155
+ mail = SendGrid::Mail.new
155
156
  mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1'))
156
157
  expected_json = {
157
- "sections"=>{
158
- "%section1%"=>"Substitution Text for Section 1"
159
- }
158
+ 'sections' => {
159
+ '%section1%' => 'Substitution Text for Section 1'
160
+ }
160
161
  }
161
162
  assert_equal mail.to_json, expected_json
162
163
  mail.add_section(Section.new(key: '%section2%', value: 'Substitution Text for Section 2'))
163
164
  expected_json = {
164
- "sections"=>{
165
- "%section1%"=>"Substitution Text for Section 1",
166
- "%section2%"=>"Substitution Text for Section 2"
167
- }
165
+ 'sections' => {
166
+ '%section1%' => 'Substitution Text for Section 1',
167
+ '%section2%' => 'Substitution Text for Section 2'
168
+ }
168
169
  }
169
170
  assert_equal mail.to_json, expected_json
170
171
  end
171
172
 
172
173
  def test_add_header
173
- mail = Mail.new
174
+ mail = SendGrid::Mail.new
174
175
  mail.add_header(Header.new(key: 'X-Test3', value: 'test3'))
175
176
  expected_json = {
176
- "headers"=>{
177
- "X-Test3"=>"test3"
178
- }
177
+ 'headers' => {
178
+ 'X-Test3' => 'test3'
179
+ }
179
180
  }
180
181
  assert_equal mail.to_json, expected_json
181
182
  mail.add_header(Header.new(key: 'X-Test4', value: 'test4'))
182
183
  expected_json = {
183
- "headers"=>{
184
- "X-Test3"=>"test3",
185
- "X-Test4"=>"test4"
186
- }
184
+ 'headers' => {
185
+ 'X-Test3' => 'test3',
186
+ 'X-Test4' => 'test4'
187
+ }
187
188
  }
188
189
  assert_equal mail.to_json, expected_json
189
190
  end
190
191
 
191
192
  def test_add_custom_arg
192
- mail = Mail.new
193
+ mail = SendGrid::Mail.new
193
194
  mail.add_custom_arg(CustomArg.new(key: 'campaign 1', value: 'welcome 1'))
194
195
  expected_json = {
195
- "custom_args"=>{
196
- "campaign 1"=>"welcome 1"
197
- }
196
+ 'custom_args' => {
197
+ 'campaign 1' => 'welcome 1'
198
+ }
198
199
  }
199
200
  assert_equal mail.to_json, expected_json
200
201
  mail.add_custom_arg(CustomArg.new(key: 'campaign 2', value: 'welcome 2'))
201
202
  expected_json = {
202
- "custom_args"=>{
203
- "campaign 1"=>"welcome 1",
204
- "campaign 2"=>"welcome 2"
205
- }
203
+ 'custom_args' => {
204
+ 'campaign 1' => 'welcome 1',
205
+ 'campaign 2' => 'welcome 2'
206
+ }
206
207
  }
207
208
  assert_equal mail.to_json, expected_json
208
209
  end
209
210
 
210
211
  def test_add_non_string_custom_arg
211
212
  mail = Mail.new
212
- mail.add_custom_arg(CustomArg.new(key: "Integer", value: 1))
213
- mail.add_custom_arg(CustomArg.new(key: "Array", value: [1, "a", true]))
214
- mail.add_custom_arg(CustomArg.new(key: "Hash", value: {"a" => 1, "b" => 2}))
213
+ mail.add_custom_arg(CustomArg.new(key: 'Integer', value: 1))
214
+ mail.add_custom_arg(CustomArg.new(key: 'Array', value: [1, 'a', true]))
215
+ mail.add_custom_arg(CustomArg.new(key: 'Hash', value: { 'a' => 1, 'b' => 2 }))
215
216
  expected_json = {
216
- "custom_args"=>{
217
- "Integer"=>"1",
218
- "Array"=>"[1, \"a\", true]",
219
- "Hash"=>"{\"a\"=>1, \"b\"=>2}",
220
- }
217
+ 'custom_args' => {
218
+ 'Integer' => '1',
219
+ 'Array' => '[1, "a", true]',
220
+ 'Hash' => '{"a"=>1, "b"=>2}'
221
+ }
221
222
  }
222
223
  assert_equal mail.to_json, expected_json
223
224
  end
224
225
 
225
226
  def test_add_attachment
226
- mail = Mail.new
227
+ mail = SendGrid::Mail.new
227
228
  mail.add_attachment('foo')
228
229
  assert_equal(['foo'.to_json], mail.attachments)
229
230
  end
230
231
 
231
232
  def test_add_valid_category
232
- mail = Mail.new
233
+ mail = SendGrid::Mail.new
233
234
  category = Category.new(name: 'foo')
234
235
  mail.add_category(category)
235
236
  assert_equal(['foo'], mail.categories)
236
237
  end
237
238
 
238
239
  def test_add_more_than_1_valid_category
239
- mail = Mail.new
240
- category_1 = Category.new(name: 'foo')
241
- category_2 = Category.new(name: 'bar')
242
- mail.add_category(category_1)
243
- mail.add_category(category_2)
244
- assert_equal(['foo', 'bar'], mail.categories)
240
+ mail = SendGrid::Mail.new
241
+ mail.add_category(Category.new(name: 'foo'))
242
+ mail.add_category(Category.new(name: 'bar'))
243
+ assert_equal(%w[foo bar], mail.categories)
245
244
  end
246
245
 
247
246
  def test_add_invalid_category
248
- mail = Mail.new
247
+ mail = SendGrid::Mail.new
249
248
  assert_raises(NoMethodError) do
250
249
  mail.add_category('foo')
251
250
  end
252
251
  end
252
+
253
+ def test_check_for_secrets
254
+ mail = Mail.new
255
+ mail.add_content(Content.new(type: 'text/plain', value: 'Sensitive information: SG.a123b456'))
256
+ assert_raises(SecurityError) do
257
+ mail.check_for_secrets([/SG.[a-zA-Z0-9_-]*/])
258
+ end
259
+ end
253
260
  end