sendgrid-ruby 1.1.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE +17 -0
  3. data/.travis.yml +1 -6
  4. data/CHANGELOG.md +6 -0
  5. data/CONTRIBUTING.md +202 -0
  6. data/Gemfile +3 -5
  7. data/LICENSE.txt +1 -1
  8. data/README.md +74 -248
  9. data/Rakefile +8 -6
  10. data/USAGE.md +4645 -0
  11. data/examples/accesssettings/accesssettings.rb +89 -0
  12. data/examples/apikeys/apikeys.rb +95 -0
  13. data/examples/asm/asm.rb +169 -0
  14. data/examples/browsers/browsers.rb +29 -0
  15. data/examples/campaigns/campaigns.rb +166 -0
  16. data/examples/categories/categories.rb +49 -0
  17. data/examples/clients/clients.rb +40 -0
  18. data/examples/contactdb/contactdb.rb +398 -0
  19. data/examples/devices/devices.rb +29 -0
  20. data/examples/geo/geo.rb +29 -0
  21. data/examples/helpers/mail/example.rb +130 -0
  22. data/examples/ips/ips.rb +167 -0
  23. data/examples/mail/mail.rb +191 -0
  24. data/examples/mailboxproviders/mailboxproviders.rb +29 -0
  25. data/examples/mailsettings/mailsettings.rb +232 -0
  26. data/examples/partnersettings/partnersettings.rb +52 -0
  27. data/examples/scopes/scopes.rb +28 -0
  28. data/examples/stats/stats.rb +29 -0
  29. data/examples/subusers/subusers.rb +182 -0
  30. data/examples/suppression/suppression.rb +186 -0
  31. data/examples/templates/templates.rb +142 -0
  32. data/examples/trackingsettings/trackingsettings.rb +123 -0
  33. data/examples/user/user.rb +256 -0
  34. data/examples/whitelabel/whitelabel.rb +323 -0
  35. data/lib/helpers/mail/README.md +14 -0
  36. data/lib/helpers/mail/mail.rb +999 -0
  37. data/lib/sendgrid-ruby.rb +33 -8
  38. data/sendgrid-ruby.gemspec +5 -17
  39. data/test/helpers/mail/test_mail.rb +122 -0
  40. data/test/test_sendgrid-ruby.rb +2016 -0
  41. metadata +42 -190
  42. data/.env_sample +0 -3
  43. data/.rspec +0 -2
  44. data/.rubocop.yml +0 -30
  45. data/FETCH_HEAD +0 -0
  46. data/Guardfile +0 -10
  47. data/example.rb +0 -41
  48. data/lib/sendgrid/client.rb +0 -62
  49. data/lib/sendgrid/exceptions.rb +0 -7
  50. data/lib/sendgrid/mail.rb +0 -182
  51. data/lib/sendgrid/recipient.rb +0 -29
  52. data/lib/sendgrid/response.rb +0 -14
  53. data/lib/sendgrid/template.rb +0 -26
  54. data/lib/sendgrid/template_mailer.rb +0 -59
  55. data/lib/sendgrid/version.rb +0 -3
  56. data/spec/lib/sendgrid/client_spec.rb +0 -87
  57. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  58. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  59. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  60. data/spec/lib/sendgrid/template_spec.rb +0 -61
  61. data/spec/lib/sendgrid_spec.rb +0 -7
  62. data/spec/spec_helper.rb +0 -1
