sendgrid-ruby 6.3.1 → 6.3.6
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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -1
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +109 -0
- data/.travis.yml +2 -3
- data/CHANGELOG.md +61 -9
- data/CONTRIBUTING.md +10 -20
- data/FIRST_TIMERS.md +79 -0
- data/ISSUE_TEMPLATE.md +5 -1
- data/Makefile +3 -2
- data/PULL_REQUEST_TEMPLATE.md +1 -1
- data/README.md +22 -27
- data/Rakefile +2 -3
- data/TROUBLESHOOTING.md +5 -5
- data/USAGE.md +145 -38
- data/examples/accesssettings/accesssettings.rb +9 -12
- data/examples/alerts/alerts.rb +8 -11
- data/examples/apikeys/apikeys.rb +12 -15
- data/examples/asm/asm.rb +27 -30
- data/examples/browsers/browsers.rb +0 -3
- data/examples/campaigns/campaigns.rb +29 -32
- data/examples/categories/categories.rb +0 -3
- data/examples/clients/clients.rb +1 -4
- data/examples/contactdb/contactdb.rb +63 -66
- data/examples/devices/devices.rb +0 -3
- data/examples/emailactivity/emailactivity.rb +52 -0
- data/examples/geo/geo.rb +0 -3
- data/examples/helpers/eventwebhook/example.rb +4 -4
- data/examples/helpers/mail/example.rb +19 -13
- data/examples/helpers/settings/example.rb +1 -1
- data/examples/helpers/stats/example.rb +4 -4
- data/examples/ips/ips.rb +19 -22
- data/examples/mail/mail.rb +72 -75
- data/examples/mailboxproviders/mailboxproviders.rb +0 -3
- data/examples/mailsettings/mailsettings.rb +21 -24
- data/examples/partnersettings/partnersettings.rb +3 -6
- data/examples/scopes/scopes.rb +7 -9
- data/examples/senderauthentication/senderauthentication.rb +41 -44
- data/examples/senders/senders.rb +28 -31
- data/examples/stats/stats.rb +0 -3
- data/examples/subusers/subusers.rb +17 -20
- data/examples/suppression/suppression.rb +15 -18
- data/examples/templates/templates.rb +29 -31
- data/examples/trackingsettings/trackingsettings.rb +14 -17
- data/examples/user/user.rb +41 -44
- data/lib/rack/sendgrid_webhook_verification.rb +5 -2
- data/lib/sendgrid/base_interface.rb +1 -1
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +4 -6
- data/lib/sendgrid/helpers/inbound/README.md +5 -5
- data/lib/sendgrid/helpers/inbound/app.rb +1 -1
- data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
- data/lib/sendgrid/helpers/inbound/send.rb +2 -2
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +1 -1
- data/lib/sendgrid/helpers/mail/README.md +3 -3
- data/lib/sendgrid/helpers/mail/asm.rb +6 -18
- data/lib/sendgrid/helpers/mail/attachment.rb +12 -42
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +6 -18
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +8 -18
- data/lib/sendgrid/helpers/mail/category.rb +2 -2
- data/lib/sendgrid/helpers/mail/click_tracking.rb +6 -18
- data/lib/sendgrid/helpers/mail/content.rb +4 -3
- data/lib/sendgrid/helpers/mail/custom_arg.rb +6 -10
- data/lib/sendgrid/helpers/mail/email.rb +5 -4
- data/lib/sendgrid/helpers/mail/footer.rb +7 -27
- data/lib/sendgrid/helpers/mail/ganalytics.rb +10 -54
- data/lib/sendgrid/helpers/mail/header.rb +6 -10
- data/lib/sendgrid/helpers/mail/mail.rb +30 -48
- data/lib/sendgrid/helpers/mail/mail_settings.rb +9 -25
- data/lib/sendgrid/helpers/mail/open_tracking.rb +6 -18
- data/lib/sendgrid/helpers/mail/personalization.rb +34 -27
- data/lib/sendgrid/helpers/mail/section.rb +6 -10
- data/lib/sendgrid/helpers/mail/spam_check.rb +7 -27
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +8 -36
- data/lib/sendgrid/helpers/mail/substitution.rb +6 -10
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +7 -20
- data/lib/sendgrid/helpers/permissions/scope.rb +1 -1
- data/lib/sendgrid/helpers/settings/README.md +2 -2
- data/lib/sendgrid/helpers/settings/settings.rb +1 -1
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +3 -5
- data/lib/sendgrid/helpers/stats/metrics.rb +5 -5
- data/lib/sendgrid/sendgrid.rb +1 -1
- data/lib/sendgrid/twilio_email.rb +1 -1
- data/lib/sendgrid/version.rb +1 -1
- data/mail_helper_v3.md +12 -12
- data/sendgrid-ruby.gemspec +8 -8
- data/spec/fixtures/event_webhook.rb +17 -11
- data/spec/rack/sendgrid_webhook_verification_spec.rb +30 -4
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +38 -36
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/settings/settings_spec.rb +2 -2
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +22 -23
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +19 -20
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +22 -23
- data/spec/spec_helper.rb +3 -1
- data/static/img/github-fork.png +0 -0
- data/static/img/github-sign-up.png +0 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +4 -6
- data/test/sendgrid/helpers/mail/test_category.rb +0 -2
- data/test/sendgrid/helpers/mail/test_email.rb +9 -11
- data/test/sendgrid/helpers/mail/test_mail.rb +101 -102
- data/test/sendgrid/helpers/mail/test_personalizations.rb +106 -93
- data/test/sendgrid/permissions/test_scopes.rb +0 -2
- data/test/sendgrid/test_sendgrid-ruby.rb +1948 -1958
- data/twilio_sendgrid_logo.png +0 -0
- data/use-cases/README.md +16 -0
- data/use-cases/domain-authentication.md +5 -0
- data/use-cases/email-statistics.md +52 -0
- data/use-cases/legacy-templates.md +98 -0
- data/use-cases/sms.md +39 -0
- data/use-cases/transactional-templates.md +111 -0
- data/use-cases/twilio-email.md +13 -0
- data/use-cases/twilio-setup.md +54 -0
- metadata +53 -28
- data/USE_CASES.md +0 -405
- data/docker/Dockerfile +0 -12
- data/docker/README.md +0 -30
data/USE_CASES.md
DELETED
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
This documentation provides examples for specific use cases. Please [open an issue](https://github.com/sendgrid/sendgrid-ruby/issues) or make a pull request for any use cases you would like us to document here. Thank you!
|
|
2
|
-
|
|
3
|
-
# Table of Contents
|
|
4
|
-
|
|
5
|
-
* [Transactional Templates](#transactional-templates)
|
|
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 an Email With Twilio Email (Pilot)](#send-an-email-with-twilio-email-pilot)
|
|
15
|
-
* [Send an SMS Message](#send-an-sms-message)
|
|
16
|
-
|
|
17
|
-
<a name="transactional-templates"></a>
|
|
18
|
-
# Transactional Templates
|
|
19
|
-
|
|
20
|
-
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.
|
|
21
|
-
|
|
22
|
-
Template ID (replace with your own):
|
|
23
|
-
|
|
24
|
-
```text
|
|
25
|
-
d-2c214ac919e84170b21855cc129b4a5f
|
|
26
|
-
```
|
|
27
|
-
Email Subject:
|
|
28
|
-
```text
|
|
29
|
-
{{subject}}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Template Body:
|
|
33
|
-
|
|
34
|
-
```html
|
|
35
|
-
<html>
|
|
36
|
-
<head>
|
|
37
|
-
<title></title>
|
|
38
|
-
</head>
|
|
39
|
-
<body>
|
|
40
|
-
Hello {{name}},
|
|
41
|
-
<br/><br/>
|
|
42
|
-
I'm glad you are trying out the template feature!
|
|
43
|
-
<br/><br/>
|
|
44
|
-
I hope you are having a great day in {{city}} :)
|
|
45
|
-
<br/><br/>
|
|
46
|
-
</body>
|
|
47
|
-
</html>
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## With Mail Helper Class
|
|
51
|
-
```ruby
|
|
52
|
-
require 'sendgrid-ruby'
|
|
53
|
-
include SendGrid
|
|
54
|
-
|
|
55
|
-
mail = Mail.new
|
|
56
|
-
mail.from = Email.new(email: 'test@example.com')
|
|
57
|
-
personalization = Personalization.new
|
|
58
|
-
personalization.add_to(Email.new(email: 'test@example.com'))
|
|
59
|
-
personalization.add_dynamic_template_data({
|
|
60
|
-
"subject" => "Testing Templates",
|
|
61
|
-
"name" => "Example User",
|
|
62
|
-
"city" => "Denver"
|
|
63
|
-
})
|
|
64
|
-
mail.add_personalization(personalization)
|
|
65
|
-
mail.template_id = 'd-2c214ac919e84170b21855cc129b4a5f'
|
|
66
|
-
|
|
67
|
-
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
68
|
-
begin
|
|
69
|
-
response = sg.client.mail._("send").post(request_body: mail.to_json)
|
|
70
|
-
rescue Exception => e
|
|
71
|
-
puts e.message
|
|
72
|
-
end
|
|
73
|
-
puts response.status_code
|
|
74
|
-
puts response.body
|
|
75
|
-
puts response.parsed_body
|
|
76
|
-
puts response.headers
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Without Mail Helper Class
|
|
80
|
-
|
|
81
|
-
```ruby
|
|
82
|
-
require 'sendgrid-ruby'
|
|
83
|
-
include SendGrid
|
|
84
|
-
|
|
85
|
-
data = JSON.parse('{
|
|
86
|
-
"personalizations": [
|
|
87
|
-
{
|
|
88
|
-
"to": [
|
|
89
|
-
{
|
|
90
|
-
"email": "test@example.com"
|
|
91
|
-
}
|
|
92
|
-
],
|
|
93
|
-
"dynamic_template_data": {
|
|
94
|
-
"subject": "Testing Templates",
|
|
95
|
-
"name": "Example User",
|
|
96
|
-
"city": "Denver"
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
],
|
|
100
|
-
"from": {
|
|
101
|
-
"email": "test@example.com"
|
|
102
|
-
},
|
|
103
|
-
"template_id": "d-2c214ac919e84170b21855cc129b4a5f"
|
|
104
|
-
}')
|
|
105
|
-
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
106
|
-
begin
|
|
107
|
-
response = sg.client.mail._("send").post(request_body: data)
|
|
108
|
-
rescue Exception => e
|
|
109
|
-
puts e.message
|
|
110
|
-
end
|
|
111
|
-
puts response.status_code
|
|
112
|
-
puts response.body
|
|
113
|
-
puts response.parsed_body
|
|
114
|
-
puts response.headers
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
<a name="legacy-templates"></a>
|
|
118
|
-
# Legacy Templates
|
|
119
|
-
|
|
120
|
-
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.
|
|
121
|
-
|
|
122
|
-
Template ID (replace with your own):
|
|
123
|
-
|
|
124
|
-
```text
|
|
125
|
-
13b8f94f-bcae-4ec6-b752-70d6cb59f932
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Email Subject:
|
|
129
|
-
|
|
130
|
-
```text
|
|
131
|
-
<%subject%>
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Template Body:
|
|
135
|
-
|
|
136
|
-
```html
|
|
137
|
-
<html>
|
|
138
|
-
<head>
|
|
139
|
-
<title></title>
|
|
140
|
-
</head>
|
|
141
|
-
<body>
|
|
142
|
-
Hello -name-,
|
|
143
|
-
<br /><br/>
|
|
144
|
-
I'm glad you are trying out the template feature!
|
|
145
|
-
<br /><br/>
|
|
146
|
-
<%body%>
|
|
147
|
-
<br /><br/>
|
|
148
|
-
I hope you are having a great day in -city- :)
|
|
149
|
-
<br /><br/>
|
|
150
|
-
</body>
|
|
151
|
-
</html>
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## With Mail Helper Class
|
|
155
|
-
|
|
156
|
-
```ruby
|
|
157
|
-
require 'sendgrid-ruby'
|
|
158
|
-
include SendGrid
|
|
159
|
-
|
|
160
|
-
mail = SendGrid::Mail.new
|
|
161
|
-
mail.from = Email.new(email: 'test@example.com')
|
|
162
|
-
mail.subject = 'I\'m replacing the subject tag'
|
|
163
|
-
personalization = Personalization.new
|
|
164
|
-
personalization.add_to(Email.new(email: 'test@example.com'))
|
|
165
|
-
personalization.add_substitution(Substitution.new(key: '-name-', value: 'Example User'))
|
|
166
|
-
personalization.add_substitution(Substitution.new(key: '-city-', value: 'Denver'))
|
|
167
|
-
mail.add_personalization(personalization)
|
|
168
|
-
mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
|
|
169
|
-
|
|
170
|
-
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
171
|
-
begin
|
|
172
|
-
response = sg.client.mail._("send").post(request_body: mail.to_json)
|
|
173
|
-
rescue Exception => e
|
|
174
|
-
puts e.message
|
|
175
|
-
end
|
|
176
|
-
puts response.status_code
|
|
177
|
-
puts response.body
|
|
178
|
-
puts response.parsed_body
|
|
179
|
-
puts response.headers
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## Without Mail Helper Class
|
|
183
|
-
|
|
184
|
-
```ruby
|
|
185
|
-
require 'sendgrid-ruby'
|
|
186
|
-
include SendGrid
|
|
187
|
-
|
|
188
|
-
data = JSON.parse('{
|
|
189
|
-
"personalizations": [
|
|
190
|
-
{
|
|
191
|
-
"to": [
|
|
192
|
-
{
|
|
193
|
-
"email": "test@example.com"
|
|
194
|
-
}
|
|
195
|
-
],
|
|
196
|
-
"substitutions": {
|
|
197
|
-
"-name-": "Example User",
|
|
198
|
-
"-city-": "Denver"
|
|
199
|
-
},
|
|
200
|
-
"subject": "I\'m replacing the subject tag"
|
|
201
|
-
}
|
|
202
|
-
],
|
|
203
|
-
"from": {
|
|
204
|
-
"email": "test@example.com"
|
|
205
|
-
},
|
|
206
|
-
"template_id": "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
|
|
207
|
-
}')
|
|
208
|
-
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
209
|
-
begin
|
|
210
|
-
response = sg.client.mail._("send").post(request_body: data)
|
|
211
|
-
rescue Exception => e
|
|
212
|
-
puts e.message
|
|
213
|
-
end
|
|
214
|
-
puts response.status_code
|
|
215
|
-
puts response.body
|
|
216
|
-
puts response.parsed_body
|
|
217
|
-
puts response.headers
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
## Adding Attachments
|
|
221
|
-
|
|
222
|
-
```ruby
|
|
223
|
-
attachment = Attachment.new
|
|
224
|
-
attachment.content = Base64.strict_encode64(File.open(fpath, 'rb').read)
|
|
225
|
-
attachment.type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
226
|
-
attachment.filename = fname
|
|
227
|
-
attachment.disposition = 'attachment'
|
|
228
|
-
attachment.content_id = 'Reports Sheet'
|
|
229
|
-
mail.add_attachment(attachment)
|
|
230
|
-
|
|
231
|
-
```
|
|
232
|
-
Attachments must be base64 encoded, using Base64's strict_encode64 where no line feeds are added.
|
|
233
|
-
|
|
234
|
-
<a name="domain-authentication"></a>
|
|
235
|
-
# How to Setup a Domain Authentication
|
|
236
|
-
|
|
237
|
-
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).
|
|
238
|
-
|
|
239
|
-
Find more information about all of SendGrid's authentication related documentation [here](https://sendgrid.com/docs/ui/account-and-settings/).
|
|
240
|
-
|
|
241
|
-
<a name="email-statistics"></a>
|
|
242
|
-
# How to View Email Statistics
|
|
243
|
-
|
|
244
|
-
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).
|
|
245
|
-
|
|
246
|
-
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.
|
|
247
|
-
|
|
248
|
-
You can also use the email statistics helper to make it easier to interact with the API.
|
|
249
|
-
|
|
250
|
-
```ruby
|
|
251
|
-
require 'sendgrid-ruby'
|
|
252
|
-
require 'date'
|
|
253
|
-
|
|
254
|
-
include SendGrid
|
|
255
|
-
|
|
256
|
-
sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
|
|
257
|
-
stats = SendGrid::EmailStats.new(sendgrid_client: sg_client)
|
|
258
|
-
|
|
259
|
-
# Fetch stats by day, between 2 dates
|
|
260
|
-
from = Date.new(2017, 10, 01)
|
|
261
|
-
to = Date.new(2017, 10, 12)
|
|
262
|
-
|
|
263
|
-
email_stats = stats.by_day(from, to)
|
|
264
|
-
|
|
265
|
-
email_stats.metrics
|
|
266
|
-
|
|
267
|
-
if !email_stats.error?
|
|
268
|
-
email_stats.metrics.each do |metric|
|
|
269
|
-
puts "Date - #{metric.date}"
|
|
270
|
-
puts "Number of Requests - #{metric.requests}"
|
|
271
|
-
puts "Bounces - #{metric.bounces}"
|
|
272
|
-
puts "Opens - #{metric.opens}"
|
|
273
|
-
puts "Clicks - #{metric.clicks}"
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
# Fetch stats by week, between 2 dates for a category
|
|
278
|
-
from = Date.new(2017, 10, 01)
|
|
279
|
-
to = Date.new(2017, 10, 12)
|
|
280
|
-
category = 'abcd'
|
|
281
|
-
|
|
282
|
-
email_stats = stats.by_week(from, to, category)
|
|
283
|
-
|
|
284
|
-
if !email_stats.error?
|
|
285
|
-
email_stats.metrics.each do |metric|
|
|
286
|
-
puts "Date - #{metric.date}"
|
|
287
|
-
puts "Number of Requests - #{metric.requests}"
|
|
288
|
-
puts "Bounces - #{metric.bounces}"
|
|
289
|
-
puts "Opens - #{metric.opens}"
|
|
290
|
-
puts "Clicks - #{metric.clicks}"
|
|
291
|
-
end
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
# Send an Email With Twilio Email (Pilot)
|
|
297
|
-
|
|
298
|
-
### 1. Obtain a Free Twilio Account
|
|
299
|
-
|
|
300
|
-
Sign up for a free Twilio account [here](https://www.twilio.com/try-twilio?source=sendgrid-ruby).
|
|
301
|
-
|
|
302
|
-
### 2. Set Up Your Environment Variables
|
|
303
|
-
|
|
304
|
-
The Twilio API allows for authentication using with either an API key/secret or your Account SID/Auth Token. You can create an API key [here](https://twil.io/get-api-key) or obtain your Account SID and Auth Token [here](https://twil.io/console).
|
|
305
|
-
|
|
306
|
-
Once you have those, follow the steps below based on your operating system.
|
|
307
|
-
|
|
308
|
-
#### Linux/Mac
|
|
309
|
-
|
|
310
|
-
```bash
|
|
311
|
-
echo "export TWILIO_API_KEY='YOUR_TWILIO_API_KEY'" > twilio.env
|
|
312
|
-
echo "export TWILIO_API_SECRET='YOUR_TWILIO_API_SECRET'" >> twilio.env
|
|
313
|
-
|
|
314
|
-
# or
|
|
315
|
-
|
|
316
|
-
echo "export TWILIO_ACCOUNT_SID='YOUR_TWILIO_ACCOUNT_SID'" > twilio.env
|
|
317
|
-
echo "export TWILIO_AUTH_TOKEN='YOUR_TWILIO_AUTH_TOKEN'" >> twilio.env
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
Then:
|
|
321
|
-
|
|
322
|
-
```bash
|
|
323
|
-
echo "twilio.env" >> .gitignore
|
|
324
|
-
source ./twilio.env
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
#### Windows
|
|
328
|
-
|
|
329
|
-
Temporarily set the environment variable (accessible only during the current CLI session):
|
|
330
|
-
|
|
331
|
-
```bash
|
|
332
|
-
set TWILIO_API_KEY=YOUR_TWILIO_API_KEY
|
|
333
|
-
set TWILIO_API_SECRET=YOUR_TWILIO_API_SECRET
|
|
334
|
-
|
|
335
|
-
: or
|
|
336
|
-
|
|
337
|
-
set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID
|
|
338
|
-
set TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
Or permanently set the environment variable (accessible in all subsequent CLI sessions):
|
|
342
|
-
|
|
343
|
-
```bash
|
|
344
|
-
setx TWILIO_API_KEY "YOUR_TWILIO_API_KEY"
|
|
345
|
-
setx TWILIO_API_SECRET "YOUR_TWILIO_API_SECRET"
|
|
346
|
-
|
|
347
|
-
: or
|
|
348
|
-
|
|
349
|
-
setx TWILIO_ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID"
|
|
350
|
-
setx TWILIO_AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN"
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
### 3. Initialize the Twilio Email Client
|
|
354
|
-
|
|
355
|
-
```ruby
|
|
356
|
-
mail_client = TwilioEmail::API(username: ENV['TWILIO_API_KEY'], password: ENV['TWILIO_API_SECRET'])
|
|
357
|
-
|
|
358
|
-
# or
|
|
359
|
-
|
|
360
|
-
mail_client = TwilioEmail::API(username: ENV['TWILIO_ACCOUNT_SID'], password: ENV['TWILIO_AUTH_TOKEN'])
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
This client has the same interface as the `SendGrid::API` client.
|
|
364
|
-
|
|
365
|
-
# Send an SMS Message
|
|
366
|
-
|
|
367
|
-
First, follow the above steps for creating a Twilio account and setting up environment variables with the proper credentials.
|
|
368
|
-
|
|
369
|
-
Then, install the Twilio Helper Library. Add this line to your application's Gemfile:
|
|
370
|
-
|
|
371
|
-
```bash
|
|
372
|
-
gem 'twilio-ruby'
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
And then execute:
|
|
376
|
-
|
|
377
|
-
```bash
|
|
378
|
-
bundle
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
Or install it yourself using:
|
|
382
|
-
|
|
383
|
-
```bash
|
|
384
|
-
gem install twilio-ruby
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
Finally, send a message.
|
|
388
|
-
|
|
389
|
-
```ruby
|
|
390
|
-
require 'twilio-ruby'
|
|
391
|
-
|
|
392
|
-
# put your own credentials here
|
|
393
|
-
account_sid = ENV['TWILIO_ACCOUNT_SID']
|
|
394
|
-
auth_token = ENV['TWILIO_AUTH_TOKEN']
|
|
395
|
-
|
|
396
|
-
# set up a client to talk to the Twilio REST API
|
|
397
|
-
@client = Twilio::REST::Client.new account_sid, auth_token
|
|
398
|
-
@client.api.account.messages.create(
|
|
399
|
-
from: '+14159341234',
|
|
400
|
-
to: '+16105557069',
|
|
401
|
-
body: 'Hey there!'
|
|
402
|
-
)
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
For more information, please visit the [Twilio SMS Ruby documentation](https://www.twilio.com/docs/sms/quickstart/ruby).
|
data/docker/Dockerfile
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
FROM ruby:2.5.1-jessie
|
|
2
|
-
|
|
3
|
-
# Clone sendgrid-ruby
|
|
4
|
-
WORKDIR /sources
|
|
5
|
-
RUN git clone https://github.com/sendgrid/sendgrid-ruby.git
|
|
6
|
-
|
|
7
|
-
# Bundle
|
|
8
|
-
WORKDIR /sources/sendgrid-ruby
|
|
9
|
-
RUN bundle install
|
|
10
|
-
|
|
11
|
-
# Install prism
|
|
12
|
-
RUN curl https://raw.githubusercontent.com/stoplightio/prism/master/install.sh | sh
|
data/docker/README.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Docker image for sendgrid-ruby
|
|
2
|
-
|
|
3
|
-
## Quickstart
|
|
4
|
-
1. [Install Docker](https://docs.docker.com/engine/installation/) on your machine.
|
|
5
|
-
2. Run `docker run --rm -it sendgrid/sendgrid-ruby irb`.
|
|
6
|
-
3. Run `require './lib/sendgrid-ruby.rb'`.
|
|
7
|
-
|
|
8
|
-
## Poke around
|
|
9
|
-
|
|
10
|
-
If you would like to just poke around in the image and check some examples:
|
|
11
|
-
```sh
|
|
12
|
-
docker run --rm -it sendgrid/sendgrid-ruby bash
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
If you want to mount your fork or specific version of the gem:
|
|
16
|
-
```sh
|
|
17
|
-
docker run --rm -v /path/to/local/sendgrid-ruby:/sources/sendgrid-ruby -it sendgrid/sendgrid-ruby bash
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Running tests
|
|
21
|
-
|
|
22
|
-
If you would like to run the tests present in the image:
|
|
23
|
-
```sh
|
|
24
|
-
docker run --rm sendgrid/sendgrid-ruby rake
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
If you want to run tests on your fork or a specific version, mount the codebase onto the image:
|
|
28
|
-
```sh
|
|
29
|
-
docker run --rm -v /path/to/local/sendgrid-ruby:/sources/sendgrid-ruby sendgrid/sendgrid-ruby rake
|
|
30
|
-
```
|