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,15 +1,13 @@
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 Custom Field #
9
7
  # POST /contactdb/custom_fields #
10
8
 
11
9
  data = JSON.parse('{
12
- "name": "pet",
10
+ "name": "pet",
13
11
  "type": "text"
14
12
  }')
15
13
  response = sg.client.contactdb.custom_fields.post(request_body: data)
@@ -21,7 +19,7 @@ puts response.headers
21
19
  # Retrieve all custom fields #
22
20
  # GET /contactdb/custom_fields #
23
21
 
24
- response = sg.client.contactdb.custom_fields.get()
22
+ response = sg.client.contactdb.custom_fields.get
25
23
  puts response.status_code
26
24
  puts response.body
27
25
  puts response.headers
@@ -30,8 +28,8 @@ puts response.headers
30
28
  # Retrieve a Custom Field #
31
29
  # GET /contactdb/custom_fields/{custom_field_id} #
32
30
 
33
- custom_field_id = "test_url_param"
34
- response = sg.client.contactdb.custom_fields._(custom_field_id).get()
31
+ custom_field_id = 'test_url_param'
32
+ response = sg.client.contactdb.custom_fields._(custom_field_id).get
35
33
  puts response.status_code
36
34
  puts response.body
37
35
  puts response.headers
@@ -40,8 +38,8 @@ puts response.headers
40
38
  # Delete a Custom Field #
41
39
  # DELETE /contactdb/custom_fields/{custom_field_id} #
42
40
 
43
- custom_field_id = "test_url_param"
44
- response = sg.client.contactdb.custom_fields._(custom_field_id).delete()
41
+ custom_field_id = 'test_url_param'
42
+ response = sg.client.contactdb.custom_fields._(custom_field_id).delete
45
43
  puts response.status_code
46
44
  puts response.body
47
45
  puts response.headers
@@ -62,7 +60,7 @@ puts response.headers
62
60
  # Retrieve all lists #
63
61
  # GET /contactdb/lists #
64
62
 
65
- response = sg.client.contactdb.lists.get()
63
+ response = sg.client.contactdb.lists.get
66
64
  puts response.status_code
67
65
  puts response.body
68
66
  puts response.headers
@@ -72,9 +70,9 @@ puts response.headers
72
70
  # DELETE /contactdb/lists #
73
71
 
74
72
  data = JSON.parse('[
75
- 1,
76
- 2,
77
- 3,
73
+ 1,
74
+ 2,
75
+ 3,
78
76
  4
79
77
  ]')
80
78
  response = sg.client.contactdb.lists.delete(request_body: data)
@@ -90,7 +88,7 @@ data = JSON.parse('{
90
88
  "name": "newlistname"
91
89
  }')
92
90
  params = JSON.parse('{"list_id": 1}')
93
- list_id = "test_url_param"
91
+ list_id = 'test_url_param'
94
92
  response = sg.client.contactdb.lists._(list_id).patch(request_body: data, query_params: params)
95
93
  puts response.status_code
96
94
  puts response.body
@@ -101,7 +99,7 @@ puts response.headers
101
99
  # GET /contactdb/lists/{list_id} #
102
100
 
103
101
  params = JSON.parse('{"list_id": 1}')
104
- list_id = "test_url_param"
102
+ list_id = 'test_url_param'
105
103
  response = sg.client.contactdb.lists._(list_id).get(query_params: params)
106
104
  puts response.status_code
107
105
  puts response.body
@@ -112,7 +110,7 @@ puts response.headers
112
110
  # DELETE /contactdb/lists/{list_id} #
113
111
 
114
112
  params = JSON.parse('{"delete_contacts": "true"}')
115
- list_id = "test_url_param"
113
+ list_id = 'test_url_param'
116
114
  response = sg.client.contactdb.lists._(list_id).delete(query_params: params)
117
115
  puts response.status_code
118
116
  puts response.body
@@ -123,10 +121,10 @@ puts response.headers
123
121
  # POST /contactdb/lists/{list_id}/recipients #
124
122
 
125
123
  data = JSON.parse('[
126
- "recipient_id1",
124
+ "recipient_id1",
127
125
  "recipient_id2"
128
126
  ]')
129
- list_id = "test_url_param"
127
+ list_id = 'test_url_param'
130
128
  response = sg.client.contactdb.lists._(list_id).recipients.post(request_body: data)
