sendgrid-ruby 5.3.0 → 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/.travis.yml +22 -20
- data/CHANGELOG.md +55 -0
- data/CODE_OF_CONDUCT.md +57 -25
- data/CONTRIBUTING.md +18 -23
- 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 +26 -13
- data/Rakefile +1 -1
- data/TROUBLESHOOTING.md +22 -16
- data/UPGRADE.md +5 -0
- data/USAGE.md +1103 -1101
- data/USE_CASES.md +248 -18
- data/examples/helpers/mail/example.rb +7 -7
- data/examples/ips/ips.rb +13 -0
- data/examples/mail/mail.rb +2 -2
- data/examples/scopes/scopes.rb +49 -3
- data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +27 -27
- data/examples/suppression/suppression.rb +10 -10
- data/lib/sendgrid/client.rb +12 -9
- data/lib/sendgrid/helpers/inbound/README.md +22 -5
- data/lib/sendgrid/helpers/inbound/app.rb +13 -1
- data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +2 -2
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +2 -2
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +2 -2
- data/lib/sendgrid/helpers/inbound/send.rb +2 -2
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +1 -1
- data/lib/sendgrid/helpers/mail/attachment.rb +24 -1
- data/lib/sendgrid/helpers/mail/category.rb +0 -8
- data/lib/sendgrid/helpers/mail/content.rb +3 -16
- data/lib/sendgrid/helpers/mail/email.rb +3 -16
- data/lib/sendgrid/helpers/mail/mail.rb +8 -40
- 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 +1 -1
- data/lib/sendgrid/helpers/stats/stats_response.rb +1 -1
- data/lib/sendgrid/version.rb +1 -1
- data/lib/sendgrid-ruby.rb +2 -0
- data/mail_helper_v3.md +9 -9
- data/sendgrid-ruby.gemspec +3 -3
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +29 -21
- data/test/sendgrid/permissions/test_scopes.rb +38 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +21 -13
- metadata +22 -11
- data/.github/ISSUE_TEMPLATE +0 -17
- data/.github/PULL_REQUEST_TEMPLATE +0 -24
- data/LICENSE.txt +0 -22
data/USE_CASES.md
CHANGED
@@ -3,15 +3,127 @@ This documentation provides examples for specific use cases. Please [open an iss
|
|
3
3
|
# Table of Contents
|
4
4
|
|
5
5
|
* [Transactional Templates](#transactional-templates)
|
6
|
-
* [
|
7
|
-
* [
|
6
|
+
* [With Mail Helper Class](#with-mail-helper-class)
|
7
|
+
* [Without Mail Helper Class](#without-mail-helper-class)
|
8
|
+
* [Legacy Templates](#legacy-templates)
|
9
|
+
* [With Mail Helper Class](#with-mail-helper-class-1)
|
10
|
+
* [Without Mail Helper Class](#without-mail-helper-class-1)
|
11
|
+
* [Adding Attachments](#adding-attachments)
|
12
|
+
* [How to Setup a Domain Authentication](#how-to-setup-a-domain-authentication)
|
13
|
+
* [How to View Email Statistics](#how-to-view-email-statistics)
|
14
|
+
* [Send a SMS Message](#send-a-sms-message)
|
15
|
+
* [1. Obtain a Free Twilio Account](#1-obtain-a-free-twilio-account)
|
16
|
+
* [2. Update Your Environment Variables](#2-update-your-environment-variables)
|
17
|
+
* [Mac](#mac)
|
18
|
+
* [Windows](#windows)
|
19
|
+
* [3. Install the Twilio Helper Library](#3-install-the-twilio-helper-library)
|
20
|
+
* [4. Setup Work](#4-setup-work)
|
21
|
+
* [5. Send an SMS](#5-send-an-sms)
|
8
22
|
|
9
23
|
<a name="transactional-templates"></a>
|
10
|
-
#
|
24
|
+
# Transactional Templates
|
11
25
|
|
12
|
-
|
26
|
+
For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html) in the UI or via the API. Following is the template content we used for testing.
|
13
27
|
|
14
|
-
|
28
|
+
Template ID (replace with your own):
|
29
|
+
|
30
|
+
```text
|
31
|
+
d-2c214ac919e84170b21855cc129b4a5f
|
32
|
+
```
|
33
|
+
Email Subject:
|
34
|
+
```text
|
35
|
+
{{subject}}
|
36
|
+
```
|
37
|
+
|
38
|
+
Template Body:
|
39
|
+
|
40
|
+
```html
|
41
|
+
<html>
|
42
|
+
<head>
|
43
|
+
<title></title>
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
Hello {{name}},
|
47
|
+
<br/><br/>
|
48
|
+
I'm glad you are trying out the template feature!
|
49
|
+
<br/><br/>
|
50
|
+
I hope you are having a great day in {{city}} :)
|
51
|
+
<br/><br/>
|
52
|
+
</body>
|
53
|
+
</html>
|
54
|
+
```
|
55
|
+
|
56
|
+
## With Mail Helper Class
|
57
|
+
```ruby
|
58
|
+
require 'sendgrid-ruby'
|
59
|
+
include SendGrid
|
60
|
+
|
61
|
+
mail = Mail.new
|
62
|
+
mail.from = Email.new(email: 'test@example.com')
|
63
|
+
personalization = Personalization.new
|
64
|
+
personalization.add_to(Email.new(email: 'test@example.com'))
|
65
|
+
personalization.add_dynamic_template_data({
|
66
|
+
"subject" => "Testing Templates",
|
67
|
+
"name" => "Example User",
|
68
|
+
"city" => "Denver"
|
69
|
+
})
|
70
|
+
mail.add_personalization(personalization)
|
71
|
+
mail.template_id = 'd-2c214ac919e84170b21855cc129b4a5f'
|
72
|
+
|
73
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
74
|
+
begin
|
75
|
+
response = sg.client.mail._("send").post(request_body: mail.to_json)
|
76
|
+
rescue Exception => e
|
77
|
+
puts e.message
|
78
|
+
end
|
79
|
+
puts response.status_code
|
80
|
+
puts response.body
|
81
|
+
puts response.parsed_body
|
82
|
+
puts response.headers
|
83
|
+
```
|
84
|
+
|
85
|
+
## Without Mail Helper Class
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
require 'sendgrid-ruby'
|
89
|
+
include SendGrid
|
90
|
+
|
91
|
+
data = JSON.parse('{
|
92
|
+
"personalizations": [
|
93
|
+
{
|
94
|
+
"to": [
|
95
|
+
{
|
96
|
+
"email": "test@example.com"
|
97
|
+
}
|
98
|
+
],
|
99
|
+
"dynamic_template_data": {
|
100
|
+
"subject": "Testing Templates",
|
101
|
+
"name": "Example User",
|
102
|
+
"city": "Denver"
|
103
|
+
}
|
104
|
+
}
|
105
|
+
],
|
106
|
+
"from": {
|
107
|
+
"email": "test@example.com"
|
108
|
+
},
|
109
|
+
"template_id": "d-2c214ac919e84170b21855cc129b4a5f"
|
110
|
+
}')
|
111
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
112
|
+
begin
|
113
|
+
response = sg.client.mail._("send").post(request_body: data)
|
114
|
+
rescue Exception => e
|
115
|
+
puts e.message
|
116
|
+
end
|
117
|
+
puts response.status_code
|
118
|
+
puts response.body
|
119
|
+
puts response.parsed_body
|
120
|
+
puts response.headers
|
121
|
+
```
|
122
|
+
|
123
|
+
<a name="legacy-templates"></a>
|
124
|
+
# Legacy Templates
|
125
|
+
|
126
|
+
For this example, we assume you have created a [legacy template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing.
|
15
127
|
|
16
128
|
Template ID (replace with your own):
|
17
129
|
|
@@ -51,7 +163,7 @@ I hope you are having a great day in -city- :)
|
|
51
163
|
require 'sendgrid-ruby'
|
52
164
|
include SendGrid
|
53
165
|
|
54
|
-
mail = Mail.new
|
166
|
+
mail = SendGrid::Mail.new
|
55
167
|
mail.from = Email.new(email: 'test@example.com')
|
56
168
|
mail.subject = 'I\'m replacing the subject tag'
|
57
169
|
personalization = Personalization.new
|
@@ -59,7 +171,6 @@ personalization.add_to(Email.new(email: 'test@example.com'))
|
|
59
171
|
personalization.add_substitution(Substitution.new(key: '-name-', value: 'Example User'))
|
60
172
|
personalization.add_substitution(Substitution.new(key: '-city-', value: 'Denver'))
|
61
173
|
mail.add_personalization(personalization)
|
62
|
-
mail.add_content(Content.new(type: 'text/html', value: 'I\'m replacing the <strong>body tag</strong>'))
|
63
174
|
mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
|
64
175
|
|
65
176
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
@@ -98,12 +209,6 @@ data = JSON.parse('{
|
|
98
209
|
"from": {
|
99
210
|
"email": "test@example.com"
|
100
211
|
},
|
101
|
-
"content": [
|
102
|
-
{
|
103
|
-
"type": "text/html",
|
104
|
-
"value": "I\'m replacing the <strong>body tag</strong>"
|
105
|
-
}
|
106
|
-
],
|
107
212
|
"template_id": "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
|
108
213
|
}')
|
109
214
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
@@ -132,16 +237,141 @@ mail.add_attachment(attachment)
|
|
132
237
|
```
|
133
238
|
Attachments must be base64 encoded, using Base64's strict_encode64 where no line feeds are added.
|
134
239
|
|
135
|
-
<a name="domain-
|
136
|
-
# How to Setup a Domain
|
240
|
+
<a name="domain-authentication"></a>
|
241
|
+
# How to Setup a Domain Authentication
|
137
242
|
|
138
|
-
You can find documentation for how to setup a domain
|
243
|
+
You can find documentation for how to setup a domain authentication via the UI [here](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) and via API [here](https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/client/USAGE.md#sender-authentication).
|
139
244
|
|
140
|
-
Find more information about all of SendGrid's
|
245
|
+
Find more information about all of SendGrid's authentication related documentation [here](https://sendgrid.com/docs/ui/account-and-settings/).
|
141
246
|
|
142
247
|
<a name="email-statistics"></a>
|
143
248
|
# How to View Email Statistics
|
144
249
|
|
145
250
|
You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](https://github.com/sendgrid/sendgrid-ruby/blob/master/USAGE.md#stats).
|
146
251
|
|
147
|
-
Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email.
|
252
|
+
Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as Twilio SendGrid processes your email.
|
253
|
+
|
254
|
+
You can also use the email statistics helper to make it easier to interact with the API.
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
require 'sendgrid-ruby'
|
258
|
+
require 'date'
|
259
|
+
|
260
|
+
include SendGrid
|
261
|
+
|
262
|
+
sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
|
263
|
+
stats = SendGrid::EmailStats.new(sendgrid_client: sg_client)
|
264
|
+
|
265
|
+
# Fetch stats by day, between 2 dates
|
266
|
+
from = Date.new(2017, 10, 01)
|
267
|
+
to = Date.new(2017, 10, 12)
|
268
|
+
|
269
|
+
email_stats = stats.by_day(from, to)
|
270
|
+
|
271
|
+
email_stats.metrics
|
272
|
+
|
273
|
+
if !email_stats.error?
|
274
|
+
email_stats.metrics.each do |metric|
|
275
|
+
puts "Date - #{metric.date}"
|
276
|
+
puts "Number of Requests - #{metric.requests}"
|
277
|
+
puts "Bounces - #{metric.bounces}"
|
278
|
+
puts "Opens - #{metric.opens}"
|
279
|
+
puts "Clicks - #{metric.clicks}"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# Fetch stats by week, between 2 dates for a category
|
284
|
+
from = Date.new(2017, 10, 01)
|
285
|
+
to = Date.new(2017, 10, 12)
|
286
|
+
category = 'abcd'
|
287
|
+
|
288
|
+
email_stats = stats.by_week(from, to, category)
|
289
|
+
|
290
|
+
if !email_stats.error?
|
291
|
+
email_stats.metrics.each do |metric|
|
292
|
+
puts "Date - #{metric.date}"
|
293
|
+
puts "Number of Requests - #{metric.requests}"
|
294
|
+
puts "Bounces - #{metric.bounces}"
|
295
|
+
puts "Opens - #{metric.opens}"
|
296
|
+
puts "Clicks - #{metric.clicks}"
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
```
|
301
|
+
|
302
|
+
<a name="sms"></a>
|
303
|
+
# Send a SMS Message
|
304
|
+
|
305
|
+
Following are the steps to add Twilio SMS to your app:
|
306
|
+
|
307
|
+
## 1. Obtain a Free Twilio Account
|
308
|
+
|
309
|
+
Sign up for a free Twilio account [here](https://www.twilio.com/try-twilio?source=sendgrid-ruby).
|
310
|
+
|
311
|
+
## 2. Update Your Environment Variables
|
312
|
+
|
313
|
+
You can obtain your Account Sid and Auth Token from [twilio.com/console](https://twilio.com/console).
|
314
|
+
|
315
|
+
### Mac
|
316
|
+
|
317
|
+
```bash
|
318
|
+
echo "export TWILIO_ACCOUNT_SID='YOUR_TWILIO_ACCOUNT_SID'" > twilio.env
|
319
|
+
echo "export TWILIO_AUTH_TOKEN='YOUR_TWILIO_AUTH_TOKEN'" >> twilio.env
|
320
|
+
echo "twilio.env" >> .gitignore
|
321
|
+
source ./twilio.env
|
322
|
+
```
|
323
|
+
|
324
|
+
### Windows
|
325
|
+
|
326
|
+
Temporarily set the environment variable (accessible only during the current CLI session):
|
327
|
+
|
328
|
+
```bash
|
329
|
+
set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID
|
330
|
+
set TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN
|
331
|
+
```
|
332
|
+
|
333
|
+
Permanently set the environment variable (accessible in all subsequent CLI sessions):
|
334
|
+
|
335
|
+
```bash
|
336
|
+
setx TWILIO_ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID"
|
337
|
+
setx TWILIO_AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN"
|
338
|
+
```
|
339
|
+
|
340
|
+
## 3. Install the Twilio Helper Library
|
341
|
+
|
342
|
+
To install using [Bundler][bundler] grab the latest stable version:
|
343
|
+
|
344
|
+
```ruby
|
345
|
+
gem 'twilio-ruby', '~> 5.23.1'
|
346
|
+
```
|
347
|
+
|
348
|
+
To manually install `twilio-ruby` via [Rubygems][rubygems] simply gem install:
|
349
|
+
|
350
|
+
```bash
|
351
|
+
gem install twilio-ruby -v 5.23.1
|
352
|
+
```
|
353
|
+
|
354
|
+
## 4. Setup Work
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
require 'twilio-ruby'
|
358
|
+
|
359
|
+
# put your own credentials here
|
360
|
+
account_sid = ENV['TWILIO_ACCOUNT_SID']
|
361
|
+
auth_token = ENV['TWILIO_AUTH_TOKEN']
|
362
|
+
|
363
|
+
# set up a client to talk to the Twilio REST API
|
364
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
365
|
+
```
|
366
|
+
|
367
|
+
## 5. Send an SMS
|
368
|
+
|
369
|
+
```ruby
|
370
|
+
@client.api.account.messages.create(
|
371
|
+
from: '+14159341234',
|
372
|
+
to: '+16105557069',
|
373
|
+
body: 'Hey there!'
|
374
|
+
)
|
375
|
+
```
|
376
|
+
|
377
|
+
For more information, please visit the [Twilio SMS Ruby documentation](https://www.twilio.com/docs/sms/quickstart/ruby).
|
@@ -4,10 +4,10 @@ require 'json'
|
|
4
4
|
|
5
5
|
def hello_world
|
6
6
|
from = Email.new(email: 'test@example.com')
|
7
|
-
subject = 'Hello World from the SendGrid Ruby Library'
|
7
|
+
subject = 'Hello World from the Twilio SendGrid Ruby Library'
|
8
8
|
to = Email.new(email: 'test@example.com')
|
9
9
|
content = Content.new(type: 'text/plain', value: 'some text here')
|
10
|
-
mail = Mail.new(from, subject, to, content)
|
10
|
+
mail = SendGrid::Mail.new(from, subject, to, content)
|
11
11
|
# puts JSON.pretty_generate(mail.to_json)
|
12
12
|
puts mail.to_json
|
13
13
|
|
@@ -19,9 +19,9 @@ def hello_world
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def kitchen_sink
|
22
|
-
mail = Mail.new
|
22
|
+
mail = SendGrid::Mail.new
|
23
23
|
mail.from = Email.new(email: 'test@example.com')
|
24
|
-
mail.subject = 'Hello World from the SendGrid Ruby Library'
|
24
|
+
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
|
25
25
|
personalization = Personalization.new
|
26
26
|
personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
27
27
|
personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
|
@@ -29,7 +29,7 @@ def kitchen_sink
|
|
29
29
|
personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
|
30
30
|
personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
|
31
31
|
personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
|
32
|
-
personalization.subject = 'Hello World from the Personalized SendGrid Ruby Library'
|
32
|
+
personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
|
33
33
|
personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
|
34
34
|
personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
|
35
35
|
personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
|
@@ -46,7 +46,7 @@ def kitchen_sink
|
|
46
46
|
personalization2.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
|
47
47
|
personalization2.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
|
48
48
|
personalization2.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
|
49
|
-
personalization2.subject = 'Hello World from the Personalized SendGrid Ruby Library'
|
49
|
+
personalization2.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
|
50
50
|
personalization2.add_header(Header.new(key: 'X-Test', value: 'True'))
|
51
51
|
personalization2.add_header(Header.new(key: 'X-Mock', value: 'False'))
|
52
52
|
personalization2.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
|
@@ -129,7 +129,7 @@ def dynamic_template_data_hello_world
|
|
129
129
|
mail = Mail.new
|
130
130
|
mail.template_id = '' # a non-legacy template id
|
131
131
|
mail.from = Email.new(email: 'test@example.com')
|
132
|
-
subject = 'Dynamic Template Data Hello World from the SendGrid Ruby Library'
|
132
|
+
subject = 'Dynamic Template Data Hello World from the Twilio SendGrid Ruby Library'
|
133
133
|
mail.subject = subject
|
134
134
|
personalization = Personalization.new
|
135
135
|
personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
data/examples/ips/ips.rb
CHANGED
@@ -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 #
|
data/examples/mail/mail.rb
CHANGED
@@ -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
|
data/examples/scopes/scopes.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
299
|
+
# Associate a Link Branding #
|
300
300
|
# POST /whitelabel/links/{link_id}/subuser #
|
301
301
|
|
302
302
|
data = JSON.parse('{
|