sendgrid-ruby 6.2.0 → 6.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/config.yml +10 -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 +147 -9
  8. data/CONTRIBUTING.md +11 -21
  9. data/Dockerfile +14 -0
  10. data/FIRST_TIMERS.md +79 -0
  11. data/Gemfile +0 -1
  12. data/ISSUE_TEMPLATE.md +5 -1
  13. data/{LICENSE.md → LICENSE} +1 -1
  14. data/Makefile +9 -2
  15. data/PULL_REQUEST_TEMPLATE.md +5 -5
  16. data/README.md +23 -31
  17. data/Rakefile +2 -3
  18. data/TROUBLESHOOTING.md +17 -5
  19. data/USAGE.md +146 -39
  20. data/examples/accesssettings/accesssettings.rb +9 -12
  21. data/examples/alerts/alerts.rb +8 -11
  22. data/examples/apikeys/apikeys.rb +12 -15
  23. data/examples/asm/asm.rb +27 -30
  24. data/examples/browsers/browsers.rb +0 -3
  25. data/examples/campaigns/campaigns.rb +29 -32
  26. data/examples/categories/categories.rb +0 -3
  27. data/examples/clients/clients.rb +1 -4
  28. data/examples/contactdb/contactdb.rb +63 -66
  29. data/examples/devices/devices.rb +0 -3
  30. data/examples/emailactivity/emailactivity.rb +52 -0
  31. data/examples/geo/geo.rb +0 -3
  32. data/examples/helpers/eventwebhook/example.rb +16 -0
  33. data/examples/helpers/mail/example.rb +24 -13
  34. data/examples/helpers/settings/example.rb +1 -1
  35. data/examples/helpers/stats/example.rb +4 -4
  36. data/examples/ips/ips.rb +19 -22
  37. data/examples/mail/mail.rb +72 -75
  38. data/examples/mailboxproviders/mailboxproviders.rb +0 -3
  39. data/examples/mailsettings/mailsettings.rb +21 -24
  40. data/examples/partnersettings/partnersettings.rb +3 -6
  41. data/examples/scopes/scopes.rb +8 -10
  42. data/examples/senderauthentication/senderauthentication.rb +41 -44
  43. data/examples/senders/senders.rb +28 -31
  44. data/examples/stats/stats.rb +0 -3
  45. data/examples/subusers/subusers.rb +17 -20
  46. data/examples/suppression/suppression.rb +15 -18
  47. data/examples/templates/templates.rb +29 -31
  48. data/examples/trackingsettings/trackingsettings.rb +14 -17
  49. data/examples/user/user.rb +41 -44
  50. data/lib/rack/sendgrid_webhook_verification.rb +55 -0
  51. data/lib/sendgrid/base_interface.rb +8 -4
  52. data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
  53. data/lib/sendgrid/helpers/inbound/README.md +5 -5
  54. data/lib/sendgrid/helpers/inbound/app.rb +2 -2
  55. data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
  56. data/lib/sendgrid/helpers/inbound/send.rb +3 -3
  57. data/lib/sendgrid/helpers/ip_management/ip_management.rb +1 -1
  58. data/lib/sendgrid/helpers/mail/README.md +3 -3
  59. data/lib/sendgrid/helpers/mail/asm.rb +6 -18
  60. data/lib/sendgrid/helpers/mail/attachment.rb +12 -42
  61. data/lib/sendgrid/helpers/mail/bcc_settings.rb +6 -18
  62. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +8 -18
  63. data/lib/sendgrid/helpers/mail/category.rb +2 -2
  64. data/lib/sendgrid/helpers/mail/click_tracking.rb +6 -18
  65. data/lib/sendgrid/helpers/mail/content.rb +4 -3
  66. data/lib/sendgrid/helpers/mail/custom_arg.rb +6 -10
  67. data/lib/sendgrid/helpers/mail/email.rb +10 -5
  68. data/lib/sendgrid/helpers/mail/footer.rb +7 -27
  69. data/lib/sendgrid/helpers/mail/ganalytics.rb +10 -54
  70. data/lib/sendgrid/helpers/mail/header.rb +6 -10
  71. data/lib/sendgrid/helpers/mail/mail.rb +32 -48
  72. data/lib/sendgrid/helpers/mail/mail_settings.rb +9 -25
  73. data/lib/sendgrid/helpers/mail/open_tracking.rb +6 -18
  74. data/lib/sendgrid/helpers/mail/personalization.rb +40 -27
  75. data/lib/sendgrid/helpers/mail/section.rb +6 -10
  76. data/lib/sendgrid/helpers/mail/spam_check.rb +7 -27
  77. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +8 -36
  78. data/lib/sendgrid/helpers/mail/substitution.rb +6 -10
  79. data/lib/sendgrid/helpers/mail/tracking_settings.rb +8 -20
  80. data/lib/sendgrid/helpers/permissions/scope.rb +2 -2
  81. data/lib/sendgrid/helpers/settings/README.md +2 -2
  82. data/lib/sendgrid/helpers/settings/settings.rb +1 -1
  83. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +3 -5
  84. data/lib/sendgrid/helpers/stats/metrics.rb +5 -5
  85. data/lib/sendgrid/sendgrid.rb +4 -3
  86. data/lib/sendgrid/twilio_email.rb +1 -1
  87. data/lib/sendgrid/version.rb +1 -1
  88. data/lib/sendgrid-ruby.rb +2 -0
  89. data/mail_helper_v3.md +12 -12
  90. data/sendgrid-ruby.gemspec +8 -8
  91. data/spec/fixtures/event_webhook.rb +22 -0
  92. data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
  93. data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
  94. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +3 -3
  95. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +3 -3
  96. data/spec/sendgrid/helpers/settings/settings_spec.rb +2 -2
  97. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +3 -3
  98. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +3 -3
  99. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +22 -23
  100. data/spec/sendgrid/helpers/stats/metrics_spec.rb +19 -20
  101. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +22 -23
  102. data/spec/spec_helper.rb +3 -1
  103. data/static/img/github-fork.png +0 -0
  104. data/static/img/github-sign-up.png +0 -0
  105. data/test/sendgrid/helpers/mail/test_attachment.rb +4 -6
  106. data/test/sendgrid/helpers/mail/test_category.rb +0 -2
  107. data/test/sendgrid/helpers/mail/test_email.rb +17 -10
  108. data/test/sendgrid/helpers/mail/test_mail.rb +101 -102
  109. data/test/sendgrid/helpers/mail/test_personalizations.rb +145 -92
  110. data/test/sendgrid/permissions/test_scopes.rb +1 -3
  111. data/test/sendgrid/test_sendgrid-ruby.rb +1964 -1986
  112. data/twilio_sendgrid_logo.png +0 -0
  113. data/use-cases/README.md +17 -0
  114. data/use-cases/domain-authentication.md +5 -0
  115. data/use-cases/email-statistics.md +52 -0
  116. data/use-cases/legacy-templates.md +98 -0
  117. data/use-cases/personalizations.md +34 -0
  118. data/use-cases/sms.md +39 -0
  119. data/use-cases/transactional-templates.md +111 -0
  120. data/use-cases/twilio-email.md +13 -0
  121. data/use-cases/twilio-setup.md +54 -0
  122. metadata +69 -34
  123. data/.codeclimate.yml +0 -21
  124. data/.travis.yml +0 -40
  125. data/USE_CASES.md +0 -405
  126. data/docker/Dockerfile +0 -12
  127. data/docker/README.md +0 -30
  128. 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
-
@@ -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
@@ -11,13 +11,14 @@ def hello_world
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
23
  mail = SendGrid::Mail.new
23
24
  mail.from = Email.new(email: 'test@example.com')
@@ -29,6 +30,9 @@ 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'))
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"))
32
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'))
@@ -36,7 +40,7 @@ def kitchen_sink
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
@@ -53,7 +57,7 @@ def kitchen_sink
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 Twilio 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}"