131
129
  puts response.status_code
132
130
  puts response.body
@@ -137,7 +135,7 @@ puts response.headers
137
135
  # GET /contactdb/lists/{list_id}/recipients #
138
136
 
139
137
  params = JSON.parse('{"page": 1, "page_size": 1, "list_id": 1}')
140
- list_id = "test_url_param"
138
+ list_id = 'test_url_param'
141
139
  response = sg.client.contactdb.lists._(list_id).recipients.get(query_params: params)
142
140
  puts response.status_code
143
141
  puts response.body
@@ -147,9 +145,9 @@ puts response.headers
147
145
  # Add a Single Recipient to a List #
148
146
  # POST /contactdb/lists/{list_id}/recipients/{recipient_id} #
149
147
 
150
- list_id = "test_url_param"
151
- recipient_id = "test_url_param"
152
- response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post()
148
+ list_id = 'test_url_param'
149
+ recipient_id = 'test_url_param'
150
+ response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post
153
151
  puts response.status_code
154
152
  puts response.body
155
153
  puts response.headers
@@ -159,8 +157,8 @@ puts response.headers
159
157
  # DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} #
160
158
 
161
159
  params = JSON.parse('{"recipient_id": 1, "list_id": 1}')
162
- list_id = "test_url_param"
163
- recipient_id = "test_url_param"
160
+ list_id = 'test_url_param'
161
+ recipient_id = 'test_url_param'
164
162
  response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params: params)
165
163
  puts response.status_code
166
164
  puts response.body
@@ -172,8 +170,8 @@ puts response.headers
172
170
 
173
171
  data = JSON.parse('[
174
172
  {
175
- "email": "jones@example.com",
176
- "first_name": "Guy",
173
+ "email": "jones@example.com",
174
+ "first_name": "Guy",
177
175
  "last_name": "Jones"
178
176
  }
179
177
  ]')
@@ -188,15 +186,15 @@ puts response.headers
188
186
 
189
187
  data = JSON.parse('[
190
188
  {
191
- "age": 25,
192
- "email": "example@example.com",
193
- "first_name": "",
189
+ "age": 25,
190
+ "email": "example@example.com",
191
+ "first_name": "",
194
192
  "last_name": "User"
195
- },
193
+ },
196
194
  {
197
- "age": 25,
198
- "email": "example2@example.com",
199
- "first_name": "Example",
195
+ "age": 25,
196
+ "email": "example2@example.com",
197
+ "first_name": "Example",
200
198
  "last_name": "User"
201
199
  }
202
200
  ]')
@@ -220,7 +218,7 @@ puts response.headers
220
218
  # DELETE /contactdb/recipients #
221
219
 
222
220
  data = JSON.parse('[
223
- "recipient_id1",
221
+ "recipient_id1",
224
222
  "recipient_id2"
225
223
  ]')
226
224
  response = sg.client.contactdb.recipients.delete(request_body: data)
@@ -232,7 +230,7 @@ puts response.headers
232
230
  # Retrieve the count of billable recipients #
233
231
  # GET /contactdb/recipients/billable_count #
234
232
 
235
- response = sg.client.contactdb.recipients.billable_count.get()
233
+ response = sg.client.contactdb.recipients.billable_count.get
236
234
  puts response.status_code
237
235
  puts response.body
238
236
  puts response.headers
@@ -241,7 +239,7 @@ puts response.headers
241
239
  # Retrieve a Count of Recipients #
242
240
  # GET /contactdb/recipients/count #
243
241
 
244
- response = sg.client.contactdb.recipients.count.get()
242
+ response = sg.client.contactdb.recipients.count.get
245
243
  puts response.status_code
246
244
  puts response.body
247
245
  puts response.headers
@@ -260,8 +258,8 @@ puts response.headers
260
258
  # Retrieve a single recipient #
261
259
  # GET /contactdb/recipients/{recipient_id} #
262
260
 
263
- recipient_id = "test_url_param"
264
- response = sg.client.contactdb.recipients._(recipient_id).get()
261
+ recipient_id = 'test_url_param'
262
+ response = sg.client.contactdb.recipients._(recipient_id).get
265
263
  puts response.status_code
266
264
  puts response.body
267
265
  puts response.headers
@@ -270,8 +268,8 @@ puts response.headers
270
268
  # Delete a Recipient #
271
269
  # DELETE /contactdb/recipients/{recipient_id} #
