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.
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,9 +1,7 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Retrieve all blocks #
9
7
  # GET /suppression/blocks #
@@ -19,9 +17,9 @@ puts response.headers
19
17
  # DELETE /suppression/blocks #
20
18
 
21
19
  data = JSON.parse('{
22
- "delete_all": false,
20
+ "delete_all": false,
23
21
  "emails": [
24
- "example1@example.com",
22
+ "example1@example.com",
25
23
  "example2@example.com"
26
24
  ]
27
25
  }')
@@ -34,8 +32,8 @@ puts response.headers
34
32
  # Retrieve a specific block #
35
33
  # GET /suppression/blocks/{email} #
36
34
 
37
- email = "test_url_param"
38
- response = sg.client.suppression.blocks._(email).get()
35
+ email = 'test_url_param'
36
+ response = sg.client.suppression.blocks._(email).get
39
37
  puts response.status_code
40
38
  puts response.body
41
39
  puts response.headers
@@ -44,8 +42,8 @@ puts response.headers
44
42
  # Delete a specific block #
45
43
  # DELETE /suppression/blocks/{email} #
46
44
 
47
- email = "test_url_param"
48
- response = sg.client.suppression.blocks._(email).delete()
45
+ email = 'test_url_param'
46
+ response = sg.client.suppression.blocks._(email).delete
49
47
  puts response.status_code
50
48
  puts response.body
51
49
  puts response.headers
@@ -65,9 +63,9 @@ puts response.headers
65
63
  # DELETE /suppression/bounces #
66
64
 
67
65
  data = JSON.parse('{
68
- "delete_all": true,
66
+ "delete_all": true,
69
67
  "emails": [
70
- "example@example.com",
68
+ "example@example.com",
71
69
  "example2@example.com"
72
70
  ]
73
71
  }')
@@ -80,8 +78,8 @@ puts response.headers
80
78
  # Retrieve a Bounce #
81
79
  # GET /suppression/bounces/{email} #
82
80
 
83
- email = "test_url_param"
84
- response = sg.client.suppression.bounces._(email).get()
81
+ email = 'test_url_param'
82
+ response = sg.client.suppression.bounces._(email).get
85
83
  puts response.status_code
86
84
  puts response.body
87
85
  puts response.headers
@@ -91,7 +89,7 @@ puts response.headers
91
89
  # DELETE /suppression/bounces/{email} #
92
90
 
93
91
  params = JSON.parse('{"email_address": "example@example.com"}')
94
- email = "test_url_param"
92
+ email = 'test_url_param'
95
93
  response = sg.client.suppression.bounces._(email).delete(query_params: params)
96
94
  puts response.status_code
97
95
  puts response.body
@@ -112,9 +110,9 @@ puts response.headers
112
110
  # DELETE /suppression/invalid_emails #
113
111
 
114
112
  data = JSON.parse('{
115
- "delete_all": false,
113
+ "delete_all": false,
116
114
  "emails": [
117
- "example1@example.com",
115
+ "example1@example.com",
118
116
  "example2@example.com"
119
117
  ]
120
118
  }')
@@ -127,8 +125,8 @@ puts response.headers
127
125
  # Retrieve a specific invalid email #
128
126
  # GET /suppression/invalid_emails/{email} #
129
127
 
130
- email = "test_url_param"
131
- response = sg.client.suppression.invalid_emails._(email).get()
128
+ email = 'test_url_param'
129
+ response = sg.client.suppression.invalid_emails._(email).get
132
130
  puts response.status_code
133
131
  puts response.body
134
132
  puts response.headers
@@ -137,8 +135,8 @@ puts response.headers
137
135
  # Delete a specific invalid email #
138
136
  # DELETE /suppression/invalid_emails/{email} #
139
137
 
140
- email = "test_url_param"
141
- response = sg.client.suppression.invalid_emails._(email).delete()
138
+ email = 'test_url_param'
139
+ response = sg.client.suppression.invalid_emails._(email).delete
142
140
  puts response.status_code
143
141
  puts response.body
144
142
  puts response.headers
@@ -147,8 +145,8 @@ puts response.headers
147
145
  # Retrieve a specific spam report #
148
146
  # GET /suppression/spam_report/{email} #
149
147
 