@@ -0,0 +1,49 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ import com.fasterxml.jackson.databind.JsonNode;
8
+ import com.fasterxml.jackson.databind.ObjectMapper;
9
+
10
+ import com.sendgrid.Client;
11
+ import com.sendgrid.Method;
12
+ import com.sendgrid.Request;
13
+ import com.sendgrid.Response;
14
+ import com.sendgrid.SendGrid;
15
+
16
+ import java.io.IOException;
17
+ import java.util.HashMap;
18
+ import java.util.Map;
19
+
20
+ ##################################################
21
+ # Retrieve all categories #
22
+ # GET /categories #
23
+
24
+ params = JSON.parse('{"category": "test_string", "limit": 1, "offset": 1}')
25
+ response = sg.client.categories.get(query_params: params)
26
+ puts response.status_code
27
+ puts response.body
28
+ puts response.headers
29
+
30
+ ##################################################
31
+ # Retrieve Email Statistics for Categories #
32
+ # GET /categories/stats #
33
+
34
+ params = JSON.parse('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "categories": "test_string"}')
35
+ response = sg.client.categories.stats.get(query_params: params)
36
+ puts response.status_code
37
+ puts response.body
38
+ puts response.headers
39
+
40
+ ##################################################
41
+ # Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] #
42
+ # GET /categories/stats/sums #
43
+
44
+ params = JSON.parse('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}')
45
+ response = sg.client.categories.stats.sums.get(query_params: params)
46
+ puts response.status_code
47
+ puts response.body
48
+ puts response.headers
49
+
@@ -0,0 +1,40 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ import com.fasterxml.jackson.databind.JsonNode;
8
+ import com.fasterxml.jackson.databind.ObjectMapper;
9
+
10
+ import com.sendgrid.Client;
11
+ import com.sendgrid.Method;
12
+ import com.sendgrid.Request;
13
+ import com.sendgrid.Response;
14
+ import com.sendgrid.SendGrid;
15
+
16
+ import java.io.IOException;
17
+ import java.util.HashMap;
18
+ import java.util.Map;
19
+
20
+ ##################################################
21
+ # Retrieve email statistics by client type. #
22
+ # GET /clients/stats #
23
+
24
+ params = JSON.parse('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}')
25
+ response = sg.client.clients.stats.get(query_params: params)
26
+ puts response.status_code
27
+ puts response.body
28
+ puts response.headers
29
+
30
+ ##################################################
31
+ # Retrieve stats by a specific client type. #
32
+ # GET /clients/{client_type}/stats #
33
+
34
+ params = JSON.parse('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}')
35
+ client_type = "test_url_param"
36
+ response = sg.client.clients._(client_type).stats.get(query_params: params)
37
+ puts response.status_code
38
+ puts response.body
39
+ puts response.headers
40
+
@@ -0,0 +1,398 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ import com.fasterxml.jackson.databind.JsonNode;
8
+ import com.fasterxml.jackson.databind.ObjectMapper;
9
+
10
+ import com.sendgrid.Client;
11
+ import com.sendgrid.Method;
12
+ import com.sendgrid.Request;
13
+ import com.sendgrid.Response;
14
+ import com.sendgrid.SendGrid;
15
+
16
+ import java.io.IOException;
17
+ import java.util.HashMap;
18
+ import java.util.Map;
19
+
20
+ ##################################################
21
+ # Create a Custom Field #
22
+ # POST /contactdb/custom_fields #
23
+
24
+ data = JSON.parse('{
25
+ "name": "pet",
26
+ "type": "text"
27
+ }')
28
+ response = sg.client.contactdb.custom_fields.post(request_body: data)
29
+ puts response.status_code
30
+ puts response.body
31
+ puts response.headers
32
+
33
+ ##################################################
34
+ # Retrieve all custom fields #
35
+ # GET /contactdb/custom_fields #
36
+
37
+ response = sg.client.contactdb.custom_fields.get()
38
+ puts response.status_code
39
+ puts response.body
40
+ puts response.headers
41
+
42
+ ##################################################
43
+ # Retrieve a Custom Field #
44
+ # GET /contactdb/custom_fields/{custom_field_id} #
45
+
46
+ custom_field_id = "test_url_param"
47
+ response = sg.client.contactdb.custom_fields._(custom_field_id).get()
48
+ puts response.status_code
49
+ puts response.body
50
+ puts response.headers
51
+
52
+ ##################################################
53
+ # Delete a Custom Field #
54
+ # DELETE /contactdb/custom_fields/{custom_field_id} #
55
+
56
+ custom_field_id = "test_url_param"
57
+ response = sg.client.contactdb.custom_fields._(custom_field_id).delete()
58
+ puts response.status_code
59
+ puts response.body
60
+ puts response.headers
61
+
62
+ ##################################################
63
+ # Create a List #
64
+ # POST /contactdb/lists #
65
+
66
+ data = JSON.parse('{
67
+ "name": "your list name"
68
+ }')
69
+ response = sg.client.contactdb.lists.post(request_body: data)
70
+ puts response.status_code
71
+ puts response.body
72
+ puts response.headers
73
+
74
+ ##################################################
75
+ # Retrieve all lists #
76
+ # GET /contactdb/lists #
77
+
78
+ response = sg.client.contactdb.lists.get()
79
+ puts response.status_code
80
+ puts response.body
81
+ puts response.headers
82
+
83
+ ##################################################
84
+ # Delete Multiple lists #
85
+ # DELETE /contactdb/lists #
86
+
87
+ response = sg.client.contactdb.lists.delete(request_body: data)
88
+ puts response.status_code
89
+ puts response.body
90
+ puts response.headers
91
+
92
+ ##################################################
93
+ # Update a List #
94
+ # PATCH /contactdb/lists/{list_id} #
95
+
96
+ data = JSON.parse('{
97
+ "name": "newlistname"
98
+ }')
99
+ params = JSON.parse('{"list_id": 0}')
100
+ list_id = "test_url_param"
101
+ response = sg.client.contactdb.lists._(list_id).patch(request_body: data, query_params: params)
102
+ puts response.status_code
103
+ puts response.body
104
+ puts response.headers
105
+
106
+ ##################################################
107
+ # Retrieve a single list #
108
+ # GET /contactdb/lists/{list_id} #
109
+
110
+ params = JSON.parse('{"list_id": 0}')
111
+ list_id = "test_url_param"
112
+ response = sg.client.contactdb.lists._(list_id).get(query_params: params)
113
+ puts response.status_code
114
+ puts response.body
115
+ puts response.headers
116
+
117
+ ##################################################
118
+ # Delete a List #
119
+ # DELETE /contactdb/lists/{list_id} #
120
+
121
+ params = JSON.parse('{"delete_contacts": "true"}')
122
+ list_id = "test_url_param"
123
+ response = sg.client.contactdb.lists._(list_id).delete(query_params: params)
124
+ puts response.status_code
125
+ puts response.body
126
+ puts response.headers
127
+
128
+ ##################################################
129
+ # Add Multiple Recipients to a List #
130
+ # POST /contactdb/lists/{list_id}/recipients #
131
+
132
+ data = JSON.parse('[
133
+ "recipient_id1",
134
+ "recipient_id2"
135
+ ]')
136
+ list_id = "test_url_param"
137
+ response = sg.client.contactdb.lists._(list_id).recipients.post(request_body: data)
138
+ puts response.status_code
139
+ puts response.body
140
+ puts response.headers
141
+
142
+ ##################################################
143
+ # Retrieve all recipients on a List #
144
+ # GET /contactdb/lists/{list_id}/recipients #
145
+
146
+ params = JSON.parse('{"page": 1, "page_size": 1, "list_id": 0}')
147
+ list_id = "test_url_param"
148
+ response = sg.client.contactdb.lists._(list_id).recipients.get(query_params: params)
149
+ puts response.status_code
150
+ puts response.body
151
+ puts response.headers
152
+
153
+ ##################################################
154
+ # Add a Single Recipient to a List #
155
+ # POST /contactdb/lists/{list_id}/recipients/{recipient_id} #
156
+
157
+ list_id = "test_url_param"
158
+ recipient_id = "test_url_param"
159
+ response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post()
160
+ puts response.status_code
161
+ puts response.body
162
+ puts response.headers
163
+
164
+ ##################################################
165
+ # Delete a Single Recipient from a Single List #
166
+ # DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} #
167
+
168
+ params = JSON.parse('{"recipient_id": 0, "list_id": 0}')
169
+ list_id = "test_url_param"
170
+ recipient_id = "test_url_param"
171
+ response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params: params)
172
+ puts response.status_code
173
+ puts response.body
174
+ puts response.headers
175
+
176
+ ##################################################
177
+ # Update Recipient #
178
+ # PATCH /contactdb/recipients #
179
+
180
+ data = JSON.parse('[
181
+ {
182
+ "email": "jones@example.com",
183
+ "first_name": "Guy",
184
+ "last_name": "Jones"
185
+ }
186
+ ]')
187
+ response = sg.client.contactdb.recipients.patch(request_body: data)
188
+ puts response.status_code
189
+ puts response.body
190
+ puts response.headers
191
+
192
+ ##################################################
193
+ # Add recipients #
194
+ # POST /contactdb/recipients #
195
+
196
+ data = JSON.parse('[
197
+ {
198
+ "age": 25,
199
+ "email": "example@example.com",
200
+ "first_name": "",
201
+ "last_name": "User"
202
+ },
203
+ {
204
+ "age": 25,
205
+ "email": "example2@example.com",
206
+ "first_name": "Example",
207
+ "last_name": "User"
208
+ }
209
+ ]')
210
+ response = sg.client.contactdb.recipients.post(request_body: data)
211
+ puts response.status_code
212
+ puts response.body
213
+ puts response.headers
214
+
215
+ ##################################################
216
+ # Retrieve recipients #
217
+ # GET /contactdb/recipients #
218
+
219
+ params = JSON.parse('{"page": 1, "page_size": 1}')
220
+ response = sg.client.contactdb.recipients.get(query_params: params)
221
+ puts response.status_code
222
+ puts response.body
223
+ puts response.headers
224
+
225
+ ##################################################
226
+ # Delete Recipient #
227
+ # DELETE /contactdb/recipients #
228
+
229
+ response = sg.client.contactdb.recipients.delete(request_body: data)
230
+ puts response.status_code
231
+ puts response.body
232
+ puts response.headers
233
+
234
+ ##################################################
235
+ # Retrieve the count of billable recipients #
236
+ # GET /contactdb/recipients/billable_count #
237
+
238
+ response = sg.client.contactdb.recipients.billable_count.get()
239
+ puts response.status_code
240
+ puts response.body
241
+ puts response.headers
242
+
243
+ ##################################################
244
+ # Retrieve a Count of Recipients #
245
+ # GET /contactdb/recipients/count #
246
+
247
+ response = sg.client.contactdb.recipients.count.get()
248
+ puts response.status_code
249
+ puts response.body
250
+ puts response.headers
251
+
252
+ ##################################################
253
+ # Retrieve recipients matching search criteria #
254
+ # GET /contactdb/recipients/search #
255
+
256
+ params = JSON.parse('{"{field_name}": "test_string"}')
257
+ response = sg.client.contactdb.recipients.search.get(query_params: params)
258
+ puts response.status_code
259
+ puts response.body
260
+ puts response.headers
261
+
262
+ ##################################################
263
+ # Retrieve a single recipient #
264
+ # GET /contactdb/recipients/{recipient_id} #
265
+
266
+ recipient_id = "test_url_param"
267
+ response = sg.client.contactdb.recipients._(recipient_id).get()
268
+ puts response.status_code
269
+ puts response.body
270
+ puts response.headers
271
+
272
+ ##################################################
273
+ # Delete a Recipient #
274
+ # DELETE /contactdb/recipients/{recipient_id} #
275
+
276
+ recipient_id = "test_url_param"
277
+ response = sg.client.contactdb.recipients._(recipient_id).delete()
278
+ puts response.status_code
279
+ puts response.body
280
+ puts response.headers
281
+
282
+ ##################################################
283
+ # Retrieve the lists that a recipient is on #
284
+ # GET /contactdb/recipients/{recipient_id}/lists #
285
+
286
+ recipient_id = "test_url_param"
287
+ response = sg.client.contactdb.recipients._(recipient_id).lists.get()
288
+ puts response.status_code
289
+ puts response.body
290
+ puts response.headers
291
+
292
+ ##################################################
293
+ # Retrieve reserved fields #
294
+ # GET /contactdb/reserved_fields #
295
+
296
+ response = sg.client.contactdb.reserved_fields.get()
297
+ puts response.status_code
298
+ puts response.body
299
+ puts response.headers
300
+
301
+ ##################################################
302
+ # Create a Segment #
303
+ # POST /contactdb/segments #
304
+
305
+ data = JSON.parse('{
306
+ "conditions": [
307
+ {
308
+ "and_or": "",
309
+ "field": "last_name",
310
+ "operator": "eq",
311
+ "value": "Miller"
312
+ },
313
+ {
314
+ "and_or": "and",
315
+ "field": "last_clicked",
316
+ "operator": "gt",
317
+ "value": "01/02/2015"
318
+ },
319
+ {
320
+ "and_or": "or",
321
+ "field": "clicks.campaign_identifier",
322
+ "operator": "eq",
323
+ "value": "513"
324
+ }
325
+ ],
326
+ "list_id": 4,
327
+ "name": "Last Name Miller"
328
+ }')
329
+ response = sg.client.contactdb.segments.post(request_body: data)
330
+ puts response.status_code
331
+ puts response.body
332
+ puts response.headers
333
+
334
+ ##################################################
335
+ # Retrieve all segments #
336
+ # GET /contactdb/segments #
337
+
338
+ response = sg.client.contactdb.segments.get()
339
+ puts response.status_code
340
+ puts response.body
341
+ puts response.headers
342
+
343
+ ##################################################
344
+ # Update a segment #
345
+ # PATCH /contactdb/segments/{segment_id} #
346
+
347
+ data = JSON.parse('{
348
+ "conditions": [
349
+ {
350
+ "and_or": "",
351
+ "field": "last_name",
352
+ "operator": "eq",
353
+ "value": "Miller"
354
+ }
355
+ ],
356
+ "list_id": 5,
357
+ "name": "The Millers"
358
+ }')
359
+ params = JSON.parse('{"segment_id": "test_string"}')
360
+ segment_id = "test_url_param"
361
+ response = sg.client.contactdb.segments._(segment_id).patch(request_body: data, query_params: params)
362
+ puts response.status_code
363
+ puts response.body
364
+ puts response.headers
365
+
366
+ ##################################################
367
+ # Retrieve a segment #
368
+ # GET /contactdb/segments/{segment_id} #
369
+
370
+ params = JSON.parse('{"segment_id": 0}')
371
+ segment_id = "test_url_param"
372
+ response = sg.client.contactdb.segments._(segment_id).get(query_params: params)
373
+ puts response.status_code
374
+ puts response.body
375
+ puts response.headers
376
+
377
+ ##################################################
378
+ # Delete a segment #
379
+ # DELETE /contactdb/segments/{segment_id} #
380
+
381
+ params = JSON.parse('{"delete_contacts": "true"}')
382
+ segment_id = "test_url_param"
383
+ response = sg.client.contactdb.segments._(segment_id).delete(query_params: params)
384
+ puts response.status_code
385
+ puts response.body
386
+ puts response.headers
387
+
388
+ ##################################################
389
+ # Retrieve recipients on a segment #
390
+ # GET /contactdb/segments/{segment_id}/recipients #
391
+
392
+ params = JSON.parse('{"page": 1, "page_size": 1}')
393
+ segment_id = "test_url_param"
394
+ response = sg.client.contactdb.segments._(segment_id).recipients.get(query_params: params)
395
+ puts response.status_code
396
+ puts response.body
397
+ puts response.headers
398
+