272
270
 
273
- recipient_id = "test_url_param"
274
- response = sg.client.contactdb.recipients._(recipient_id).delete()
271
+ recipient_id = 'test_url_param'
272
+ response = sg.client.contactdb.recipients._(recipient_id).delete
275
273
  puts response.status_code
276
274
  puts response.body
277
275
  puts response.headers
@@ -280,8 +278,8 @@ puts response.headers
280
278
  # Retrieve the lists that a recipient is on #
281
279
  # GET /contactdb/recipients/{recipient_id}/lists #
282
280
 
283
- recipient_id = "test_url_param"
284
- response = sg.client.contactdb.recipients._(recipient_id).lists.get()
281
+ recipient_id = 'test_url_param'
282
+ response = sg.client.contactdb.recipients._(recipient_id).lists.get
285
283
  puts response.status_code
286
284
  puts response.body
287
285
  puts response.headers
@@ -290,7 +288,7 @@ puts response.headers
290
288
  # Retrieve reserved fields #
291
289
  # GET /contactdb/reserved_fields #
292
290
 
293
- response = sg.client.contactdb.reserved_fields.get()
291
+ response = sg.client.contactdb.reserved_fields.get
294
292
  puts response.status_code
295
293
  puts response.body
296
294
  puts response.headers
@@ -302,25 +300,25 @@ puts response.headers
302
300
  data = JSON.parse('{
303
301
  "conditions": [
304
302
  {
305
- "and_or": "",
306
- "field": "last_name",
307
- "operator": "eq",
303
+ "and_or": "",
304
+ "field": "last_name",
305
+ "operator": "eq",
308
306
  "value": "Miller"
309
- },
307
+ },
310
308
  {
311
- "and_or": "and",
312
- "field": "last_clicked",
313
- "operator": "gt",
309
+ "and_or": "and",
310
+ "field": "last_clicked",
311
+ "operator": "gt",
314
312
  "value": "01/02/2015"
315
- },
313
+ },
316
314
  {
317
- "and_or": "or",
318
- "field": "clicks.campaign_identifier",
319
- "operator": "eq",
315
+ "and_or": "or",
316
+ "field": "clicks.campaign_identifier",
317
+ "operator": "eq",
320
318
  "value": "513"
321
319
  }
322
- ],
323
- "list_id": 4,
320
+ ],
321
+ "list_id": 4,
324
322
  "name": "Last Name Miller"
325
323
  }')
326
324
  response = sg.client.contactdb.segments.post(request_body: data)
@@ -332,7 +330,7 @@ puts response.headers
332
330
  # Retrieve all segments #
333
331
  # GET /contactdb/segments #
334
332
 
335
- response = sg.client.contactdb.segments.get()
333
+ response = sg.client.contactdb.segments.get
336
334
  puts response.status_code
337
335
  puts response.body
338
336
  puts response.headers
@@ -344,17 +342,17 @@ puts response.headers
344
342
  data = JSON.parse('{
345
343
  "conditions": [
346
344
  {
347
- "and_or": "",
348
- "field": "last_name",
349
- "operator": "eq",
345
+ "and_or": "",
346
+ "field": "last_name",
347
+ "operator": "eq",
350
348
  "value": "Miller"
351
349
  }
352
- ],
353
- "list_id": 5,
350
+ ],
351
+ "list_id": 5,
354
352
  "name": "The Millers"
355
353
  }')
356
354
  params = JSON.parse('{"segment_id": "test_string"}')
357
- segment_id = "test_url_param"
355
+ segment_id = 'test_url_param'
358
356
  response = sg.client.contactdb.segments._(segment_id).patch(request_body: data, query_params: params)
359
357
  puts response.status_code
360
358
  puts response.body
@@ -365,7 +363,7 @@ puts response.headers
365
363
  # GET /contactdb/segments/{segment_id} #
366
364
 
367
365
  params = JSON.parse('{"segment_id": 1}')
368
- segment_id = "test_url_param"
366
+ segment_id = 'test_url_param'
369
367
  response = sg.client.contactdb.segments._(segment_id).get(query_params: params)
370
368
  puts response.status_code
371
369
  puts response.body
@@ -376,7 +374,7 @@ puts response.headers
376
374
  # DELETE /contactdb/segments/{segment_id} #
377
375
 