150
- email = "test_url_param"
151
- response = sg.client.suppression.spam_report._(email).get()
148
+ email = 'test_url_param'
149
+ response = sg.client.suppression.spam_report._(email).get
152
150
  puts response.status_code
153
151
  puts response.body
154
152
  puts response.headers
@@ -157,8 +155,8 @@ puts response.headers
157
155
  # Delete a specific spam report #
158
156
  # DELETE /suppression/spam_report/{email} #
159
157
 
160
- email = "test_url_param"
161
- response = sg.client.suppression.spam_report._(email).delete()
158
+ email = 'test_url_param'
159
+ response = sg.client.suppression.spam_reports._(email).delete
162
160
  puts response.status_code
163
161
  puts response.body
164
162
  puts response.headers
@@ -178,9 +176,9 @@ puts response.headers
178
176
  # DELETE /suppression/spam_reports #
179
177
 
180
178
  data = JSON.parse('{
181
- "delete_all": false,
179
+ "delete_all": false,
182
180
  "emails": [
183
- "example1@example.com",
181
+ "example1@example.com",
184
182
  "example2@example.com"
185
183
  ]
186
184
  }')
@@ -198,4 +196,3 @@ response = sg.client.suppression.unsubscribes.get(query_params: params)
198
196
  puts response.status_code
199
197
  puts response.body
200
198
  puts response.headers
201
-
@@ -1,9 +1,7 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Create a transactional template. #
9
7
  # POST /templates #
@@ -17,10 +15,11 @@ puts response.body
17
15
  puts response.headers
18
16
 
19
17
  ##################################################
20
- # Retrieve all transactional templates. #
18
+ # Retrieve all transactional templates (legacy & dynamic). #
21
19
  # GET /templates #
22
20
 
23
- response = sg.client.templates.get()
21
+ params = JSON.parse('{"generations": "legacy,dynamic"}')
22
+ response = sg.client.templates.get(query_params: params)
24
23
  puts response.status_code
25
24
  puts response.body
26
25
  puts response.headers
@@ -32,7 +31,7 @@ puts response.headers
32
31
  data = JSON.parse('{
33
32
  "name": "new_example_name"
34
33
  }')
35
- template_id = "test_url_param"
34
+ template_id = 'test_url_param'
36
35
  response = sg.client.templates._(template_id).patch(request_body: data)
37
36
  puts response.status_code
38
37
  puts response.body
@@ -42,8 +41,8 @@ puts response.headers
42
41
  # Retrieve a single transactional template. #
43
42
  # GET /templates/{template_id} #
44
43
 
45
- template_id = "test_url_param"
46
- response = sg.client.templates._(template_id).get()
44
+ template_id = 'test_url_param'
45
+ response = sg.client.templates._(template_id).get
47
46
  puts response.status_code
48
47
  puts response.body
49
48
  puts response.headers
@@ -52,8 +51,8 @@ puts response.headers
52
51
  # Delete a template. #
53
52
  # DELETE /templates/{template_id} #
54
53
 
55
- template_id = "test_url_param"
56
- response = sg.client.templates._(template_id).delete()
54
+ template_id = 'test_url_param'
55
+ response = sg.client.templates._(template_id).delete
57
56
  puts response.status_code
58
57
  puts response.body
59
58
  puts response.headers
@@ -63,14 +62,14 @@ puts response.headers
63
62
  # POST /templates/{template_id}/versions #
64
63
 
65
64
  data = JSON.parse('{
66
- "active": 1,
67
- "html_content": "<%body%>",
68
- "name": "example_version_name",
69
- "plain_content": "<%body%>",
70
- "subject": "<%subject%>",
65
+ "active": 1,
66
+ "html_content": "<%body%>",
67
+ "name": "example_version_name",
68
+ "plain_content": "<%body%>",
69
+ "subject": "<%subject%>",
71
70
  "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
72
71
  }')
73
- template_id = "test_url_param"
72
+ template_id = 'test_url_param'
74
73
  response = sg.client.templates._(template_id).versions.post(request_body: data)
75
74
  puts response.status_code
76
75
  puts response.body
@@ -81,14 +80,14 @@ puts response.headers
81
80
  # PATCH /templates/{template_id}/versions/{version_id} #
82
81
 
