sendgrid-ruby 1.1.6 → 6.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +21 -0
- data/.env_sample +1 -3
- data/.gitignore +1 -0
- data/.travis.yml +28 -17
- data/CHANGELOG.md +231 -1
- data/CODE_OF_CONDUCT.md +73 -0
- data/CONTRIBUTING.md +214 -0
- data/Gemfile +5 -4
- data/ISSUE_TEMPLATE.md +26 -0
- data/LICENSE.md +21 -0
- data/Makefile +7 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +161 -225
- data/Rakefile +9 -2
- data/TROUBLESHOOTING.md +137 -0
- data/UPGRADE.md +5 -0
- data/USAGE.md +5037 -0
- data/USE_CASES.md +377 -0
- data/config.ru +4 -0
- data/docker/Dockerfile +12 -0
- data/docker/README.md +30 -0
- data/examples/accesssettings/accesssettings.rb +83 -0
- data/examples/alerts/alerts.rb +62 -0
- data/examples/apikeys/apikeys.rb +84 -0
- data/examples/asm/asm.rb +173 -0
- data/examples/browsers/browsers.rb +16 -0
- data/examples/campaigns/campaigns.rb +153 -0
- data/examples/categories/categories.rb +36 -0
- data/examples/clients/clients.rb +27 -0
- data/examples/contactdb/contactdb.rb +395 -0
- data/examples/devices/devices.rb +16 -0
- data/examples/geo/geo.rb +16 -0
- data/examples/helpers/mail/example.rb +147 -0
- data/examples/helpers/settings/example.rb +23 -0
- data/examples/helpers/stats/example.rb +42 -0
- data/examples/ips/ips.rb +167 -0
- data/examples/mail/mail.rb +173 -0
- data/examples/mailboxproviders/mailboxproviders.rb +16 -0
- data/examples/mailsettings/mailsettings.rb +219 -0
- data/examples/partnersettings/partnersettings.rb +39 -0
- data/examples/scopes/scopes.rb +61 -0
- data/examples/senderauthentication/senderauthentication.rb +310 -0
- data/examples/senders/senders.rb +98 -0
- data/examples/stats/stats.rb +16 -0
- data/examples/subusers/subusers.rb +169 -0
- data/examples/suppression/suppression.rb +201 -0
- data/examples/templates/templates.rb +129 -0
- data/examples/trackingsettings/trackingsettings.rb +110 -0
- data/examples/user/user.rb +293 -0
- data/gemfiles/Sinatra_1.gemfile +6 -0
- data/gemfiles/Sinatra_2.gemfile +6 -0
- data/lib/sendgrid/client.rb +33 -57
- data/lib/sendgrid/helpers/inbound/README.md +98 -0
- data/lib/sendgrid/helpers/inbound/app.rb +32 -0
- data/lib/sendgrid/helpers/inbound/config.yml +26 -0
- data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
- data/lib/sendgrid/helpers/inbound/send.rb +26 -0
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +14 -0
- data/lib/sendgrid/helpers/mail/asm.rb +33 -0
- data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
- data/lib/sendgrid/helpers/mail/category.rb +20 -0
- data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/content.rb +20 -0
- data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
- data/lib/sendgrid/helpers/mail/email.rb +29 -0
- data/lib/sendgrid/helpers/mail/footer.rb +43 -0
- data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
- data/lib/sendgrid/helpers/mail/header.rb +24 -0
- data/lib/sendgrid/helpers/mail/mail.rb +140 -0
- data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
- data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
- data/lib/sendgrid/helpers/mail/section.rb +24 -0
- data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
- data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
- data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
- data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
- data/lib/sendgrid/helpers/settings/README.md +14 -0
- data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/settings.rb +28 -0
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
- data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
- data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
- data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
- data/lib/sendgrid/version.rb +1 -1
- data/lib/sendgrid-ruby.rb +27 -6
- data/mail_helper_v3.md +390 -0
- data/sendgrid-ruby.gemspec +13 -17
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
- data/spec/spec_helper.rb +10 -1
- data/test/prism.sh +42 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
- data/test/sendgrid/helpers/mail/test_category.rb +27 -0
- data/test/sendgrid/helpers/mail/test_email.rb +34 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +261 -0
- data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
- data/test/sendgrid/permissions/test_scopes.rb +38 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +2751 -0
- metadata +149 -115
- data/.rspec +0 -2
- data/.rubocop.yml +0 -30
- data/FETCH_HEAD +0 -0
- data/Guardfile +0 -10
- data/LICENSE.txt +0 -22
- data/example.rb +0 -41
- data/lib/sendgrid/exceptions.rb +0 -7
- data/lib/sendgrid/mail.rb +0 -182
- data/lib/sendgrid/recipient.rb +0 -29
- data/lib/sendgrid/response.rb +0 -14
- data/lib/sendgrid/template.rb +0 -26
- data/lib/sendgrid/template_mailer.rb +0 -59
- data/spec/lib/sendgrid/client_spec.rb +0 -87
- data/spec/lib/sendgrid/mail_spec.rb +0 -151
- data/spec/lib/sendgrid/recipient_spec.rb +0 -91
- data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
- data/spec/lib/sendgrid/template_spec.rb +0 -61
- data/spec/lib/sendgrid_spec.rb +0 -7
@@ -0,0 +1,395 @@
|
|
1
|
+
require 'sendgrid-ruby'
|
2
|
+
|
3
|
+
|
4
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
|
+
|
6
|
+
|
7
|
+
##################################################
|
8
|
+
# Create a Custom Field #
|
9
|
+
# POST /contactdb/custom_fields #
|
10
|
+
|
11
|
+
data = JSON.parse('{
|
12
|
+
"name": "pet",
|
13
|
+
"type": "text"
|
14
|
+
}')
|
15
|
+
response = sg.client.contactdb.custom_fields.post(request_body: data)
|
16
|
+
puts response.status_code
|
17
|
+
puts response.body
|
18
|
+
puts response.headers
|
19
|
+
|
20
|
+
##################################################
|
21
|
+
# Retrieve all custom fields #
|
22
|
+
# GET /contactdb/custom_fields #
|
23
|
+
|
24
|
+
response = sg.client.contactdb.custom_fields.get()
|
25
|
+
puts response.status_code
|
26
|
+
puts response.body
|
27
|
+
puts response.headers
|
28
|
+
|
29
|
+
##################################################
|
30
|
+
# Retrieve a Custom Field #
|
31
|
+
# GET /contactdb/custom_fields/{custom_field_id} #
|
32
|
+
|
33
|
+
custom_field_id = "test_url_param"
|
34
|
+
response = sg.client.contactdb.custom_fields._(custom_field_id).get()
|
35
|
+
puts response.status_code
|
36
|
+
puts response.body
|
37
|
+
puts response.headers
|
38
|
+
|
39
|
+
##################################################
|
40
|
+
# Delete a Custom Field #
|
41
|
+
# DELETE /contactdb/custom_fields/{custom_field_id} #
|
42
|
+
|
43
|
+
custom_field_id = "test_url_param"
|
44
|
+
response = sg.client.contactdb.custom_fields._(custom_field_id).delete()
|
45
|
+
puts response.status_code
|
46
|
+
puts response.body
|
47
|
+
puts response.headers
|
48
|
+
|
49
|
+
##################################################
|
50
|
+
# Create a List #
|
51
|
+
# POST /contactdb/lists #
|
52
|
+
|
53
|
+
data = JSON.parse('{
|
54
|
+
"name": "your list name"
|
55
|
+
}')
|
56
|
+
response = sg.client.contactdb.lists.post(request_body: data)
|
57
|
+
puts response.status_code
|
58
|
+
puts response.body
|
59
|
+
puts response.headers
|
60
|
+
|
61
|
+
##################################################
|
62
|
+
# Retrieve all lists #
|
63
|
+
# GET /contactdb/lists #
|
64
|
+
|
65
|
+
response = sg.client.contactdb.lists.get()
|
66
|
+
puts response.status_code
|
67
|
+
puts response.body
|
68
|
+
puts response.headers
|
69
|
+
|
70
|
+
##################################################
|
71
|
+
# Delete Multiple lists #
|
72
|
+
# DELETE /contactdb/lists #
|
73
|
+
|
74
|
+
data = JSON.parse('[
|
75
|
+
1,
|
76
|
+
2,
|
77
|
+
3,
|
78
|
+
4
|
79
|
+
]')
|
80
|
+
response = sg.client.contactdb.lists.delete(request_body: data)
|
81
|
+
puts response.status_code
|
82
|
+
puts response.body
|
83
|
+
puts response.headers
|
84
|
+
|
85
|
+
##################################################
|
86
|
+
# Update a List #
|
87
|
+
# PATCH /contactdb/lists/{list_id} #
|
88
|
+
|
89
|
+
data = JSON.parse('{
|
90
|
+
"name": "newlistname"
|
91
|
+
}')
|
92
|
+
params = JSON.parse('{"list_id": 1}')
|
93
|
+
list_id = "test_url_param"
|
94
|
+
response = sg.client.contactdb.lists._(list_id).patch(request_body: data, query_params: params)
|
95
|
+
puts response.status_code
|
96
|
+
puts response.body
|
97
|
+
puts response.headers
|
98
|
+
|
99
|
+
##################################################
|
100
|
+
# Retrieve a single list #
|
101
|
+
# GET /contactdb/lists/{list_id} #
|
102
|
+
|
103
|
+
params = JSON.parse('{"list_id": 1}')
|
104
|
+
list_id = "test_url_param"
|
105
|
+
response = sg.client.contactdb.lists._(list_id).get(query_params: params)
|
106
|
+
puts response.status_code
|
107
|
+
puts response.body
|
108
|
+
puts response.headers
|
109
|
+
|
110
|
+
##################################################
|
111
|
+
# Delete a List #
|
112
|
+
# DELETE /contactdb/lists/{list_id} #
|
113
|
+
|
114
|
+
params = JSON.parse('{"delete_contacts": "true"}')
|
115
|
+
list_id = "test_url_param"
|
116
|
+
response = sg.client.contactdb.lists._(list_id).delete(query_params: params)
|
117
|
+
puts response.status_code
|
118
|
+
puts response.body
|
119
|
+
puts response.headers
|
120
|
+
|
121
|
+
##################################################
|
122
|
+
# Add Multiple Recipients to a List #
|
123
|
+
# POST /contactdb/lists/{list_id}/recipients #
|
124
|
+
|
125
|
+
data = JSON.parse('[
|
126
|
+
"recipient_id1",
|
127
|
+
"recipient_id2"
|
128
|
+
]')
|
129
|
+
list_id = "test_url_param"
|
130
|
+
response = sg.client.contactdb.lists._(list_id).recipients.post(request_body: data)
|
131
|
+
puts response.status_code
|
132
|
+
puts response.body
|
133
|
+
puts response.headers
|
134
|
+
|
135
|
+
##################################################
|
136
|
+
# Retrieve all recipients on a List #
|
137
|
+
# GET /contactdb/lists/{list_id}/recipients #
|
138
|
+
|
139
|
+
params = JSON.parse('{"page": 1, "page_size": 1, "list_id": 1}')
|
140
|
+
list_id = "test_url_param"
|
141
|
+
response = sg.client.contactdb.lists._(list_id).recipients.get(query_params: params)
|
142
|
+
puts response.status_code
|
143
|
+
puts response.body
|
144
|
+
puts response.headers
|
145
|
+
|
146
|
+
##################################################
|
147
|
+
# Add a Single Recipient to a List #
|
148
|
+
# POST /contactdb/lists/{list_id}/recipients/{recipient_id} #
|
149
|
+
|
150
|
+
list_id = "test_url_param"
|
151
|
+
recipient_id = "test_url_param"
|
152
|
+
response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post()
|
153
|
+
puts response.status_code
|
154
|
+
puts response.body
|
155
|
+
puts response.headers
|
156
|
+
|
157
|
+
##################################################
|
158
|
+
# Delete a Single Recipient from a Single List #
|
159
|
+
# DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} #
|
160
|
+
|
161
|
+
params = JSON.parse('{"recipient_id": 1, "list_id": 1}')
|
162
|
+
list_id = "test_url_param"
|
163
|
+
recipient_id = "test_url_param"
|
164
|
+
response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params: params)
|
165
|
+
puts response.status_code
|
166
|
+
puts response.body
|
167
|
+
puts response.headers
|
168
|
+
|
169
|
+
##################################################
|
170
|
+
# Update Recipient #
|
171
|
+
# PATCH /contactdb/recipients #
|
172
|
+
|
173
|
+
data = JSON.parse('[
|
174
|
+
{
|
175
|
+
"email": "jones@example.com",
|
176
|
+
"first_name": "Guy",
|
177
|
+
"last_name": "Jones"
|
178
|
+
}
|
179
|
+
]')
|
180
|
+
response = sg.client.contactdb.recipients.patch(request_body: data)
|
181
|
+
puts response.status_code
|
182
|
+
puts response.body
|
183
|
+
puts response.headers
|
184
|
+
|
185
|
+
##################################################
|
186
|
+
# Add recipients #
|
187
|
+
# POST /contactdb/recipients #
|
188
|
+
|
189
|
+
data = JSON.parse('[
|
190
|
+
{
|
191
|
+
"age": 25,
|
192
|
+
"email": "example@example.com",
|
193
|
+
"first_name": "",
|
194
|
+
"last_name": "User"
|
195
|
+
},
|
196
|
+
{
|
197
|
+
"age": 25,
|
198
|
+
"email": "example2@example.com",
|
199
|
+
"first_name": "Example",
|
200
|
+
"last_name": "User"
|
201
|
+
}
|
202
|
+
]')
|
203
|
+
response = sg.client.contactdb.recipients.post(request_body: data)
|
204
|
+
puts response.status_code
|
205
|
+
puts response.body
|
206
|
+
puts response.headers
|
207
|
+
|
208
|
+
##################################################
|
209
|
+
# Retrieve recipients #
|
210
|
+
# GET /contactdb/recipients #
|
211
|
+
|
212
|
+
params = JSON.parse('{"page": 1, "page_size": 1}')
|
213
|
+
response = sg.client.contactdb.recipients.get(query_params: params)
|
214
|
+
puts response.status_code
|
215
|
+
puts response.body
|
216
|
+
puts response.headers
|
217
|
+
|
218
|
+
##################################################
|
219
|
+
# Delete Recipient #
|
220
|
+
# DELETE /contactdb/recipients #
|
221
|
+
|
222
|
+
data = JSON.parse('[
|
223
|
+
"recipient_id1",
|
224
|
+
"recipient_id2"
|
225
|
+
]')
|
226
|
+
response = sg.client.contactdb.recipients.delete(request_body: data)
|
227
|
+
puts response.status_code
|
228
|
+
puts response.body
|
229
|
+
puts response.headers
|
230
|
+
|
231
|
+
##################################################
|
232
|
+
# Retrieve the count of billable recipients #
|
233
|
+
# GET /contactdb/recipients/billable_count #
|
234
|
+
|
235
|
+
response = sg.client.contactdb.recipients.billable_count.get()
|
236
|
+
puts response.status_code
|
237
|
+
puts response.body
|
238
|
+
puts response.headers
|
239
|
+
|
240
|
+
##################################################
|
241
|
+
# Retrieve a Count of Recipients #
|
242
|
+
# GET /contactdb/recipients/count #
|
243
|
+
|
244
|
+
response = sg.client.contactdb.recipients.count.get()
|
245
|
+
puts response.status_code
|
246
|
+
puts response.body
|
247
|
+
puts response.headers
|
248
|
+
|
249
|
+
##################################################
|
250
|
+
# Retrieve recipients matching search criteria #
|
251
|
+
# GET /contactdb/recipients/search #
|
252
|
+
|
253
|
+
params = JSON.parse('{"{field_name}": "test_string"}')
|
254
|
+
response = sg.client.contactdb.recipients.search.get(query_params: params)
|
255
|
+
puts response.status_code
|
256
|
+
puts response.body
|
257
|
+
puts response.headers
|
258
|
+
|
259
|
+
##################################################
|
260
|
+
# Retrieve a single recipient #
|
261
|
+
# GET /contactdb/recipients/{recipient_id} #
|
262
|
+
|
263
|
+
recipient_id = "test_url_param"
|
264
|
+
response = sg.client.contactdb.recipients._(recipient_id).get()
|
265
|
+
puts response.status_code
|
266
|
+
puts response.body
|
267
|
+
puts response.headers
|
268
|
+
|
269
|
+
##################################################
|
270
|
+
# Delete a Recipient #
|
271
|
+
# DELETE /contactdb/recipients/{recipient_id} #
|
272
|
+
|
273
|
+
recipient_id = "test_url_param"
|
274
|
+
response = sg.client.contactdb.recipients._(recipient_id).delete()
|
275
|
+
puts response.status_code
|
276
|
+
puts response.body
|
277
|
+
puts response.headers
|
278
|
+
|
279
|
+
##################################################
|
280
|
+
# Retrieve the lists that a recipient is on #
|
281
|
+
# GET /contactdb/recipients/{recipient_id}/lists #
|
282
|
+
|
283
|
+
recipient_id = "test_url_param"
|
284
|
+
response = sg.client.contactdb.recipients._(recipient_id).lists.get()
|
285
|
+
puts response.status_code
|
286
|
+
puts response.body
|
287
|
+
puts response.headers
|
288
|
+
|
289
|
+
##################################################
|
290
|
+
# Retrieve reserved fields #
|
291
|
+
# GET /contactdb/reserved_fields #
|
292
|
+
|
293
|
+
response = sg.client.contactdb.reserved_fields.get()
|
294
|
+
puts response.status_code
|
295
|
+
puts response.body
|
296
|
+
puts response.headers
|
297
|
+
|
298
|
+
##################################################
|
299
|
+
# Create a Segment #
|
300
|
+
# POST /contactdb/segments #
|
301
|
+
|
302
|
+
data = JSON.parse('{
|
303
|
+
"conditions": [
|
304
|
+
{
|
305
|
+
"and_or": "",
|
306
|
+
"field": "last_name",
|
307
|
+
"operator": "eq",
|
308
|
+
"value": "Miller"
|
309
|
+
},
|
310
|
+
{
|
311
|
+
"and_or": "and",
|
312
|
+
"field": "last_clicked",
|
313
|
+
"operator": "gt",
|
314
|
+
"value": "01/02/2015"
|
315
|
+
},
|
316
|
+
{
|
317
|
+
"and_or": "or",
|
318
|
+
"field": "clicks.campaign_identifier",
|
319
|
+
"operator": "eq",
|
320
|
+
"value": "513"
|
321
|
+
}
|
322
|
+
],
|
323
|
+
"list_id": 4,
|
324
|
+
"name": "Last Name Miller"
|
325
|
+
}')
|
326
|
+
response = sg.client.contactdb.segments.post(request_body: data)
|
327
|
+
puts response.status_code
|
328
|
+
puts response.body
|
329
|
+
puts response.headers
|
330
|
+
|
331
|
+
##################################################
|
332
|
+
# Retrieve all segments #
|
333
|
+
# GET /contactdb/segments #
|
334
|
+
|
335
|
+
response = sg.client.contactdb.segments.get()
|
336
|
+
puts response.status_code
|
337
|
+
puts response.body
|
338
|
+
puts response.headers
|
339
|
+
|
340
|
+
##################################################
|
341
|
+
# Update a segment #
|
342
|
+
# PATCH /contactdb/segments/{segment_id} #
|
343
|
+
|
344
|
+
data = JSON.parse('{
|
345
|
+
"conditions": [
|
346
|
+
{
|
347
|
+
"and_or": "",
|
348
|
+
"field": "last_name",
|
349
|
+
"operator": "eq",
|
350
|
+
"value": "Miller"
|
351
|
+
}
|
352
|
+
],
|
353
|
+
"list_id": 5,
|
354
|
+
"name": "The Millers"
|
355
|
+
}')
|
356
|
+
params = JSON.parse('{"segment_id": "test_string"}')
|
357
|
+
segment_id = "test_url_param"
|
358
|
+
response = sg.client.contactdb.segments._(segment_id).patch(request_body: data, query_params: params)
|
359
|
+
puts response.status_code
|
360
|
+
puts response.body
|
361
|
+
puts response.headers
|
362
|
+
|
363
|
+
##################################################
|
364
|
+
# Retrieve a segment #
|
365
|
+
# GET /contactdb/segments/{segment_id} #
|
366
|
+
|
367
|
+
params = JSON.parse('{"segment_id": 1}')
|
368
|
+
segment_id = "test_url_param"
|
369
|
+
response = sg.client.contactdb.segments._(segment_id).get(query_params: params)
|
370
|
+
puts response.status_code
|
371
|
+
puts response.body
|
372
|
+
puts response.headers
|
373
|
+
|
374
|
+
##################################################
|
375
|
+
# Delete a segment #
|
376
|
+
# DELETE /contactdb/segments/{segment_id} #
|
377
|
+
|
378
|
+
params = JSON.parse('{"delete_contacts": "true"}')
|
379
|
+
segment_id = "test_url_param"
|
380
|
+
response = sg.client.contactdb.segments._(segment_id).delete(query_params: params)
|
381
|
+
puts response.status_code
|
382
|
+
puts response.body
|
383
|
+
puts response.headers
|
384
|
+
|
385
|
+
##################################################
|
386
|
+
# Retrieve recipients on a segment #
|
387
|
+
# GET /contactdb/segments/{segment_id}/recipients #
|
388
|
+
|
389
|
+
params = JSON.parse('{"page": 1, "page_size": 1}')
|
390
|
+
segment_id = "test_url_param"
|
391
|
+
response = sg.client.contactdb.segments._(segment_id).recipients.get(query_params: params)
|
392
|
+
puts response.status_code
|
393
|
+
puts response.body
|
394
|
+
puts response.headers
|
395
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sendgrid-ruby'
|
2
|
+
|
3
|
+
|
4
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
|
+
|
6
|
+
|
7
|
+
##################################################
|
8
|
+
# Retrieve email statistics by device type. #
|
9
|
+
# GET /devices/stats #
|
10
|
+
|
11
|
+
params = JSON.parse('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}')
|
12
|
+
response = sg.client.devices.stats.get(query_params: params)
|
13
|
+
puts response.status_code
|
14
|
+
puts response.body
|
15
|
+
puts response.headers
|
16
|
+
|
data/examples/geo/geo.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sendgrid-ruby'
|
2
|
+
|
3
|
+
|
4
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
|
+
|
6
|
+
|
7
|
+
##################################################
|
8
|
+
# Retrieve email statistics by country and state/province. #
|
9
|
+
# GET /geo/stats #
|
10
|
+
|
11
|
+
params = JSON.parse('{"end_date": "2016-04-01", "country": "US", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}')
|
12
|
+
response = sg.client.geo.stats.get(query_params: params)
|
13
|
+
puts response.status_code
|
14
|
+
puts response.body
|
15
|
+
puts response.headers
|
16
|
+
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'sendgrid-ruby'
|
2
|
+
include SendGrid
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
def hello_world
|
6
|
+
from = Email.new(email: 'test@example.com')
|
7
|
+
subject = 'Hello World from the Twilio SendGrid Ruby Library'
|
8
|
+
to = Email.new(email: 'test@example.com')
|
9
|
+
content = Content.new(type: 'text/plain', value: 'some text here')
|
10
|
+
mail = SendGrid::Mail.new(from, subject, to, content)
|
11
|
+
# puts JSON.pretty_generate(mail.to_json)
|
12
|
+
puts mail.to_json
|
13
|
+
|
14
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'], host: 'https://api.sendgrid.com')
|
15
|
+
response = sg.client.mail._('send').post(request_body: mail.to_json)
|
16
|
+
puts response.status_code
|
17
|
+
puts response.body
|
18
|
+
puts response.headers
|
19
|
+
end
|
20
|
+
|
21
|
+
def kitchen_sink
|
22
|
+
mail = SendGrid::Mail.new
|
23
|
+
mail.from = Email.new(email: 'test@example.com')
|
24
|
+
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
|
25
|
+
personalization = Personalization.new
|
26
|
+
personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
27
|
+
personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
|
28
|
+
personalization.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
|
29
|
+
personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
|
30
|
+
personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
|
31
|
+
personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
|
32
|
+
personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby 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
|
40
|
+
mail.add_personalization(personalization)
|
41
|
+
|
42
|
+
personalization2 = Personalization.new
|
43
|
+
personalization2.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
44
|
+
personalization2.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
|
45
|
+
personalization2.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
|
46
|
+
personalization2.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
|
47
|
+
personalization2.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
|
48
|
+
personalization2.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
|
49
|
+
personalization2.subject = 'Hello World from the Personalized Twilio SendGrid Ruby 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
|
57
|
+
mail.add_personalization(personalization2)
|
58
|
+
|
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>'))
|
61
|
+
|
62
|
+
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'
|
68
|
+
mail.add_attachment(attachment)
|
69
|
+
|
70
|
+
attachment2 = Attachment.new
|
71
|
+
attachment2.content = 'BwdW'
|
72
|
+
attachment2.type = 'image/png'
|
73
|
+
attachment2.filename = 'banner.png'
|
74
|
+
attachment2.disposition = 'inline'
|
75
|
+
attachment2.content_id = 'Banner'
|
76
|
+
mail.add_attachment(attachment2)
|
77
|
+
|
78
|
+
mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
|
79
|
+
|
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'))
|
82
|
+
|
83
|
+
mail.add_header(Header.new(key: 'X-Test3', value: 'test3'))
|
84
|
+
mail.add_header(Header.new(key: 'X-Test4', value: 'test4'))
|
85
|
+
|
86
|
+
mail.add_category(Category.new(name: 'May'))
|
87
|
+
mail.add_category(Category.new(name: '2016'))
|
88
|
+
|
89
|
+
mail.add_custom_arg(CustomArg.new(key: 'campaign', value: 'welcome'))
|
90
|
+
mail.add_custom_arg(CustomArg.new(key: 'weekday', value: 'morning'))
|
91
|
+
|
92
|
+
mail.send_at = 1443636842
|
93
|
+
|
94
|
+
# This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work
|
95
|
+
# mail.batch_id = 'sendgrid_batch_id'
|
96
|
+
|
97
|
+
mail.asm = ASM.new(group_id: 99, groups_to_display: [4,5,6,7,8])
|
98
|
+
|
99
|
+
mail.ip_pool_name = '23'
|
100
|
+
|
101
|
+
mail_settings = MailSettings.new
|
102
|
+
mail_settings.bcc = BccSettings.new(enable: true, email: 'test@example.com')
|
103
|
+
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>')
|
105
|
+
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')
|
107
|
+
mail.mail_settings = mail_settings
|
108
|
+
|
109
|
+
tracking_settings = TrackingSettings.new
|
110
|
+
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')
|
114
|
+
mail.tracking_settings = tracking_settings
|
115
|
+
|
116
|
+
mail.reply_to = Email.new(email: 'test@example.com')
|
117
|
+
|
118
|
+
# puts JSON.pretty_generate(mail.to_json)
|
119
|
+
puts mail.to_json
|
120
|
+
|
121
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'], host: 'https://api.sendgrid.com')
|
122
|
+
response = sg.client.mail._('send').post(request_body: mail.to_json)
|
123
|
+
puts response.status_code
|
124
|
+
puts response.body
|
125
|
+
puts response.headers
|
126
|
+
end
|
127
|
+
|
128
|
+
def dynamic_template_data_hello_world
|
129
|
+
mail = Mail.new
|
130
|
+
mail.template_id = '' # a non-legacy template id
|
131
|
+
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
|
+
personalization = Personalization.new
|
135
|
+
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
|
+
]
|
140
|
+
})
|
141
|
+
mail.add_personalization(personalization)
|
142
|
+
end
|
143
|
+
|
144
|
+
hello_world
|
145
|
+
kitchen_sink
|
146
|
+
dynamic_template_data_hello_world
|
147
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'sendgrid-ruby'
|
2
|
+
include SendGrid
|
3
|
+
|
4
|
+
sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
|
5
|
+
settings = SendGrid::Settings.new(sendgrid_client: sg_client)
|
6
|
+
|
7
|
+
# Fetch settings
|
8
|
+
response = settings.bcc
|
9
|
+
puts response.status_code
|
10
|
+
puts response.body
|
11
|
+
puts response.headers
|
12
|
+
|
13
|
+
# Turn on bcc settings
|
14
|
+
response = settings.update_bcc(enabled: true, email: "email@example.com")
|
15
|
+
puts response.status_code
|
16
|
+
puts response.body
|
17
|
+
puts response.headers
|
18
|
+
|
19
|
+
# Turn off bcc settings
|
20
|
+
response = settings.update_bcc(enabled: false)
|
21
|
+
puts response.status_code
|
22
|
+
puts response.body
|
23
|
+
puts response.headers
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'sendgrid-ruby'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
include SendGrid
|
5
|
+
|
6
|
+
sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
|
7
|
+
stats = SendGrid::EmailStats.new(sendgrid_client: sg_client)
|
8
|
+
|
9
|
+
# Fetch stats by day, between 2 dates
|
10
|
+
from = Date.new(2017, 10, 01)
|
11
|
+
to = Date.new(2017, 10, 12)
|
12
|
+
|
13
|
+
email_stats = stats.by_day(from, to)
|
14
|
+
|
15
|
+
email_stats.metrics
|
16
|
+
|
17
|
+
if !email_stats.error?
|
18
|
+
email_stats.metrics.each do |metric|
|
19
|
+
puts "Date - #{metric.date}"
|
20
|
+
puts "Number of Requests - #{metric.requests}"
|
21
|
+
puts "Bounces - #{metric.bounces}"
|
22
|
+
puts "Opens - #{metric.opens}"
|
23
|
+
puts "Clicks - #{metric.clicks}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Fetch stats by week, between 2 dates for a category
|
28
|
+
from = Date.new(2017, 10, 01)
|
29
|
+
to = Date.new(2017, 10, 12)
|
30
|
+
category = 'abcd'
|
31
|
+
|
32
|
+
email_stats = stats.by_week(from, to, category)
|
33
|
+
|
34
|
+
if !email_stats.error?
|
35
|
+
email_stats.metrics.each do |metric|
|
36
|
+
puts "Date - #{metric.date}"
|
37
|
+
puts "Number of Requests - #{metric.requests}"
|
38
|
+
puts "Bounces - #{metric.bounces}"
|
39
|
+
puts "Opens - #{metric.opens}"
|
40
|
+
puts "Clicks - #{metric.clicks}"
|
41
|
+
end
|
42
|
+
end
|