378
376
  params = JSON.parse('{"delete_contacts": "true"}')
379
- segment_id = "test_url_param"
377
+ segment_id = 'test_url_param'
380
378
  response = sg.client.contactdb.segments._(segment_id).delete(query_params: params)
381
379
  puts response.status_code
382
380
  puts response.body
@@ -387,9 +385,8 @@ puts response.headers
387
385
  # GET /contactdb/segments/{segment_id}/recipients #
388
386
 
389
387
  params = JSON.parse('{"page": 1, "page_size": 1}')
390
- segment_id = "test_url_param"
388
+ segment_id = 'test_url_param'
391
389
  response = sg.client.contactdb.segments._(segment_id).recipients.get(query_params: params)
392
390
  puts response.status_code
393
391
  puts response.body
394
392
  puts response.headers
395
-
@@ -0,0 +1,48 @@
1
+ require 'sendgrid-ruby'
2
+
3
+ # Example 1
4
+ # Sending using "global" data residency
5
+
6
+ from = SendGrid::Email.new(email: 'example@abc.com')
7
+ to = SendGrid::Email.new(email: 'example@abc.com')
8
+ subject = 'Sending with Twilio SendGrid is Fun'
9
+ content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
10
+ mail = SendGrid::Mail.new(from, subject, to, content)
11
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
12
+ sg.sendgrid_data_residency(region: "global")
13
+ puts sg.host
14
+ response = sg.client.mail._('send').post(request_body: mail.to_json)
15
+ puts response.status_code
16
+ puts response.body
17
+ puts response.headers
18
+
19
+ # Example 2
20
+ # Sending using "eu" data residency
21
+
22
+ from = SendGrid::Email.new(email: 'example@abc.com')
23
+ to = SendGrid::Email.new(email: 'example@abc.com')
24
+ subject = 'Sending with Twilio SendGrid is Fun'
25
+ content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
26
+ mail = SendGrid::Mail.new(from, subject, to, content)
27
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY_EU'])
28
+ sg.sendgrid_data_residency(region: 'eu')
29
+ puts sg.host
30
+ response = sg.client.mail._('send').post(request_body: mail.to_json)
31
+ puts response.status_code
32
+ puts response.body
33
+ puts response.headers
34
+
35
+ # Example 3
36
+ # Sending using no data residency
37
+
38
+ from = SendGrid::Email.new(email: 'example@abc.com')
39
+ to = SendGrid::Email.new(email: 'example@abc.com')
40
+ subject = 'Sending with Twilio SendGrid is Fun'
41
+ content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
42
+ mail = SendGrid::Mail.new(from, subject, to, content)
43
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
44
+ puts sg.host
45
+ response = sg.client.mail._('send').post(request_body: mail.to_json)
46
+ puts response.status_code
47
+ puts response.body
48
+ puts response.headers
@@ -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 email statistics by device type. #
9
7
  # GET /devices/stats #
@@ -13,4 +11,3 @@ response = sg.client.devices.stats.get(query_params: params)
13
11
  puts response.status_code
14
12
  puts response.body
15
13
  puts response.headers
16
-
@@ -0,0 +1,52 @@
1
+ require 'sendgrid-ruby'
2
+
3
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
4
+
5
+ ##################################################
6
+ # Filter all messages #
7
+ # GET /messages #
8
+
9
+ require 'erb'
10
+
11
+ filter_key = 'to_email'
12
+ filter_operator = ERB::Util.url_encode('=')
13
+ filter_value = 'testing@sendgrid.net'
14
+ filter_value = ERB::Util.url_encode(format('"%s"', filter_value))
15
+ query_params = {}
16
+ query_params['query'] = format("%s%s%s", filter_key, filter_operator, filter_value)
17
+ query_params['limit'] = '1'
18
+
19
+ params = query_params
20
+ response = sg.client.messages.get(query_params: params)
21
+ puts response.status_code
22
+ puts response.body
23
+ puts response.headers
24
+
25
+ ##################################################
26
+ # Filter messages by message ID #
27
+ # GET /messages/{msg_id} #
28
+
29
+ msg_id = "test_url_param"
30
+ response = sg.client.messages._(msg_id).get
31
+ puts response.status_code
32
+ puts response.body
33
+ puts response.headers
34
+
35
+ ##################################################
36
+ # Request a CSV #
37
+ # POST /messages/download #
38
+
39
+ response = sg.client.messages.download.post
40
+ puts response.status_code
41
+ puts response.body
42
+ puts response.headers
43
+
44
+ ##################################################
45
+ # Download CSV #
46
+ # GET /messages/download/{download_uuid} #
47
+
48
+ download_uuid = "test_url_param"
49
+ response = sg.client.messages.download._(download_uuid).get
50
+ puts response.status_code
51
+ puts response.body
52
+ puts response.headers
data/examples/geo/geo.rb CHANGED
@@ -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 email statistics by country and state/province. #
9
7
  # GET /geo/stats #