83
82
  data = JSON.parse('{
84
- "active": 1,
85
- "html_content": "<%body%>",
86
- "name": "updated_example_name",
87
- "plain_content": "<%body%>",
83
+ "active": 1,
84
+ "html_content": "<%body%>",
85
+ "name": "updated_example_name",
86
+ "plain_content": "<%body%>",
88
87
  "subject": "<%subject%>"
89
88
  }')
90
- template_id = "test_url_param"
91
- version_id = "test_url_param"
89
+ template_id = 'test_url_param'
90
+ version_id = 'test_url_param'
92
91
  response = sg.client.templates._(template_id).versions._(version_id).patch(request_body: data)
93
92
  puts response.status_code
94
93
  puts response.body
@@ -98,9 +97,9 @@ puts response.headers
98
97
  # Retrieve a specific transactional template version. #
99
98
  # GET /templates/{template_id}/versions/{version_id} #
100
99
 
101
- template_id = "test_url_param"
102
- version_id = "test_url_param"
103
- response = sg.client.templates._(template_id).versions._(version_id).get()
100
+ template_id = 'test_url_param'
101
+ version_id = 'test_url_param'
102
+ response = sg.client.templates._(template_id).versions._(version_id).get
104
103
  puts response.status_code
105
104
  puts response.body
106
105
  puts response.headers
@@ -109,9 +108,9 @@ puts response.headers
109
108
  # Delete a transactional template version. #
110
109
  # DELETE /templates/{template_id}/versions/{version_id} #
111
110
 
112
- template_id = "test_url_param"
113
- version_id = "test_url_param"
114
- response = sg.client.templates._(template_id).versions._(version_id).delete()
111
+ template_id = 'test_url_param'
112
+ version_id = 'test_url_param'
113
+ response = sg.client.templates._(template_id).versions._(version_id).delete
115
114
  puts response.status_code
116
115
  puts response.body
117
116
  puts response.headers
@@ -120,10 +119,9 @@ puts response.headers
120
119
  # Activate a transactional template version. #
121
120
  # POST /templates/{template_id}/versions/{version_id}/activate #
122
121
 
123
- template_id = "test_url_param"
124
- version_id = "test_url_param"
125
- response = sg.client.templates._(template_id).versions._(version_id).activate.post()
122
+ template_id = 'test_url_param'
123
+ version_id = 'test_url_param'
124
+ response = sg.client.templates._(template_id).versions._(version_id).activate.post
126
125
  puts response.status_code
127
126
  puts response.body
128
127
  puts response.headers
129
-
@@ -1,9 +1,7 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Retrieve Tracking Settings #
9
7
  # GET /tracking_settings #
@@ -30,7 +28,7 @@ puts response.headers
30
28
  # Retrieve Click Track Settings #
31
29
  # GET /tracking_settings/click #
32
30
 
33
- response = sg.client.tracking_settings.click.get()
31
+ response = sg.client.tracking_settings.click.get
34
32
  puts response.status_code
35
33
  puts response.body
36
34
  puts response.headers
@@ -40,11 +38,11 @@ puts response.headers
40
38
  # PATCH /tracking_settings/google_analytics #
41
39
 
42
40
  data = JSON.parse('{
43
- "enabled": true,
44
- "utm_campaign": "website",
45
- "utm_content": "",
46
- "utm_medium": "email",
47
- "utm_source": "sendgrid.com",
41
+ "enabled": true,
42
+ "utm_campaign": "website",
43
+ "utm_content": "",
44
+ "utm_medium": "email",
45
+ "utm_source": "sendgrid.com",
48
46
  "utm_term": ""
49
47
  }')
50
48
  response = sg.client.tracking_settings.google_analytics.patch(request_body: data)
@@ -56,7 +54,7 @@ puts response.headers
56
54
  # Retrieve Google Analytics Settings #
57
55
  # GET /tracking_settings/google_analytics #
58
56
 
59
- response = sg.client.tracking_settings.google_analytics.get()
57
+ response = sg.client.tracking_settings.google_analytics.get
60
58
  puts response.status_code
61
59
  puts response.body
62
60
  puts response.headers
@@ -77,7 +75,7 @@ puts response.headers
77
75
  # Get Open Tracking Settings #
78
76
  # GET /tracking_settings/open #
79
77
 
