sendgrid-ruby 4.0.8 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +21 -0
  3. data/.env_sample +1 -0
  4. data/.github/PULL_REQUEST_TEMPLATE +26 -0
  5. data/.gitignore +1 -0
  6. data/.travis.yml +11 -2
  7. data/CHANGELOG.md +119 -3
  8. data/CODE_OF_CONDUCT.md +41 -0
  9. data/CONTRIBUTING.md +34 -30
  10. data/Gemfile +4 -1
  11. data/LICENSE.txt +1 -1
  12. data/README.md +53 -24
  13. data/Rakefile +7 -2
  14. data/TROUBLESHOOTING.md +41 -15
  15. data/UPGRADE.md +5 -0
  16. data/USAGE.md +1130 -1129
  17. data/USE_CASES.md +280 -16
  18. data/config.ru +4 -0
  19. data/docker/Dockerfile +12 -0
  20. data/docker/README.md +30 -0
  21. data/examples/helpers/mail/example.rb +62 -45
  22. data/examples/helpers/settings/example.rb +23 -0
  23. data/examples/helpers/stats/example.rb +42 -0
  24. data/examples/ips/ips.rb +13 -0
  25. data/examples/mail/mail.rb +2 -2
  26. data/examples/scopes/scopes.rb +49 -3
  27. data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +27 -27
  28. data/examples/suppression/suppression.rb +10 -10
  29. data/gemfiles/Sinatra_1.gemfile +6 -0
  30. data/gemfiles/Sinatra_2.gemfile +6 -0
  31. data/lib/sendgrid-ruby.rb +27 -1
  32. data/lib/sendgrid/client.rb +12 -9
  33. data/lib/sendgrid/helpers/inbound/README.md +98 -0
  34. data/lib/sendgrid/helpers/inbound/app.rb +32 -0
  35. data/lib/sendgrid/helpers/inbound/config.yml +26 -0
  36. data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
  37. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
  38. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
  39. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
  40. data/lib/sendgrid/helpers/inbound/send.rb +26 -0
  41. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  42. data/lib/sendgrid/helpers/mail/README.md +1 -1
  43. data/lib/sendgrid/helpers/mail/asm.rb +33 -0
  44. data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
  45. data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
  46. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
  47. data/lib/sendgrid/helpers/mail/category.rb +20 -0
  48. data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
  49. data/lib/sendgrid/helpers/mail/content.rb +20 -0
  50. data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
  51. data/lib/sendgrid/helpers/mail/email.rb +29 -0
  52. data/lib/sendgrid/helpers/mail/footer.rb +43 -0
  53. data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
  54. data/lib/sendgrid/helpers/mail/header.rb +24 -0
  55. data/lib/sendgrid/helpers/mail/mail.rb +36 -895
  56. data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
  57. data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
  58. data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
  59. data/lib/sendgrid/helpers/mail/section.rb +24 -0
  60. data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
  61. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
  62. data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
  63. data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
  64. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  65. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  66. data/lib/sendgrid/helpers/settings/README.md +14 -0
  67. data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
  68. data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
  69. data/lib/sendgrid/helpers/settings/settings.rb +28 -0
  70. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
  71. data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
  72. data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
  73. data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
  74. data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
  75. data/lib/sendgrid/version.rb +2 -2
  76. data/mail_helper_v3.md +390 -0
  77. data/sendgrid-ruby.gemspec +12 -5
  78. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  79. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
  80. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
  81. data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
  82. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
  83. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
  84. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
  85. data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
  86. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
  87. data/spec/spec_helper.rb +10 -0
  88. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  89. data/test/sendgrid/helpers/mail/test_category.rb +27 -0
  90. data/test/sendgrid/helpers/mail/test_email.rb +34 -0
  91. data/test/sendgrid/helpers/mail/test_mail.rb +198 -59
  92. data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
  93. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  94. data/test/sendgrid/test_sendgrid-ruby.rb +90 -9
  95. metadata +170 -10
@@ -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
@@ -23,6 +23,19 @@ puts response.status_code
23
23
  puts response.body
24
24
  puts response.headers
25
25
 
26
+ ##################################################
27
+ # Retrieve unassigned IPs #
28
+ # GET /ips #
29
+
30
+ params = {}
31
+ response = sg.client.ips.get(query_params: params)
32
+ all_ips = JSON.parse(response.body)
33
+ unassigned_ips = all_ips.select {|ip| ip.subusers.empty?}
34
+ puts response.status_code
35
+ puts response.body
36
+ puts unassigned_ips
37
+ puts response.headers
38
+
26
39
  ##################################################
27
40
  # Create an IP pool. #
28
41
  # POST /ips/pools #
@@ -79,8 +79,8 @@ data = JSON.parse('{
79
79
  },