@@ -13,4 +11,3 @@ response = sg.client.geo.stats.get(query_params: params)
13
11
  puts response.status_code
14
12
  puts response.body
15
13
  puts response.headers
16
-
@@ -0,0 +1,16 @@
1
+ require 'sengrid-ruby'
2
+ include SendGrid
3
+
4
+ def is_valid_signature(request)
5
+ public_key = 'base64-encoded public key'
6
+
7
+ event_webhook = SendGrid::EventWebhook.new
8
+ ec_public_key = event_webhook.convert_public_key_to_ecdsa(public_key)
9
+
10
+ event_webhook.verify_signature(
11
+ ec_public_key,
12
+ request.body.read,
13
+ request.env[SendGrid::EventWebhookHeader::SIGNATURE],
14
+ request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
15
+ )
16
+ end
@@ -4,24 +4,25 @@ require 'json'
4
4
 
5
5
  def hello_world
6
6
  from = Email.new(email: 'test@example.com')
7
- subject = 'Hello World from the SendGrid Ruby Library'
7
+ subject = 'Hello World from the Twilio SendGrid Ruby Library'
8
8
  to = Email.new(email: 'test@example.com')
9
9
  content = Content.new(type: 'text/plain', value: 'some text here')
10
- mail = Mail.new(from, subject, to, content)
10
+ mail = SendGrid::Mail.new(from, subject, to, content)
11
11
  # puts JSON.pretty_generate(mail.to_json)
12
12
  puts mail.to_json
13
13
 
14
- sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'], host: 'https://api.sendgrid.com')
14
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
15
15
  response = sg.client.mail._('send').post(request_body: mail.to_json)
16
16
  puts response.status_code
17
17
  puts response.body
18
18
  puts response.headers
19
19
  end
20
20
 
21
+ # rubocop:disable Metrics/AbcSize
21
22
  def kitchen_sink
22
- mail = Mail.new
23
+ mail = SendGrid::Mail.new
23
24
  mail.from = Email.new(email: 'test@example.com')
24
- mail.subject = 'Hello World from the SendGrid Ruby Library'
25
+ mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
25
26
  personalization = Personalization.new
26
27
  personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
27
28
  personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
@@ -29,14 +30,17 @@ def kitchen_sink
29
30
  personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
30
31
  personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
31
32
  personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
32
- personalization.subject = 'Hello World from the Personalized SendGrid Ruby Library'
33
+ # Note, the domain of the from email property specified in any personalization must
34
+ # match the domain of the from email property specified at root level
35
+ personalization.add_from(Email.new(email: 'alias@example.com', name: "My alias"))
36
+ personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
33
37
  personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
34
38
  personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
35
39
  personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
36
40
  personalization.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
37
41
  personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
38
42
  personalization.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
39
- personalization.send_at = 1443636843
43
+ personalization.send_at = 1_443_636_843
40
44
  mail.add_personalization(personalization)
41
45
 
42
46
  personalization2 = Personalization.new
@@ -46,14 +50,14 @@ def kitchen_sink
46
50
  personalization2.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
47
51
  personalization2.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
48
52
  personalization2.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
49
- personalization2.subject = 'Hello World from the Personalized SendGrid Ruby Library'
53
+ personalization2.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
50
54
  personalization2.add_header(Header.new(key: 'X-Test', value: 'True'))
51
55
  personalization2.add_header(Header.new(key: 'X-Mock', value: 'False'))
52
56
  personalization2.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
53
57
  personalization2.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
54
58
  personalization2.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
55
59
  personalization2.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
56
- personalization2.send_at = 1443636843
60
+ personalization2.send_at = 1_443_636_843
57
61
  mail.add_personalization(personalization2)
58
62
 
59
63
  mail.add_content(Content.new(type: 'text/plain', value: 'some text here'))