80
- response = sg.client.tracking_settings.open.get()
78
+ response = sg.client.tracking_settings.open.get
81
79
  puts response.status_code
82
80
  puts response.body
83
81
  puts response.headers
@@ -87,11 +85,11 @@ puts response.headers
87
85
  # PATCH /tracking_settings/subscription #
88
86
 
89
87
  data = JSON.parse('{
90
- "enabled": true,
91
- "html_content": "html content",
92
- "landing": "landing page html",
93
- "plain_content": "text content",
94
- "replace": "replacement tag",
88
+ "enabled": true,
89
+ "html_content": "html content",
90
+ "landing": "landing page html",
91
+ "plain_content": "text content",
92
+ "replace": "replacement tag",
95
93
  "url": "url"
96
94
  }')
97
95
  response = sg.client.tracking_settings.subscription.patch(request_body: data)
@@ -103,8 +101,7 @@ puts response.headers
103
101
  # Retrieve Subscription Tracking Settings #
104
102
  # GET /tracking_settings/subscription #
105
103
 
106
- response = sg.client.tracking_settings.subscription.get()
104
+ response = sg.client.tracking_settings.subscription.get
107
105
  puts response.status_code
108
106
  puts response.body
109
107
  puts response.headers
110
-
@@ -1,14 +1,12 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Get a user's account information. #
9
7
  # GET /user/account #
10
8
 
11
- response = sg.client.user.account.get()
9
+ response = sg.client.user.account.get
12
10
  puts response.status_code
13
11
  puts response.body
14
12
  puts response.headers
@@ -17,7 +15,7 @@ puts response.headers
17
15
  # Retrieve your credit balance #
18
16
  # GET /user/credits #
19
17
 
20
- response = sg.client.user.credits.get()
18
+ response = sg.client.user.credits.get
21
19
  puts response.status_code
22
20
  puts response.body
23
21
  puts response.headers
@@ -38,7 +36,7 @@ puts response.headers
38
36
  # Retrieve your account email address #
39
37
  # GET /user/email #
40
38
 
41
- response = sg.client.user.email.get()
39
+ response = sg.client.user.email.get
42
40
  puts response.status_code
43
41
  puts response.body
44
42
  puts response.headers
@@ -48,7 +46,7 @@ puts response.headers
48
46
  # PUT /user/password #
49
47
 
50
48
  data = JSON.parse('{
51
- "new_password": "new_password",
49
+ "new_password": "new_password",
52
50
  "old_password": "old_password"
53
51
  }')
54
52
  response = sg.client.user.password.put(request_body: data)
@@ -61,8 +59,8 @@ puts response.headers
61
59
  # PATCH /user/profile #
62
60
 
63
61
  data = JSON.parse('{
64
- "city": "Orange",
65
- "first_name": "Example",
62
+ "city": "Orange",
63
+ "first_name": "Example",
66
64
  "last_name": "User"
67
65
  }')
68
66
  response = sg.client.user.profile.patch(request_body: data)
@@ -74,7 +72,7 @@ puts response.headers
74
72
  # Get a user's profile #
75
73
  # GET /user/profile #
76
74
 
77
- response = sg.client.user.profile.get()
75
+ response = sg.client.user.profile.get
78
76
  puts response.status_code
79
77
  puts response.body
80
78
  puts response.headers
@@ -84,7 +82,7 @@ puts response.headers
84
82
  # POST /user/scheduled_sends #
85
83
 
86
84
  data = JSON.parse('{
87
- "batch_id": "YOUR_BATCH_ID",
85
+ "batch_id": "YOUR_BATCH_ID",
88
86
  "status": "pause"
89
87
  }')
90
88
  response = sg.client.user.scheduled_sends.post(request_body: data)
@@ -96,7 +94,7 @@ puts response.headers
96
94
  # Retrieve all scheduled sends #
97
95
  # GET /user/scheduled_sends #
98
96
 
99
- response = sg.client.user.scheduled_sends.get()
97
+ response = sg.client.user.scheduled_sends.get
100
98
  puts response.status_code
101
99
  puts response.body
102
100
  puts response.headers
@@ -108,7 +106,7 @@ puts response.headers
108
106
  data = JSON.parse('{
109
107
  "status": "pause"
110
108
  }')
