sendgrid-ruby 6.1.4 → 6.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/USE_CASES.md +58 -30
- data/lib/sendgrid-ruby.rb +3 -1
- data/lib/sendgrid/base_interface.rb +36 -0
- data/lib/sendgrid/sendgrid.rb +20 -0
- data/lib/sendgrid/twilio_email.rb +21 -0
- data/lib/sendgrid/version.rb +1 -1
- data/spec/sendgrid/sendgrid_spec.rb +11 -0
- data/spec/sendgrid/twilio_email_spec.rb +11 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +1 -1
- metadata +9 -3
- data/lib/sendgrid/client.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eebc101d8e4c0fd0b310052df65639517dce3d1274d8469f7ca12c7854307b06
|
4
|
+
data.tar.gz: 89565ce858129ddbf1921a474b34661f18852241339225038181e43c58f74af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 180658efc2dd204c30090d9ca812430e36f75280519e054991227a5b6d5dd6f49860e84284ed7e51ebb9039d1460ad59a3cf269736c69cfd12d1f49b4e732501
|
7
|
+
data.tar.gz: 060a8cee0e604d646be5dfdeee262eb2fb244c8c17d1ed0d6c112d004506201f2092c125e4cfda2c96a04a92b6bdc6b7a91b44f6149bba4ca4753a08cca0c10d
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
[2020-04-29] Version 6.2.0
|
5
|
+
--------------------------
|
6
|
+
**Library - Feature**
|
7
|
+
- [PR #417](https://github.com/sendgrid/sendgrid-ruby/pull/417): add support for Twilio Email. Thanks to [@childish-sambino](https://github.com/childish-sambino)!
|
8
|
+
|
9
|
+
|
4
10
|
[2020-04-15] Version 6.1.4
|
5
11
|
--------------------------
|
6
12
|
**Library - Fix**
|
data/USE_CASES.md
CHANGED
@@ -11,14 +11,8 @@ This documentation provides examples for specific use cases. Please [open an iss
|
|
11
11
|
* [Adding Attachments](#adding-attachments)
|
12
12
|
* [How to Setup a Domain Authentication](#how-to-setup-a-domain-authentication)
|
13
13
|
* [How to View Email Statistics](#how-to-view-email-statistics)
|
14
|
-
* [Send
|
15
|
-
|
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)
|
14
|
+
* [Send an Email With Twilio Email (Pilot)](#send-an-email-with-twilio-email-pilot)
|
15
|
+
* [Send an SMS Message](#send-an-sms-message)
|
22
16
|
|
23
17
|
<a name="transactional-templates"></a>
|
24
18
|
# Transactional Templates
|
@@ -299,59 +293,98 @@ end
|
|
299
293
|
|
300
294
|
```
|
301
295
|
|
302
|
-
|
303
|
-
# Send a SMS Message
|
296
|
+
# Send an Email With Twilio Email (Pilot)
|
304
297
|
|
305
|
-
|
306
|
-
|
307
|
-
## 1. Obtain a Free Twilio Account
|
298
|
+
### 1. Obtain a Free Twilio Account
|
308
299
|
|
309
300
|
Sign up for a free Twilio account [here](https://www.twilio.com/try-twilio?source=sendgrid-ruby).
|
310
301
|
|
311
|
-
|
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).
|
312
305
|
|
313
|
-
|
306
|
+
Once you have those, follow the steps below based on your operating system.
|
314
307
|
|
315
|
-
|
308
|
+
#### Linux/Mac
|
316
309
|
|
317
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
|
+
|
318
316
|
echo "export TWILIO_ACCOUNT_SID='YOUR_TWILIO_ACCOUNT_SID'" > twilio.env
|
319
317
|
echo "export TWILIO_AUTH_TOKEN='YOUR_TWILIO_AUTH_TOKEN'" >> twilio.env
|
318
|
+
```
|
319
|
+
|
320
|
+
Then:
|
321
|
+
|
322
|
+
```bash
|
320
323
|
echo "twilio.env" >> .gitignore
|
321
324
|
source ./twilio.env
|
322
325
|
```
|
323
326
|
|
324
|
-
|
327
|
+
#### Windows
|
325
328
|
|
326
329
|
Temporarily set the environment variable (accessible only during the current CLI session):
|
327
330
|
|
328
331
|
```bash
|
332
|
+
set TWILIO_API_KEY=YOUR_TWILIO_API_KEY
|
333
|
+
set TWILIO_API_SECRET=YOUR_TWILIO_API_SECRET
|
334
|
+
|
335
|
+
: or
|
336
|
+
|
329
337
|
set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID
|
330
338
|
set TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN
|
331
339
|
```
|
332
340
|
|
333
|
-
|
341
|
+
Or permanently set the environment variable (accessible in all subsequent CLI sessions):
|
334
342
|
|
335
343
|
```bash
|
344
|
+
setx TWILIO_API_KEY "YOUR_TWILIO_API_KEY"
|
345
|
+
setx TWILIO_API_SECRET "YOUR_TWILIO_API_SECRET"
|
346
|
+
|
347
|
+
: or
|
348
|
+
|
336
349
|
setx TWILIO_ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID"
|
337
350
|
setx TWILIO_AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN"
|
338
351
|
```
|
339
352
|
|
340
|
-
|
341
|
-
|
342
|
-
To install using [Bundler][bundler] grab the latest stable version:
|
353
|
+
### 3. Initialize the Twilio Email Client
|
343
354
|
|
344
355
|
```ruby
|
345
|
-
|
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'])
|
346
361
|
```
|
347
362
|
|
348
|
-
|
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:
|
349
376
|
|
350
377
|
```bash
|
351
|
-
|
378
|
+
bundle
|
352
379
|
```
|
353
380
|
|
354
|
-
|
381
|
+
Or install it yourself using:
|
382
|
+
|
383
|
+
```bash
|
384
|
+
gem install twilio-ruby
|
385
|
+
```
|
386
|
+
|
387
|
+
Finally, send a message.
|
355
388
|
|
356
389
|
```ruby
|
357
390
|
require 'twilio-ruby'
|
@@ -362,11 +395,6 @@ auth_token = ENV['TWILIO_AUTH_TOKEN']
|
|
362
395
|
|
363
396
|
# set up a client to talk to the Twilio REST API
|
364
397
|
@client = Twilio::REST::Client.new account_sid, auth_token
|
365
|
-
```
|
366
|
-
|
367
|
-
## 5. Send an SMS
|
368
|
-
|
369
|
-
```ruby
|
370
398
|
@client.api.account.messages.create(
|
371
399
|
from: '+14159341234',
|
372
400
|
to: '+16105557069',
|
data/lib/sendgrid-ruby.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
require_relative 'sendgrid/
|
1
|
+
require_relative 'sendgrid/base_interface'
|
2
|
+
require_relative 'sendgrid/sendgrid'
|
3
|
+
require_relative 'sendgrid/twilio_email'
|
2
4
|
require_relative 'sendgrid/version'
|
3
5
|
require_relative 'sendgrid/helpers/ip_management/ip_management'
|
4
6
|
require_relative 'sendgrid/helpers/mail/asm'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'ruby_http_client'
|
2
|
+
require_relative 'version'
|
3
|
+
|
4
|
+
# Initialize the HTTP client
|
5
|
+
class BaseInterface
|
6
|
+
attr_accessor :client
|
7
|
+
attr_reader :request_headers, :host, :version, :impersonate_subuser
|
8
|
+
# * *Args* :
|
9
|
+
# - +auth+ -> authorization header value
|
10
|
+
# - +host+ -> the base URL for the API
|
11
|
+
# - +request_headers+ -> any headers that you want to be globally applied
|
12
|
+
# - +version+ -> the version of the API you wish to access,
|
13
|
+
# currently only "v3" is supported
|
14
|
+
# - +impersonate_subuser+ -> the subuser to impersonate, will be passed
|
15
|
+
# in the "On-Behalf-Of" header
|
16
|
+
#
|
17
|
+
def initialize(auth:, host:, request_headers: nil, version: nil, impersonate_subuser: nil)
|
18
|
+
@auth = auth
|
19
|
+
@host = host
|
20
|
+
@version = version ? version : 'v3'
|
21
|
+
@impersonate_subuser = impersonate_subuser
|
22
|
+
@user_agent = "sendgrid/#{SendGrid::VERSION};ruby"
|
23
|
+
@request_headers = JSON.parse('
|
24
|
+
{
|
25
|
+
"Authorization": "' + @auth + '",
|
26
|
+
"Accept": "application/json",
|
27
|
+
"User-Agent": "' + @user_agent + '"
|
28
|
+
}
|
29
|
+
')
|
30
|
+
@request_headers['On-Behalf-Of'] = @impersonate_subuser if @impersonate_subuser
|
31
|
+
|
32
|
+
@request_headers = @request_headers.merge(request_headers) if request_headers
|
33
|
+
@client = SendGrid::Client.new(host: "#{@host}/#{@version}",
|
34
|
+
request_headers: @request_headers)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Quickly and easily access the Twilio SendGrid API.
|
2
|
+
module SendGrid
|
3
|
+
class API < BaseInterface
|
4
|
+
# * *Args* :
|
5
|
+
# - +api_key+ -> your Twilio SendGrid API key
|
6
|
+
# - +host+ -> the base URL for the API
|
7
|
+
# - +request_headers+ -> any headers that you want to be globally applied
|
8
|
+
# - +version+ -> the version of the API you wish to access,
|
9
|
+
# currently only "v3" is supported
|
10
|
+
# - +impersonate_subuser+ -> the subuser to impersonate, will be passed
|
11
|
+
# in the "On-Behalf-Of" header
|
12
|
+
#
|
13
|
+
def initialize(api_key:, host: nil, request_headers: nil, version: nil, impersonate_subuser: nil)
|
14
|
+
auth = "Bearer #{api_key}"
|
15
|
+
host = 'https://api.sendgrid.com' unless host
|
16
|
+
|
17
|
+
super(auth: auth, host: host, request_headers: request_headers, version: version, impersonate_subuser: impersonate_subuser)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Quickly and easily access the Twilio Email API.
|
2
|
+
module TwilioEmail
|
3
|
+
class API < BaseInterface
|
4
|
+
# * *Args* :
|
5
|
+
# - +username+ -> your Twilio Email API key SID or Account SID
|
6
|
+
# - +password+ -> your Twilio Email API key secret or Account Auth Token
|
7
|
+
# - +host+ -> the base URL for the API
|
8
|
+
# - +request_headers+ -> any headers that you want to be globally applied
|
9
|
+
# - +version+ -> the version of the API you wish to access,
|
10
|
+
# currently only "v3" is supported
|
11
|
+
# - +impersonate_subuser+ -> the subuser to impersonate, will be passed
|
12
|
+
# in the "On-Behalf-Of" header
|
13
|
+
#
|
14
|
+
def initialize(username:, password:, host: nil, request_headers: nil, version: nil, impersonate_subuser: nil)
|
15
|
+
auth = "Basic #{Base64.strict_encode64("#{username}:#{password}")}"
|
16
|
+
host = 'https://email.twilio.com' unless host
|
17
|
+
|
18
|
+
super(auth: auth, host: host, request_headers: request_headers, version: version, impersonate_subuser: impersonate_subuser)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/sendgrid/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SendGrid::API do
|
4
|
+
describe '.new' do
|
5
|
+
it 'initializes correctly' do
|
6
|
+
mail_client = SendGrid::API.new(api_key: 'fake_key')
|
7
|
+
expect(mail_client.request_headers['Authorization']).to eq('Bearer fake_key')
|
8
|
+
expect(mail_client.host).to eq('https://api.sendgrid.com')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TwilioEmail::API do
|
4
|
+
describe '.new' do
|
5
|
+
it 'initializes correctly' do
|
6
|
+
mail_client = TwilioEmail::API.new(username: 'username', password: 'password')
|
7
|
+
expect(mail_client.request_headers['Authorization']).to eq('Basic dXNlcm5hbWU6cGFzc3dvcmQ=')
|
8
|
+
expect(mail_client.host).to eq('https://email.twilio.com')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -58,7 +58,7 @@ class TestAPI < MiniTest::Test
|
|
58
58
|
assert_equal(test_headers, sg.request_headers)
|
59
59
|
assert_equal("v3", sg.version)
|
60
60
|
assert_equal(subuser, sg.impersonate_subuser)
|
61
|
-
assert_equal("6.
|
61
|
+
assert_equal("6.2.0", SendGrid::VERSION)
|
62
62
|
assert_instance_of(SendGrid::Client, sg.client)
|
63
63
|
end
|
64
64
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elmer Thomas
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-04-
|
13
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_http_client
|
@@ -189,7 +189,7 @@ files:
|
|
189
189
|
- gemfiles/Sinatra_1.gemfile
|
190
190
|
- gemfiles/Sinatra_2.gemfile
|
191
191
|
- lib/sendgrid-ruby.rb
|
192
|
-
- lib/sendgrid/
|
192
|
+
- lib/sendgrid/base_interface.rb
|
193
193
|
- lib/sendgrid/helpers/inbound/README.md
|
194
194
|
- lib/sendgrid/helpers/inbound/app.rb
|
195
195
|
- lib/sendgrid/helpers/inbound/config.yml
|
@@ -232,6 +232,8 @@ files:
|
|
232
232
|
- lib/sendgrid/helpers/stats/email_stats.rb
|
233
233
|
- lib/sendgrid/helpers/stats/metrics.rb
|
234
234
|
- lib/sendgrid/helpers/stats/stats_response.rb
|
235
|
+
- lib/sendgrid/sendgrid.rb
|
236
|
+
- lib/sendgrid/twilio_email.rb
|
235
237
|
- lib/sendgrid/version.rb
|
236
238
|
- mail_helper_v3.md
|
237
239
|
- sendgrid-ruby.gemspec
|
@@ -244,6 +246,8 @@ files:
|
|
244
246
|
- spec/sendgrid/helpers/stats/email_stats_spec.rb
|
245
247
|
- spec/sendgrid/helpers/stats/metrics_spec.rb
|
246
248
|
- spec/sendgrid/helpers/stats/stats_response_spec.rb
|
249
|
+
- spec/sendgrid/sendgrid_spec.rb
|
250
|
+
- spec/sendgrid/twilio_email_spec.rb
|
247
251
|
- spec/spec_helper.rb
|
248
252
|
- test/prism.sh
|
249
253
|
- test/sendgrid/helpers/mail/test_attachment.rb
|
@@ -286,6 +290,8 @@ test_files:
|
|
286
290
|
- spec/sendgrid/helpers/stats/email_stats_spec.rb
|
287
291
|
- spec/sendgrid/helpers/stats/metrics_spec.rb
|
288
292
|
- spec/sendgrid/helpers/stats/stats_response_spec.rb
|
293
|
+
- spec/sendgrid/sendgrid_spec.rb
|
294
|
+
- spec/sendgrid/twilio_email_spec.rb
|
289
295
|
- spec/spec_helper.rb
|
290
296
|
- test/prism.sh
|
291
297
|
- test/sendgrid/helpers/mail/test_attachment.rb
|
data/lib/sendgrid/client.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# Quickly and easily access the Twilio SendGrid API.
|
2
|
-
require 'ruby_http_client'
|
3
|
-
require_relative 'version'
|
4
|
-
|
5
|
-
module SendGrid
|
6
|
-
# Initialize the HTTP client
|
7
|
-
class API
|
8
|
-
attr_accessor :client
|
9
|
-
attr_reader :request_headers, :host, :version, :impersonate_subuser
|
10
|
-
# * *Args* :
|
11
|
-
# - +api_key+ -> your Twilio SendGrid API key
|
12
|
-
# - +host+ -> the base URL for the API
|
13
|
-
# - +request_headers+ -> any headers that you want to be globally applied
|
14
|
-
# - +version+ -> the version of the API you wish to access,
|
15
|
-
# currently only "v3" is supported
|
16
|
-
#
|
17
|
-
def initialize(api_key: '', host: nil, request_headers: nil, version: nil, impersonate_subuser: nil)
|
18
|
-
@api_key = api_key
|
19
|
-
@host = host ? host : 'https://api.sendgrid.com'
|
20
|
-
@version = version ? version : 'v3'
|
21
|
-
@impersonate_subuser = impersonate_subuser
|
22
|
-
@user_agent = "sendgrid/#{SendGrid::VERSION};ruby"
|
23
|
-
@request_headers = JSON.parse('
|
24
|
-
{
|
25
|
-
"Authorization": "Bearer ' + @api_key + '",
|
26
|
-
"Accept": "application/json",
|
27
|
-
"User-Agent": "' + @user_agent + '"
|
28
|
-
}
|
29
|
-
')
|
30
|
-
@request_headers['On-Behalf-Of'] = @impersonate_subuser if @impersonate_subuser
|
31
|
-
|
32
|
-
|
33
|
-
@request_headers = @request_headers.merge(request_headers) if request_headers
|
34
|
-
@client = Client.new(host: "#{@host}/#{@version}",
|
35
|
-
request_headers: @request_headers)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|