@@ -89,12 +93,12 @@ def kitchen_sink
89
93
  mail.add_custom_arg(CustomArg.new(key: 'campaign', value: 'welcome'))
90
94
  mail.add_custom_arg(CustomArg.new(key: 'weekday', value: 'morning'))
91
95
 
92
- mail.send_at = 1443636842
96
+ mail.send_at = 1_443_636_842
93
97
 
94
98
  # This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work
95
99
  # mail.batch_id = 'sendgrid_batch_id'
96
100
 
97
- mail.asm = ASM.new(group_id: 99, groups_to_display: [4,5,6,7,8])
101
+ mail.asm = ASM.new(group_id: 99, groups_to_display: [4, 5, 6, 7, 8])
98
102
 
99
103
  mail.ip_pool_name = '23'
100
104
 
@@ -118,30 +122,37 @@ def kitchen_sink
118
122
  # puts JSON.pretty_generate(mail.to_json)
119
123
  puts mail.to_json
120
124
 
121
- sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'], host: 'https://api.sendgrid.com')
125
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
122
126
  response = sg.client.mail._('send').post(request_body: mail.to_json)
123
127
  puts response.status_code
124
128
  puts response.body
125
129
  puts response.headers
126
130
  end
131
+ # rubocop:enable Metrics/AbcSize
127
132
 
128
133
  def dynamic_template_data_hello_world
129
134
  mail = Mail.new
130
135
  mail.template_id = '' # a non-legacy template id
131
136
  mail.from = Email.new(email: 'test@example.com')
132
- subject = 'Dynamic Template Data Hello World from the SendGrid Ruby Library'
133
- mail.subject = subject
134
137
  personalization = Personalization.new
135
138
  personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
136
- personalization.add_dynamic_template_data({
137
- "variable" => [
138
- {"foo" => "bar"}, {"foo" => "baz"}
139
+ personalization.add_dynamic_template_data(
140
+ 'variable' => [
141
+ { 'foo' => 'bar' }, { 'foo' => 'baz' }
139
142
  ]
140
- })
143
+ )
141
144
  mail.add_personalization(personalization)
145
+
146
+ # puts JSON.pretty_generate(mail.to_json)
147
+ puts mail.to_json
148
+
149
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
150
+ response = sg.client.mail._('send').post(request_body: mail.to_json)
151
+ puts response.status_code
152
+ puts response.body
153
+ puts response.headers
142
154
  end
143
155
 
144
156
  hello_world
145
157
  kitchen_sink
146
158
  dynamic_template_data_hello_world
147
-
@@ -11,7 +11,7 @@ puts response.body
11
11
  puts response.headers
12
12
 
13
13
  # Turn on bcc settings
14
- response = settings.update_bcc(enabled: true, email: "email@example.com")
14
+ response = settings.update_bcc(enabled: true, email: 'email@example.com')
15
15
  puts response.status_code
16
16
  puts response.body
17
17
  puts response.headers
@@ -7,14 +7,14 @@ sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
7
7
  stats = SendGrid::EmailStats.new(sendgrid_client: sg_client)
8
8
 
9
9
  # Fetch stats by day, between 2 dates
10
- from = Date.new(2017, 10, 01)
10
+ from = Date.new(2017, 10, 1)
11
11
  to = Date.new(2017, 10, 12)
12
12
 
13
13
  email_stats = stats.by_day(from, to)
14
14
 
15
15
  email_stats.metrics
16
16
 
17
- if !email_stats.error?
17
+ unless email_stats.error?
18
18
  email_stats.metrics.each do |metric|
19
19
  puts "Date - #{metric.date}"
20
20
  puts "Number of Requests - #{metric.requests}"
@@ -25,13 +25,13 @@ if !email_stats.error?
25
25
  end
26
26
 
27
27
  # Fetch stats by week, between 2 dates for a category
28
- from = Date.new(2017, 10, 01)
28
+ from = Date.new(2017, 10, 1)
29
29
  to = Date.new(2017, 10, 12)
30
30
  category = 'abcd'
31
31
 
32
32
  email_stats = stats.by_week(from, to, category)
33
33
 
34
- if !email_stats.error?
34
+ unless email_stats.error?
35
35
  email_stats.metrics.each do |metric|
36
36
  puts "Date - #{metric.date}"
37
37
  puts "Number of Requests - #{metric.requests}"