111
- batch_id = "test_url_param"
109
+ batch_id = 'test_url_param'
112
110
  response = sg.client.user.scheduled_sends._(batch_id).patch(request_body: data)
113
111
  puts response.status_code
114
112
  puts response.body
@@ -118,8 +116,8 @@ puts response.headers
118
116
  # Retrieve scheduled send #
119
117
  # GET /user/scheduled_sends/{batch_id} #
120
118
 
121
- batch_id = "test_url_param"
122
- response = sg.client.user.scheduled_sends._(batch_id).get()
119
+ batch_id = 'test_url_param'
120
+ response = sg.client.user.scheduled_sends._(batch_id).get
123
121
  puts response.status_code
124
122
  puts response.body
125
123
  puts response.headers
@@ -128,8 +126,8 @@ puts response.headers
128
126
  # Delete a cancellation or pause of a scheduled send #
129
127
  # DELETE /user/scheduled_sends/{batch_id} #
130
128
 
131
- batch_id = "test_url_param"
132
- response = sg.client.user.scheduled_sends._(batch_id).delete()
129
+ batch_id = 'test_url_param'
130
+ response = sg.client.user.scheduled_sends._(batch_id).delete
133
131
  puts response.status_code
134
132
  puts response.body
135
133
  puts response.headers
@@ -139,7 +137,7 @@ puts response.headers
139
137
  # PATCH /user/settings/enforced_tls #
140
138
 
141
139
  data = JSON.parse('{
142
- "require_tls": true,
140
+ "require_tls": true,
143
141
  "require_valid_cert": false
144
142
  }')
145
143
  response = sg.client.user.settings.enforced_tls.patch(request_body: data)
@@ -151,7 +149,7 @@ puts response.headers
151
149
  # Retrieve current Enforced TLS settings. #
152
150
  # GET /user/settings/enforced_tls #
153
151
 
154
- response = sg.client.user.settings.enforced_tls.get()
152
+ response = sg.client.user.settings.enforced_tls.get
155
153
  puts response.status_code
156
154
  puts response.body
157
155
  puts response.headers
@@ -172,7 +170,7 @@ puts response.headers
172
170
  # Retrieve your username #
173
171
  # GET /user/username #
174
172
 
175
- response = sg.client.user.username.get()
173
+ response = sg.client.user.username.get
176
174
  puts response.status_code
177
175
  puts response.body
178
176
  puts response.headers
@@ -182,18 +180,18 @@ puts response.headers
182
180
  # PATCH /user/webhooks/event/settings #
183
181
 
184
182
  data = JSON.parse('{
185
- "bounce": true,
186
- "click": true,
187
- "deferred": true,
188
- "delivered": true,
189
- "dropped": true,
190
- "enabled": true,
191
- "group_resubscribe": true,
192
- "group_unsubscribe": true,
193
- "open": true,
194
- "processed": true,
195
- "spam_report": true,
196
- "unsubscribe": true,
183
+ "bounce": true,
184
+ "click": true,
185
+ "deferred": true,
186
+ "delivered": true,
187
+ "dropped": true,
188
+ "enabled": true,
189
+ "group_resubscribe": true,
190
+ "group_unsubscribe": true,
191
+ "open": true,
192
+ "processed": true,
193
+ "spam_report": true,
194
+ "unsubscribe": true,
197
195
  "url": "url"
198
196
  }')
199
197
  response = sg.client.user.webhooks.event.settings.patch(request_body: data)
@@ -205,7 +203,7 @@ puts response.headers
205
203
  # Retrieve Event Webhook settings #
206
204
  # GET /user/webhooks/event/settings #
207
205
 
208
- response = sg.client.user.webhooks.event.settings.get()
206
+ response = sg.client.user.webhooks.event.settings.get
209
207
  puts response.status_code
210
208
  puts response.body
211
209
  puts response.headers
@@ -227,9 +225,9 @@ puts response.headers
227
225
  # POST /user/webhooks/parse/settings #
228
226
 
229
227
  data = JSON.parse('{
230
- "hostname": "myhostname.com",
231
- "send_raw": false,
232
- "spam_check": true,
228
+ "hostname": "myhostname.com",
229
+ "send_raw": false,
230
+ "spam_check": true,
233
231
  "url": "http://email.myhosthame.com"
234
232
  }')
