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,89 @@
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 recent access attempts #
22
+ # GET /access_settings/activity #
23
+
24
+ params = JSON.parse('{"limit": 1}')
25
+ response = sg.client.access_settings.activity.get(query_params: params)
26
+ puts response.status_code
27
+ puts response.body
28
+ puts response.headers
29
+
30
+ ##################################################
31
+ # Add one or more IPs to the whitelist #
32
+ # POST /access_settings/whitelist #
33
+
34
+ data = JSON.parse('{
35
+ "ips": [
36
+ {
37
+ "ip": "192.168.1.1"
38
+ },
39
+ {
40
+ "ip": "192.*.*.*"
41
+ },
42
+ {
43
+ "ip": "192.168.1.3/32"
44
+ }
45
+ ]
46
+ }')
47
+ response = sg.client.access_settings.whitelist.post(request_body: data)
48
+ puts response.status_code
49
+ puts response.body
50
+ puts response.headers
51
+
52
+ ##################################################
53
+ # Retrieve a list of currently whitelisted IPs #
54
+ # GET /access_settings/whitelist #
55
+
56
+ response = sg.client.access_settings.whitelist.get()
57
+ puts response.status_code
58
+ puts response.body
59
+ puts response.headers
60
+
61
+ ##################################################
62
+ # Remove one or more IPs from the whitelist #
63
+ # DELETE /access_settings/whitelist #
64
+
65
+ response = sg.client.access_settings.whitelist.delete(request_body: data)
66
+ puts response.status_code
67
+ puts response.body
68
+ puts response.headers
69
+
70
+ ##################################################
71
+ # Retrieve a specific whitelisted IP #
72
+ # GET /access_settings/whitelist/{rule_id} #
73
+
74
+ rule_id = "test_url_param"
75
+ response = sg.client.access_settings.whitelist._(rule_id).get()
76
+ puts response.status_code
77
+ puts response.body
78
+ puts response.headers
79
+
80
+ ##################################################
81
+ # Remove a specific IP from the whitelist #
82
+ # DELETE /access_settings/whitelist/{rule_id} #
83
+
84
+ rule_id = "test_url_param"
85
+ response = sg.client.access_settings.whitelist._(rule_id).delete()
86
+ puts response.status_code
87
+ puts response.body
88
+ puts response.headers
89
+
@@ -0,0 +1,95 @@
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 API keys #
22
+ # POST /api_keys #
23
+
24
+ data = JSON.parse('{
25
+ "name": "My API Key",
26
+ "scopes": [
27
+ "mail.send",
28
+ "alerts.create",
29
+ "alerts.read"
30
+ ]
31
+ }')
32
+ response = sg.client.api_keys.post(request_body: data)
33
+ puts response.status_code
34
+ puts response.body
35
+ puts response.headers
36
+
37
+ ##################################################
38
+ # Retrieve all API Keys belonging to the authenticated user #
39
+ # GET /api_keys #
40
+
41
+ response = sg.client.api_keys.get()
42
+ puts response.status_code
43
+ puts response.body
44
+ puts response.headers
45
+
46
+ ##################################################
47
+ # Update the name & scopes of an API Key #
48
+ # PUT /api_keys/{api_key_id} #
49
+
50
+ data = JSON.parse('{
51
+ "name": "A New Hope",
52
+ "scopes": [
53
+ "user.profile.read",
54
+ "user.profile.update"
55
+ ]
56
+ }')
57
+ api_key_id = "test_url_param"
58
+ response = sg.client.api_keys._(api_key_id).put(request_body: data)
59
+ puts response.status_code
60
+ puts response.body
61
+ puts response.headers
62
+
63
+ ##################################################
64
+ # Update API keys #
65
+ # PATCH /api_keys/{api_key_id} #
66
+
67
+ data = JSON.parse('{
68
+ "name": "A New Hope"
69
+ }')
70
+ api_key_id = "test_url_param"
71
+ response = sg.client.api_keys._(api_key_id).patch(request_body: data)
72
+ puts response.status_code
73
+ puts response.body
74
+ puts response.headers
75
+
76
+ ##################################################
77
+ # Retrieve an existing API Key #
78
+ # GET /api_keys/{api_key_id} #
79
+
80
+ api_key_id = "test_url_param"
81
+ response = sg.client.api_keys._(api_key_id).get()
82
+ puts response.status_code
83
+ puts response.body
84
+ puts response.headers
85
+
86
+ ##################################################
87
+ # Delete API keys #
88
+ # DELETE /api_keys/{api_key_id} #
89
+
90
+ api_key_id = "test_url_param"
91
+ response = sg.client.api_keys._(api_key_id).delete()
92
+ puts response.status_code
93
+ puts response.body
94
+ puts response.headers
95
+
@@ -0,0 +1,169 @@
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 new suppression group #
22
+ # POST /asm/groups #
23
+
24
+ data = JSON.parse('{
25
+ "description": "Suggestions for products our users might like.",
26
+ "is_default": true,
27
+ "name": "Product Suggestions"
28
+ }')
29
+ response = sg.client.asm.groups.post(request_body: data)
30
+ puts response.status_code
31
+ puts response.body
32
+ puts response.headers
33
+
34
+ ##################################################
35
+ # Retrieve information about multiple suppression groups #
36
+ # GET /asm/groups #
37
+
38
+ params = JSON.parse('{"id": 1}')
39
+ response = sg.client.asm.groups.get(query_params: params)
40
+ puts response.status_code
41
+ puts response.body
42
+ puts response.headers
43
+
44
+ ##################################################
45
+ # Update a suppression group. #
46
+ # PATCH /asm/groups/{group_id} #
47
+
48
+ data = JSON.parse('{
49
+ "description": "Suggestions for items our users might like.",
50
+ "id": 103,
51
+ "name": "Item Suggestions"
52
+ }')
53
+ group_id = "test_url_param"
54
+ response = sg.client.asm.groups._(group_id).patch(request_body: data)
55
+ puts response.status_code
56
+ puts response.body
57
+ puts response.headers
58
+
59
+ ##################################################
60
+ # Get information on a single suppression group. #
61
+ # GET /asm/groups/{group_id} #
62
+
63
+ group_id = "test_url_param"
64
+ response = sg.client.asm.groups._(group_id).get()
65
+ puts response.status_code
66
+ puts response.body
67
+ puts response.headers
68
+
69
+ ##################################################
70
+ # Delete a suppression group. #
71
+ # DELETE /asm/groups/{group_id} #
72
+
73
+ group_id = "test_url_param"
74
+ response = sg.client.asm.groups._(group_id).delete()
75
+ puts response.status_code
76
+ puts response.body
77
+ puts response.headers
78
+
79
+ ##################################################
80
+ # Add suppressions to a suppression group #
81
+ # POST /asm/groups/{group_id}/suppressions #
82
+
83
+ data = JSON.parse('{
84
+ "recipient_emails": [
85
+ "test1@example.com",
86
+ "test2@example.com"
87
+ ]
88
+ }')
89
+ group_id = "test_url_param"
90
+ response = sg.client.asm.groups._(group_id).suppressions.post(request_body: data)
91
+ puts response.status_code
92
+ puts response.body
93
+ puts response.headers
94
+
95
+ ##################################################
96
+ # Retrieve all suppressions for a suppression group #
97
+ # GET /asm/groups/{group_id}/suppressions #
98
+
99
+ group_id = "test_url_param"
100
+ response = sg.client.asm.groups._(group_id).suppressions.get()
101
+ puts response.status_code
102
+ puts response.body
103
+ puts response.headers
104
+
105
+ ##################################################
106
+ # Delete a suppression from a suppression group #
107
+ # DELETE /asm/groups/{group_id}/suppressions/{email} #
108
+
109
+ group_id = "test_url_param"
110
+ email = "test_url_param"
111
+ response = sg.client.asm.groups._(group_id).suppressions._(email).delete()
112
+ puts response.status_code
113
+ puts response.body
114
+ puts response.headers
115
+
116
+ ##################################################
117
+ # Retrieve all suppressions #
118
+ # GET /asm/suppressions #
119
+
120
+ response = sg.client.asm.suppressions.get()
121
+ puts response.status_code
122
+ puts response.body
123
+ puts response.headers
124
+
125
+ ##################################################
126
+ # Add recipient addresses to the global suppression group. #
127
+ # POST /asm/suppressions/global #
128
+
129
+ data = JSON.parse('{
130
+ "recipient_emails": [
131
+ "test1@example.com",
132
+ "test2@example.com"
133
+ ]
134
+ }')
135
+ response = sg.client.asm.suppressions.global.post(request_body: data)
136
+ puts response.status_code
137
+ puts response.body
138
+ puts response.headers
139
+
140
+ ##################################################
141
+ # Retrieve a Global Suppression #
142
+ # GET /asm/suppressions/global/{email} #
143
+
144
+ email = "test_url_param"
145
+ response = sg.client.asm.suppressions.global._(email).get()
146
+ puts response.status_code
147
+ puts response.body
148
+ puts response.headers
149
+
150
+ ##################################################
151
+ # Delete a Global Suppression #
152
+ # DELETE /asm/suppressions/global/{email} #
153
+
154
+ email = "test_url_param"
155
+ response = sg.client.asm.suppressions.global._(email).delete()
156
+ puts response.status_code
157
+ puts response.body
158
+ puts response.headers
159
+
160
+ ##################################################
161
+ # Retrieve all suppression groups for an email address #
162
+ # GET /asm/suppressions/{email} #
163
+
164
+ email = "test_url_param"
165
+ response = sg.client.asm.suppressions._(email).get()
166
+ puts response.status_code
167
+ puts response.body
168
+ puts response.headers
169
+
@@ -0,0 +1,29 @@
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 browser. #
22
+ # GET /browsers/stats #
23
+
24
+ params = JSON.parse('{"end_date": "2016-04-01", "aggregated_by": "day", "browsers": "test_string", "limit": "test_string", "offset": "test_string", "start_date": "2016-01-01"}')
25
+ response = sg.client.browsers.stats.get(query_params: params)
26
+ puts response.status_code
27
+ puts response.body
28
+ puts response.headers
29
+
@@ -0,0 +1,166 @@
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 Campaign #
22
+ # POST /campaigns #
23
+
24
+ data = JSON.parse('{
25
+ "categories": [
26
+ "spring line"
27
+ ],
28
+ "custom_unsubscribe_url": "",
29
+ "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
30
+ "ip_pool": "marketing",
31
+ "list_ids": [
32
+ 110,
33
+ 124
34
+ ],
35
+ "plain_content": "Check out our spring line!",
36
+ "segment_ids": [
37
+ 110
38
+ ],
39
+ "sender_id": 124451,
40
+ "subject": "New Products for Spring!",
41
+ "suppression_group_id": 42,
42
+ "title": "March Newsletter"
43
+ }')
44
+ response = sg.client.campaigns.post(request_body: data)
45
+ puts response.status_code
46
+ puts response.body
47
+ puts response.headers
48
+
49
+ ##################################################
50
+ # Retrieve all Campaigns #
51
+ # GET /campaigns #
52
+
53
+ params = JSON.parse('{"limit": 0, "offset": 0}')
54
+ response = sg.client.campaigns.get(query_params: params)
55
+ puts response.status_code
56
+ puts response.body
57
+ puts response.headers
58
+
59
+ ##################################################
60
+ # Update a Campaign #
61
+ # PATCH /campaigns/{campaign_id} #
62
+
63
+ data = JSON.parse('{
64
+ "categories": [
65
+ "summer line"
66
+ ],
67
+ "html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
68
+ "plain_content": "Check out our summer line!",
69
+ "subject": "New Products for Summer!",
70
+ "title": "May Newsletter"
71
+ }')
72
+ campaign_id = "test_url_param"
73
+ response = sg.client.campaigns._(campaign_id).patch(request_body: data)
74
+ puts response.status_code
75
+ puts response.body
76
+ puts response.headers
77
+
78
+ ##################################################
79
+ # Retrieve a single campaign #
80
+ # GET /campaigns/{campaign_id} #
81
+
82
+ campaign_id = "test_url_param"
83
+ response = sg.client.campaigns._(campaign_id).get()
84
+ puts response.status_code
85
+ puts response.body
86
+ puts response.headers
87
+
88
+ ##################################################
89
+ # Delete a Campaign #
90
+ # DELETE /campaigns/{campaign_id} #
91
+
92
+ campaign_id = "test_url_param"
93
+ response = sg.client.campaigns._(campaign_id).delete()
94
+ puts response.status_code
95
+ puts response.body
96
+ puts response.headers
97
+
98
+ ##################################################
99
+ # Update a Scheduled Campaign #
100
+ # PATCH /campaigns/{campaign_id}/schedules #
101
+
102
+ data = JSON.parse('{
103
+ "send_at": 1489451436
104
+ }')
105
+ campaign_id = "test_url_param"
106
+ response = sg.client.campaigns._(campaign_id).schedules.patch(request_body: data)
107
+ puts response.status_code
108
+ puts response.body
109
+ puts response.headers
110
+
111
+ ##################################################
112
+ # Schedule a Campaign #
113
+ # POST /campaigns/{campaign_id}/schedules #
114
+
115
+ data = JSON.parse('{
116
+ "send_at": 1489771528
117
+ }')
118
+ campaign_id = "test_url_param"
119
+ response = sg.client.campaigns._(campaign_id).schedules.post(request_body: data)
120
+ puts response.status_code
121
+ puts response.body
122
+ puts response.headers
123
+
124
+ ##################################################
125
+ # View Scheduled Time of a Campaign #
126
+ # GET /campaigns/{campaign_id}/schedules #
127
+
128
+ campaign_id = "test_url_param"
129
+ response = sg.client.campaigns._(campaign_id).schedules.get()
130
+ puts response.status_code
131
+ puts response.body
132
+ puts response.headers
133
+
134
+ ##################################################
135
+ # Unschedule a Scheduled Campaign #
136
+ # DELETE /campaigns/{campaign_id}/schedules #
137
+
138
+ campaign_id = "test_url_param"
139
+ response = sg.client.campaigns._(campaign_id).schedules.delete()
140
+ puts response.status_code
141
+ puts response.body
142
+ puts response.headers
143
+
144
+ ##################################################
145
+ # Send a Campaign #
146
+ # POST /campaigns/{campaign_id}/schedules/now #
147
+
148
+ campaign_id = "test_url_param"
149
+ response = sg.client.campaigns._(campaign_id).schedules.now.post()
150
+ puts response.status_code
151
+ puts response.body
152
+ puts response.headers
153
+
154
+ ##################################################
155
+ # Send a Test Campaign #
156
+ # POST /campaigns/{campaign_id}/schedules/test #
157
+
158
+ data = JSON.parse('{
159
+ "to": "your.email@example.com"
160
+ }')
161
+ campaign_id = "test_url_param"
162
+ response = sg.client.campaigns._(campaign_id).schedules.test.post(request_body: data)
163
+ puts response.status_code
164
+ puts response.body
165
+ puts response.headers
166
+