80
80
  "footer": {
81
81
  "enable": true,
82
- "html": "<p>Thanks</br>The SendGrid Team</p>",
83
- "text": "Thanks,/n The SendGrid Team"
82
+ "html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
83
+ "text": "Thanks,/n The Twilio SendGrid Team"
84
84
  },
85
85
  "sandbox_mode": {
86
86
  "enable": false
@@ -1,9 +1,7 @@
1
- require 'sendgrid-ruby'
2
-
1
+ require_relative '../../lib/sendgrid-ruby.rb'
3
2
 
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Retrieve a list of scopes for which this user has access. #
9
7
  # GET /scopes #
@@ -13,3 +11,51 @@ puts response.status_code
13
11
  puts response.body
14
12
  puts response.headers
15
13
 
14
+ ##################################################
15
+ # Update the name & scopes of an API Key #
16
+ # PUT /api_keys/{api_key_id} #
17
+
18
+
19
+ scopes = [
20
+ "user.profile.read",
21
+ "user.profile.update"
22
+ ]
23
+
24
+ data = {
25
+ "name": "A New Hope",
26
+ "scopes": scopes
27
+ }
28
+ api_key_id = "test_url_param"
29
+ response = sg.client.api_keys._(api_key_id).put(request_body: data)
30
+ puts response.status_code
31
+ puts response.body
32
+ puts response.headers
33
+
34
+ # The above method shows how to update the scopes
35
+ # To get various scopes that each of the endpoint has, use the following
36
+
37
+ # To get all admin permissions
38
+ scopes = SendGrid::Scope.admin_permissions
39
+
40
+ # To get all read only permissions
41
+ scopes = SendGrid::Scope.read_only_permissions
42
+
43
+ # There are two methods for each endpoints, namely
44
+ # {endpoint}_read_only_permissions and {endpoint}_full_access_permissions
45
+
46
+ # These are the endpoints :
47
+ # alerts, api_keys, asm_groups, billing, categories, credentials, stats, ips, mail_settings, mail,
48
+ # marketing_campaigns, partner_settings, scheduled_sends, subusers, suppression, teammates,
49
+ # templates, tracking_settings, user_settings, webhooks, whitelabel, access_settings
50
+
51
+ # read only permissions for alerts
52
+ scopes = SendGrid::Scope.alerts_read_only_permissions
53
+
54
+ # full access permissions for alerts
55
+ scopes = SendGrid::Scope.alerts_full_access_permissions
56
+
57
+ # read only permissions for billing
58
+ scopes = SendGrid::Scope.billing_read_only_permissions
59
+
60
+ # full access permissions for billing
61
+ scopes = SendGrid::Scope.billing_full_access_permissions
@@ -5,7 +5,7 @@ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
5
 
6
6
 
7
7
  ##################################################
8
- # Create a domain whitelabel. #
8
+ # Create a domain authentication. #
9
9
  # POST /whitelabel/domains #
10
10
 
11
11
  data = JSON.parse('{
@@ -26,7 +26,7 @@ puts response.body
26
26
  puts response.headers
27
27
 
28
28
  ##################################################
29
- # List all domain whitelabels. #
29
+ # List all domain authentications. #
30
30
  # GET /whitelabel/domains #
31
31
 
32
32
  params = JSON.parse('{"username": "test_string", "domain": "test_string", "exclude_subusers": "true", "limit": 1, "offset": 1}')
@@ -36,7 +36,7 @@ puts response.body
36
36
  puts response.headers
37
37
 
38
38
  ##################################################
39
- # Get the default domain whitelabel. #
39
+ # Get the default domain authentication. #
40
40
  # GET /whitelabel/domains/default #
41
41
 
42
42
  response = sg.client.whitelabel.domains.default.get()
@@ -45,7 +45,7 @@ puts response.body
45
45
  puts response.headers
46
46
 
47
47
  ##################################################
48
- # List the domain whitelabel associated with the given user. #
48
+ # List the domain authentication associated with the given user. #
49
49
  # GET /whitelabel/domains/subuser #
50
50
 
51
51
  response = sg.client.whitelabel.domains.subuser.get()
@@ -54,7 +54,7 @@ puts response.body
54
54
  puts response.headers
55
55
 
56
56
  ##################################################
57
- # Disassociate a domain whitelabel from a given user. #
57
+ # Disassociate a domain authentication from a given user. #
58
58
  # DELETE /whitelabel/domains/subuser #
59
59
 
60
60
  response = sg.client.whitelabel.domains.subuser.delete()
@@ -63,7 +63,7 @@ puts response.body
63
63
  puts response.headers
64
64
 
65
65
  ##################################################
66
- # Update a domain whitelabel. #
66
+ # Update a domain authentication. #
67
67
  # PATCH /whitelabel/domains/{domain_id} #
68
68
 
69
69
  data = JSON.parse('{
@@ -77,7 +77,7 @@ puts response.body
77
77
  puts response.headers
78
78
 
79
79
  ##################################################
80
- # Retrieve a domain whitelabel. #
80
+ # Retrieve a domain authentication. #
81
81
  # GET /whitelabel/domains/{domain_id} #
82
82
 
83
83
  domain_id = "test_url_param"
@@ -87,7 +87,7 @@ puts response.body
87
87
  puts response.headers
88
88
 
89
89
  ##################################################
90
- # Delete a domain whitelabel. #
90
+ # Delete a domain authentication. #
91
91
  # DELETE /whitelabel/domains/{domain_id} #
92
92
 
93
93
  domain_id = "test_url_param"
@@ -97,7 +97,7 @@ puts response.body
97
97
  puts response.headers
98
98
 
99
99
  ##################################################
100
- # Associate a domain whitelabel with a given user. #
100
+ # Associate a domain authentication with a given user. #
101
101
  # POST /whitelabel/domains/{domain_id}/subuser #
102
102
 
103
103
  data = JSON.parse('{
@@ -110,7 +110,7 @@ puts response.body
110
110
  puts response.headers
111
111
 
112
112
  ##################################################
113
- # Add an IP to a domain whitelabel. #
113
+ # Add an IP to a domain authentication. #
114
114
  # POST /whitelabel/domains/{id}/ips #
115
115
 
116
116
  data = JSON.parse('{
@@ -123,7 +123,7 @@ puts response.body
123
123
  puts response.headers
124
124
 
125
125
  ##################################################
126
- # Remove an IP from a domain whitelabel. #
126
+ # Remove an IP from a domain authentication. #
127
127
  # DELETE /whitelabel/domains/{id}/ips/{ip} #
128
128
 
129
129
  id = "test_url_param"
@@ -134,7 +134,7 @@ puts response.body
134
134
  puts response.headers
135
135
 
136
136
  ##################################################
137
- # Validate a domain whitelabel. #
137
+ # Validate a domain authentication. #
138
138
  # POST /whitelabel/domains/{id}/validate #
139
139
 
140
140
  id = "test_url_param"
@@ -144,7 +144,7 @@ puts response.body
144
144
  puts response.headers
145
145
 
146
146
  ##################################################
147
- # Create an IP whitelabel #
147
+ # Create a reverse DNS record #
148
148
  # POST /whitelabel/ips #
149
149
 
150
150
  data = JSON.parse('{
@@ -158,7 +158,7 @@ puts response.body
158
158
  puts response.headers
159
159
 
160
160
  ##################################################
161
- # Retrieve all IP whitelabels #
161
+ # Retrieve a reverse DNS record #
162
162
  # GET /whitelabel/ips #
163
163
 
164
164
  params = JSON.parse('{"ip": "test_string", "limit": 1, "offset": 1}')
@@ -168,7 +168,7 @@ puts response.body
168
168
  puts response.headers
169
169
 
170
170
  ##################################################
171
- # Retrieve an IP whitelabel #
171
+ # Retrieve a reverse DNS record #
172
172
  # GET /whitelabel/ips/{id} #
173
173
 
174
174
  id = "test_url_param"
@@ -178,7 +178,7 @@ puts response.body
178
178
  puts response.headers
179
179
 
180
180
  ##################################################
181
- # Delete an IP whitelabel #
181
+ # Delete a reverse DNS record #
182
182
  # DELETE /whitelabel/ips/{id} #
183
183
 
184
184
  id = "test_url_param"
@@ -188,7 +188,7 @@ puts response.body
188
188
  puts response.headers
189
189
 
190
190
  ##################################################
191
- # Validate an IP whitelabel #
191
+ # Validate a reverse DNS record #
192
192
  # POST /whitelabel/ips/{id}/validate #
193
193
 
194
194
  id = "test_url_param"
@@ -198,7 +198,7 @@ puts response.body
198
198
  puts response.headers
199
199
 
200
200
  ##################################################
201
- # Create a Link Whitelabel #
201
+ # Create a Branded Link #
202
202
  # POST /whitelabel/links #
203
203
 
204
204
  data = JSON.parse('{
@@ -213,7 +213,7 @@ puts response.body
213
213
  puts response.headers
214
214
 
215
215
  ##################################################
216
- # Retrieve all link whitelabels #
216
+ # Retrieve all link brandings #
217
217
  # GET /whitelabel/links #
218
218
 
219
219
  params = JSON.parse('{"limit": 1}')
@@ -223,7 +223,7 @@ puts response.body
223
223
  puts response.headers
224
224
 
225
225
  ##################################################
226
- # Retrieve a Default Link Whitelabel #
226
+ # Retrieve a Default Link Branding #
227
227
  # GET /whitelabel/links/default #
228
228
 
229
229
  params = JSON.parse('{"domain": "test_string"}')
@@ -233,7 +233,7 @@ puts response.body
233
233
  puts response.headers
234
234
 
235
235
  ##################################################
236
- # Retrieve Associated Link Whitelabel #
236
+ # Retrieve Associated Link Branding #
237
237
  # GET /whitelabel/links/subuser #
238
238
 
239
239
  params = JSON.parse('{"username": "test_string"}')
@@ -243,7 +243,7 @@ puts response.body
243
243
  puts response.headers
244
244
 
245
245
  ##################################################
246
- # Disassociate a Link Whitelabel #
246
+ # Disassociate a Link Branding #
247
247
  # DELETE /whitelabel/links/subuser #
248
248
 
249
249
  params = JSON.parse('{"username": "test_string"}')
@@ -253,7 +253,7 @@ puts response.body
253
253
  puts response.headers
254
254
 
255
255
  ##################################################
256
- # Update a Link Whitelabel #
256
+ # Update a Link Branding #
257
257
  # PATCH /whitelabel/links/{id} #
258
258
 
259
259
  data = JSON.parse('{
@@ -266,7 +266,7 @@ puts response.body
266
266
  puts response.headers
267
267
 
268
268
  ##################################################
269
- # Retrieve a Link Whitelabel #
269
+ # Retrieve a Link Branding #
270
270
  # GET /whitelabel/links/{id} #
271
271
 
272
272
  id = "test_url_param"
@@ -276,7 +276,7 @@ puts response.body
276
276
  puts response.headers
277
277
 
278
278
  ##################################################
279
- # Delete a Link Whitelabel #
279
+ # Delete a Link Branding #
280
280
  # DELETE /whitelabel/links/{id} #
281
281
 
282
282
  id = "test_url_param"
@@ -286,7 +286,7 @@ puts response.body
286
286
  puts response.headers
287
287
 
288
288
  ##################################################
289
- # Validate a Link Whitelabel #
289
+ # Validate a Link Branding #
290
290
  # POST /whitelabel/links/{id}/validate #
291
291
 
292
292
  id = "test_url_param"
@@ -296,7 +296,7 @@ puts response.body
296
296
  puts response.headers
297
297
 
298
298
  ##################################################
299
- # Associate a Link Whitelabel #
299
+ # Associate a Link Branding #
300
300
  # POST /whitelabel/links/{link_id}/subuser #
301
301
 
302
302
  data = JSON.parse('{
@@ -19,9 +19,9 @@ puts response.headers
19
19
  # DELETE /suppression/blocks #
20
20
 
21
21
  data = JSON.parse('{
22
- "delete_all": false,
22
+ "delete_all": false,
23
23
  "emails": [
24
- "example1@example.com",
24
+ "example1@example.com",
25
25
  "example2@example.com"
26
26
  ]
27
27
  }')
@@ -65,9 +65,9 @@ puts response.headers
65
65
  # DELETE /suppression/bounces #
66
66
 
67
67
  data = JSON.parse('{
68
- "delete_all": true,
68
+ "delete_all": true,
69
69
  "emails": [
70
- "example@example.com",
70
+ "example@example.com",
71
71
  "example2@example.com"
72
72
  ]
73
73
  }')
@@ -112,9 +112,9 @@ puts response.headers
112
112
  # DELETE /suppression/invalid_emails #
113
113
 
114
114
  data = JSON.parse('{
115
- "delete_all": false,
115
+ "delete_all": false,
116
116
  "emails": [
117
- "example1@example.com",
117
+ "example1@example.com",
118
118
  "example2@example.com"
119
119
  ]
120
120
  }')
@@ -148,7 +148,7 @@ puts response.headers
148
148
  # GET /suppression/spam_report/{email} #
149
149
 
150
150
  email = "test_url_param"
151
- response = sg.client.suppression.spam_report._(email).get()
151
+ response = sg.client.suppression.spam_reports._(email).get()
152
152
  puts response.status_code
153
153
  puts response.body
154
154
  puts response.headers
@@ -158,7 +158,7 @@ puts response.headers
158
158
  # DELETE /suppression/spam_report/{email} #
159
159
 
160
160
  email = "test_url_param"
161
- response = sg.client.suppression.spam_report._(email).delete()
161
+ response = sg.client.suppression.spam_reports._(email).delete()
162
162
  puts response.status_code
163
163
  puts response.body
164
164
  puts response.headers
@@ -178,9 +178,9 @@ puts response.headers
178
178
  # DELETE /suppression/spam_reports #
179
179
 
180
180
  data = JSON.parse('{
181
- "delete_all": false,
181
+ "delete_all": false,
182
182
  "emails": [
183
- "example1@example.com",
183
+ "example1@example.com",
184
184
  "example2@example.com"
185
185
  ]
186
186
  }')