235
233
  response = sg.client.user.webhooks.parse.settings.post(request_body: data)
@@ -241,7 +239,7 @@ puts response.headers
241
239
  # Retrieve all parse settings #
242
240
  # GET /user/webhooks/parse/settings #
243
241
 
244
- response = sg.client.user.webhooks.parse.settings.get()
242
+ response = sg.client.user.webhooks.parse.settings.get
245
243
  puts response.status_code
246
244
  puts response.body
247
245
  puts response.headers
@@ -251,11 +249,11 @@ puts response.headers
251
249
  # PATCH /user/webhooks/parse/settings/{hostname} #
252
250
 
253
251
  data = JSON.parse('{
254
- "send_raw": true,
255
- "spam_check": false,
252
+ "send_raw": true,
253
+ "spam_check": false,
256
254
  "url": "http://newdomain.com/parse"
257
255
  }')
258
- hostname = "test_url_param"
256
+ hostname = 'test_url_param'
259
257
  response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body: data)
260
258
  puts response.status_code
261
259
  puts response.body
@@ -265,8 +263,8 @@ puts response.headers
265
263
  # Retrieve a specific parse setting #
266
264
  # GET /user/webhooks/parse/settings/{hostname} #
267
265
 
268
- hostname = "test_url_param"
269
- response = sg.client.user.webhooks.parse.settings._(hostname).get()
266
+ hostname = 'test_url_param'
267
+ response = sg.client.user.webhooks.parse.settings._(hostname).get
270
268
  puts response.status_code
271
269
  puts response.body
272
270
  puts response.headers
@@ -275,8 +273,8 @@ puts response.headers
275
273
  # Delete a parse setting #
276
274
  # DELETE /user/webhooks/parse/settings/{hostname} #
277
275
 
278
- hostname = "test_url_param"
279
- response = sg.client.user.webhooks.parse.settings._(hostname).delete()
276
+ hostname = 'test_url_param'
277
+ response = sg.client.user.webhooks.parse.settings._(hostname).delete
280
278
  puts response.status_code
281
279
  puts response.body
282
280
  puts response.headers
@@ -290,4 +288,3 @@ response = sg.client.user.webhooks.parse.stats.get(query_params: params)
290
288
  puts response.status_code
291
289
  puts response.body
292
290
  puts response.headers
293
-
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ # Middleware that verifies webhooks from SendGrid using the EventWebhook
5
+ # verifier.
6
+ #
7
+ # The middleware takes a public key with which to set up the request
8
+ # validator and any number of paths. When a path matches the incoming request
9
+ # path, the request will be verified using the signature and timestamp of the
10
+ # request.
11
+ #
12
+ # Example:
13
+ #
14
+ # require 'rack'
15
+ # use Rack::SendGridWebhookVerification, ENV['PUBLIC_KEY'], /\/emails/
16
+ #
17
+ # The above appends this middleware to the stack, using a public key saved in
18
+ # the ENV and only against paths that match /\/emails/. If the request
19
+ # validates then it gets passed on to the action as normal. If the request
20
+ # doesn't validate then the middleware responds immediately with a 403 status.
21
+ class SendGridWebhookVerification
22
+ def initialize(app, public_key, *paths)
23
+ @app = app
24
+ @public_key = public_key
25
+ @path_regex = Regexp.union(paths)
26
+ end
27
+
28
+ def call(env)
29
+ return @app.call(env) unless env['PATH_INFO'].match(@path_regex)
30
+
31
+ request = Rack::Request.new(env)
32
+
33
+ event_webhook = SendGrid::EventWebhook.new
34
+ ec_public_key = event_webhook.convert_public_key_to_ecdsa(@public_key)
35
+ verified = event_webhook.verify_signature(
36
+ ec_public_key,
37
+ request.body.read,
38
+ request.env[SendGrid::EventWebhookHeader::SIGNATURE],
39
+ request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
40
+ )
41
+
42
+ request.body.rewind
43
+
44
+ if verified
45
+ @app.call(env)
46
+ else
47
+ [
48
+ 403,
49
+ { 'Content-Type' => 'text/plain' },
50
+ ['SendGrid Request Verification Failed.']
51
+ ]
52
+ end
53
+ end
54
+ end
55
+ end