sendgrid-ruby 6.3.2 → 6.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a84b6e88237dcfab04ae17b076923e3ff2199683514b1f5916c4e0851f83b871
4
- data.tar.gz: 2d19e0c66fd9ff2abcc0a6b38ae8e080cbba4961dc12e2a086243069cd81f59b
3
+ metadata.gz: 0a99cbab593becca226765be0e10692ded5477764699344b3b93ca619aa3290e
4
+ data.tar.gz: 2db29c6f0abeef43197c19fd384a2760e42f0ba952ed490a3ba60efbab3a1261
5
5
  SHA512:
6
- metadata.gz: 534ea0a42703026d6fccab526263f44cf6fdcc3f65228fcbc06a6d3c7c6ad80dfc12e553d6273515d87f7595a170e171a9c897980a76b7c47d0a55b940551ffb
7
- data.tar.gz: b9f2b208e7838d3e9716678c5227eea427fc168e244fa5ba7709970f9a83ec49f9da18062494a2901a1efc6e46dbc9e67e0cfc9bc559b1b09089ee9747a2e47c
6
+ metadata.gz: 4c9853763d323eef8a89334648df9cb8f8a3ed30687fedd463cffaec72aa6f4ca6627280a7c7805f8040001370c96441810e32fcec5b1528961b114734c85664
7
+ data.tar.gz: f46c413bb546de8f57eaa1bc4cb85ef73a585a372a5df1417c7511d79797f9b42ddfb2a7797550e831182a597fe5bdeebd95ce794d9dd505a1434d5ad4e929f0
@@ -16,6 +16,6 @@ ratings:
16
16
  - "**.rb"
17
17
  exclude_paths:
18
18
  - examples/
19
+ - gemfiles/
19
20
  - spec/
20
21
  - test/
21
- - gemfiles/
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Exclude:
3
+ - examples/**/*
4
+ - gemfiles/**/*
5
+ - spec/**/*
6
+ - test/**/*
@@ -1,6 +1,19 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ [2020-07-22] Version 6.3.3
5
+ --------------------------
6
+ **Library - Chore**
7
+ - [PR #431](https://github.com/sendgrid/sendgrid-ruby/pull/431): migrate to new default sendgrid-oai branch. Thanks to [@eshanholtz](https://github.com/eshanholtz)!
8
+ - [PR #366](https://github.com/sendgrid/sendgrid-ruby/pull/366): add Rubocop configuration file. Thanks to [@RolandBurrows](https://github.com/RolandBurrows)!
9
+
10
+ **Library - Test**
11
+ - [PR #429](https://github.com/sendgrid/sendgrid-ruby/pull/429): fix the license test and actually run the test scripts. Thanks to [@childish-sambino](https://github.com/childish-sambino)!
12
+
13
+ **Library - Docs**
14
+ - [PR #273](https://github.com/sendgrid/sendgrid-ruby/pull/273): Create a Use Cases Directory and Associated Files. Thanks to [@alanunruh](https://github.com/alanunruh)!
15
+
16
+
4
17
  [2020-07-08] Version 6.3.2
5
18
  --------------------------
6
19
  **Library - Test**
@@ -124,20 +124,13 @@ Tests for the mail send and Web API v3 endpoints.
124
124
 
125
125
  The Web API v3 client is `sendgrid-ruby.rb`
126
126
 
127
- <a name="testing"></a>
128
127
  ## Testing
129
128
 
130
- All PRs require passing tests before the PR will be reviewed.
129
+ All PRs require passing tests before the PR will be reviewed. All test files are in the [`tests`](https://github.com/sendgrid/sendgrid-ruby/tree/master/test) directory. For the purposes of contributing to this repo, please update the [`test_sendgrid-ruby.rb`](https://github.com/sendgrid/sendgrid-ruby/blob/master/test/test_sendgrid-ruby.rb) file with unit tests as you modify the code.
131
130
 
132
- All test files are in the [`tests`](https://github.com/sendgrid/sendgrid-ruby/tree/master/test) directory.
131
+ The integration tests require a Twilio SendGrid mock API in order to execute. We've simplified setting this up using Docker to run the tests. You will just need [Docker Desktop](https://docs.docker.com/get-docker/) and `make`.
133
132
 
134
- For the purposes of contributing to this repo, please update the [`test_sendgrid-ruby.rb`](https://github.com/sendgrid/sendgrid-ruby/blob/master/test/test_sendgrid-ruby.rb) file with unit tests as you modify the code.
135
-
136
- To run the tests:
137
-
138
- ```bash
139
- rake
140
- ```
133
+ Once these are available, simply execute the Docker test target to run all tests: `make test-docker`. This command can also be used to open an interactive shell into the container where this library is installed. To start a *bash* shell for example, use this command: `command=bash make test-docker`.
141
134
 
142
135
  <a name="style-guidelines-and-naming-conventions"></a>
143
136
  ## Style Guidelines & Naming Conventions
data/Makefile CHANGED
@@ -4,11 +4,11 @@ install:
4
4
  gem install bundler:2.1.2; bundle install
5
5
 
6
6
  test:
7
- bundle exec rake spec
7
+ bundle exec rake
8
8
 
9
9
  test-integ: test
10
10
 
11
11
  version ?= ruby:latest
12
12
  test-docker:
13
- curl -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/prism/prism.sh -o prism.sh
13
+ curl -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/main/prism/prism.sh -o prism.sh
14
14
  version=$(version) bash ./prism.sh
data/README.md CHANGED
@@ -205,7 +205,6 @@ We encourage contribution to our libraries (you might even score some nifty swag
205
205
 
206
206
  - [Feature Request](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#feature_request)
207
207
  - [Bug Reports](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#submit_a_bug_report)
208
- - [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#cla)
209
208
  - [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#improvements_to_the_codebase)
210
209
  - [Review Pull Requests](https://github.com/sendgrid/sendgrid-ruby/blob/master/CONTRIBUTING.md#code-reviews)
211
210
 
@@ -1,3 +1,3 @@
1
1
  module SendGrid
2
- VERSION = '6.3.2'
2
+ VERSION = '6.3.3'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require_relative "../../../../lib/sendgrid/helpers/mail/mail"
2
- require_relative "../../../../lib/sendgrid/client"
2
+ require_relative "../../../../lib/sendgrid/sendgrid"
3
3
  include SendGrid
4
4
  require "json"
5
5
  require 'minitest/autorun'
@@ -34,7 +34,7 @@ class TestAPI < MiniTest::Test
34
34
  assert_equal(test_headers, sg.request_headers)
35
35
  assert_equal("v3", sg.version)
36
36
  assert_equal(subuser, sg.impersonate_subuser)
37
- assert_equal("6.3.2", SendGrid::VERSION)
37
+ assert_equal("6.3.3", SendGrid::VERSION)
38
38
  assert_instance_of(SendGrid::Client, sg.client)
39
39
  end
40
40
 
@@ -2652,76 +2652,65 @@ class TestAPI < MiniTest::Test
2652
2652
  self.assert_equal('200', response.status_code)
2653
2653
  end
2654
2654
 
2655
-
2656
- def test_license_file_correct_year_range
2657
- if File.exist?('./LICENSE.md')
2658
- # get only the first line from the license txt file
2659
- year_range = File.open('./LICENSE.md', &:readline).gsub(/[^\d-]/, '')
2660
- self.assert_equal("#{Time.now.year}", year_range)
2661
- end
2662
- end
2663
-
2664
- def test_docker_exists
2665
- assert(File.file?('./Docker') || File.file?('./docker/Dockerfile'))
2655
+ def test_license_file_year
2656
+ # Read the third line from the license file
2657
+ year = IO.readlines('./LICENSE.md')[2].gsub(/[^\d]/, '')
2658
+ self.assert_equal("#{Time.now.year}", year)
2666
2659
  end
2667
2660
 
2668
- # def test_docker_compose_exists
2669
- # assert(File.file?('./docker-compose.yml') || File.file?('./docker/docker-compose.yml'))
2670
- # end
2671
-
2672
2661
  def test_env_sample_exists
2673
- assert(File.file?('./.env_sample'))
2662
+ assert(File.file?('./.env_sample'))
2674
2663
  end
2675
2664
 
2676
2665
  def test_gitignore_exists
2677
- assert(File.file?('./.gitignore'))
2666
+ assert(File.file?('./.gitignore'))
2678
2667
  end
2679
2668
 
2680
2669
  def test_travis_exists
2681
- assert(File.file?('./.travis.yml'))
2670
+ assert(File.file?('./.travis.yml'))
2682
2671
  end
2683
2672
 
2684
2673
  def test_codeclimate_exists
2685
- assert(File.file?('./.codeclimate.yml'))
2674
+ assert(File.file?('./.codeclimate.yml'))
2686
2675
  end
2687
2676
 
2688
2677
  def test_changelog_exists
2689
- assert(File.file?('./CHANGELOG.md'))
2678
+ assert(File.file?('./CHANGELOG.md'))
2690
2679
  end
2691
2680
 
2692
2681
  def test_code_of_conduct_exists
2693
- assert(File.file?('./CODE_OF_CONDUCT.md'))
2682
+ assert(File.file?('./CODE_OF_CONDUCT.md'))
2694
2683
  end
2695
2684
 
2696
2685
  def test_contributing_exists
2697
- assert(File.file?('./CONTRIBUTING.md'))
2686
+ assert(File.file?('./CONTRIBUTING.md'))
2698
2687
  end
2699
2688
 
2700
2689
  def test_issue_template_exists
2701
- assert(File.file?('./ISSUE_TEMPLATE.md'))
2690
+ assert(File.file?('./ISSUE_TEMPLATE.md'))
2702
2691
  end
2703
2692
 
2704
2693
  def test_license_exists
2705
- assert(File.file?('./LICENSE.md'))
2694
+ assert(File.file?('./LICENSE.md'))
2706
2695
  end
2707
2696
 
2708
- def test_pull_request_template_exists
2709
- assert(File.file?('./PULL_REQUEST_TEMPLATE.md'))
2697
+ def test_pr_template_exists
2698
+ assert(File.file?('./PULL_REQUEST_TEMPLATE.md'))
2710
2699
  end
2711
2700
 
2712
2701
  def test_readme_exists
2713
- assert(File.file?('./README.md'))
2702
+ assert(File.file?('./README.md'))
2714
2703
  end
2715
2704
 
2716
2705
  def test_troubleshooting_exists
2717
- assert(File.file?('./TROUBLESHOOTING.md'))
2706
+ assert(File.file?('./TROUBLESHOOTING.md'))
2718
2707
  end
2719
2708
 
2720
2709
  def test_usage_exists
2721
- assert(File.file?('./USAGE.md'))
2710
+ assert(File.file?('./USAGE.md'))
2722
2711
  end
2723
2712
 
2724
- def test_use_cases_exists
2725
- assert(File.file?('./USE_CASES.md'))
2713
+ def test_use_cases_readme_exists
2714
+ assert(File.file?('./use-cases/README.md'))
2726
2715
  end
2727
2716
  end
@@ -0,0 +1,16 @@
1
+ This directory provides examples for specific use cases.
2
+
3
+ Please [open an issue](https://github.com/sendgrid/sendgrid-ruby/issues) or [make a pull request](https://github.com/sendgrid/sendgrid-ruby/pulls) for any use cases you would like us to document here. Thank you!
4
+
5
+ # Email Use Cases
6
+ * [Transactional Templates](transactional-templates.md)
7
+ * [Legacy Templates](legacy-templates.md)
8
+
9
+ # Twilio Use Cases
10
+ * [Twilio Setup](twilio-setup.md)
11
+ * [Send an Email With Twilio Email (Pilot)](twilio-email.md)
12
+ * [Send an SMS Message](sms.md)
13
+
14
+ # Non-Email Use Cases
15
+ * [How to Set up a Domain Authentication](domain-authentication.md)
16
+ * [How to View Email Statistics](email-statistics.md)
@@ -0,0 +1,5 @@
1
+ # How to Setup a Domain Authentication
2
+
3
+ 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-ruby/blob/master/USAGE.md#sender-authentication).
4
+
5
+ Find more information about all of Twilio SendGrid's authentication related documentation [here](https://sendgrid.com/docs/ui/account-and-settings/).
@@ -0,0 +1,52 @@
1
+ # How to View Email Statistics
2
+
3
+ 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).
4
+
5
+ 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.
6
+
7
+ You can also use the email statistics helper to make it easier to interact with the API.
8
+
9
+ ```ruby
10
+ require 'sendgrid-ruby'
11
+ require 'date'
12
+
13
+ include SendGrid
14
+
15
+ sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
16
+ stats = SendGrid::EmailStats.new(sendgrid_client: sg_client)
17
+
18
+ # Fetch stats by day, between 2 dates
19
+ from = Date.new(2017, 10, 01)
20
+ to = Date.new(2017, 10, 12)
21
+
22
+ email_stats = stats.by_day(from, to)
23
+
24
+ email_stats.metrics
25
+
26
+ if !email_stats.error?
27
+ email_stats.metrics.each do |metric|
28
+ puts "Date - #{metric.date}"
29
+ puts "Number of Requests - #{metric.requests}"
30
+ puts "Bounces - #{metric.bounces}"
31
+ puts "Opens - #{metric.opens}"
32
+ puts "Clicks - #{metric.clicks}"
33
+ end
34
+ end
35
+
36
+ # Fetch stats by week, between 2 dates for a category
37
+ from = Date.new(2017, 10, 01)
38
+ to = Date.new(2017, 10, 12)
39
+ category = 'abcd'
40
+
41
+ email_stats = stats.by_week(from, to, category)
42
+
43
+ if !email_stats.error?
44
+ email_stats.metrics.each do |metric|
45
+ puts "Date - #{metric.date}"
46
+ puts "Number of Requests - #{metric.requests}"
47
+ puts "Bounces - #{metric.bounces}"
48
+ puts "Opens - #{metric.opens}"
49
+ puts "Clicks - #{metric.clicks}"
50
+ end
51
+ end
52
+ ```
@@ -0,0 +1,98 @@
1
+ # Legacy Templates
2
+
3
+ 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.
4
+
5
+ Template ID (replace with your own):
6
+ ```text
7
+ 13b8f94f-bcae-4ec6-b752-70d6cb59f932
8
+ ```
9
+
10
+ Email Subject:
11
+ ```text
12
+ <%subject%>
13
+ ```
14
+
15
+ Template Body:
16
+ ```html
17
+ <html>
18
+ <head>
19
+ <title></title>
20
+ </head>
21
+ <body>
22
+ Hello -name-,
23
+ <br /><br/>
24
+ I'm glad you are trying out the template feature!
25
+ <br /><br/>
26
+ <%body%>
27
+ <br /><br/>
28
+ I hope you are having a great day in -city- :)
29
+ <br /><br/>
30
+ </body>
31
+ </html>
32
+ ```
33
+
34
+ ## With Mail Helper Class
35
+
36
+ ```ruby
37
+ require 'sendgrid-ruby'
38
+ include SendGrid
39
+
40
+ mail = SendGrid::Mail.new
41
+ mail.from = Email.new(email: 'test@example.com')
42
+ mail.subject = 'I\'m replacing the subject tag'
43
+ personalization = Personalization.new
44
+ personalization.add_to(Email.new(email: 'test@example.com'))
45
+ personalization.add_substitution(Substitution.new(key: '-name-', value: 'Example User'))
46
+ personalization.add_substitution(Substitution.new(key: '-city-', value: 'Denver'))
47
+ mail.add_personalization(personalization)
48
+ mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
49
+
50
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
51
+ begin
52
+ response = sg.client.mail._("send").post(request_body: mail.to_json)
53
+ rescue Exception => e
54
+ puts e.message
55
+ end
56
+ puts response.status_code
57
+ puts response.body
58
+ puts response.parsed_body
59
+ puts response.headers
60
+ ```
61
+
62
+ ## Without Mail Helper Class
63
+
64
+ ```ruby
65
+ require 'sendgrid-ruby'
66
+ include SendGrid
67
+
68
+ data = JSON.parse('{
69
+ "personalizations": [
70
+ {
71
+ "to": [
72
+ {
73
+ "email": "test@example.com"
74
+ }
75
+ ],
76
+ "substitutions": {
77
+ "-name-": "Example User",
78
+ "-city-": "Denver"
79
+ },
80
+ "subject": "I\'m replacing the subject tag"
81
+ }
82
+ ],
83
+ "from": {
84
+ "email": "test@example.com"
85
+ },
86
+ "template_id": "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
87
+ }')
88
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
89
+ begin
90
+ response = sg.client.mail._("send").post(request_body: data)
91
+ rescue Exception => e
92
+ puts e.message
93
+ end
94
+ puts response.status_code
95
+ puts response.body
96
+ puts response.parsed_body
97
+ puts response.headers
98
+ ```
@@ -0,0 +1,39 @@
1
+ First, follow the [Twilio Setup](twilio-setup.md) guide for creating a Twilio account and setting up environment variables with the proper credentials.
2
+
3
+ Then, install the Twilio Helper Library. Add this line to your application's Gemfile:
4
+
5
+ ```bash
6
+ gem 'twilio-ruby'
7
+ ```
8
+
9
+ And then execute:
10
+
11
+ ```bash
12
+ bundle
13
+ ```
14
+
15
+ Or install it yourself using:
16
+
17
+ ```bash
18
+ gem install twilio-ruby
19
+ ```
20
+
21
+ Finally, send a message.
22
+
23
+ ```ruby
24
+ require 'twilio-ruby'
25
+
26
+ # put your own credentials here
27
+ account_sid = ENV['TWILIO_ACCOUNT_SID']
28
+ auth_token = ENV['TWILIO_AUTH_TOKEN']
29
+
30
+ # set up a client to talk to the Twilio REST API
31
+ @client = Twilio::REST::Client.new account_sid, auth_token
32
+ @client.api.account.messages.create(
33
+ from: '+14159341234',
34
+ to: '+16105557069',
35
+ body: 'Hey there!'
36
+ )
37
+ ```
38
+
39
+ For more information, please visit the [Twilio SMS Ruby documentation](https://www.twilio.com/docs/sms/quickstart/ruby).
@@ -0,0 +1,111 @@
1
+ # Transactional Templates
2
+
3
+ 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.
4
+
5
+ Template ID (replace with your own):
6
+ ```text
7
+ d-2c214ac919e84170b21855cc129b4a5f
8
+ ```
9
+
10
+ Email Subject:
11
+ ```text
12
+ {{subject}}
13
+ ```
14
+
15
+ Template Body:
16
+ ```html
17
+ <html>
18
+ <head>
19
+ <title></title>
20
+ </head>
21
+ <body>
22
+ Hello {{name}},
23
+ <br/><br/>
24
+ I'm glad you are trying out the template feature!
25
+ <br/><br/>
26
+ I hope you are having a great day in {{city}} :)
27
+ <br/><br/>
28
+ </body>
29
+ </html>
30
+ ```
31
+
32
+ ## With Mail Helper Class
33
+ ```ruby
34
+ require 'sendgrid-ruby'
35
+ include SendGrid
36
+
37
+ mail = Mail.new
38
+ mail.from = Email.new(email: 'test@example.com')
39
+ personalization = Personalization.new
40
+ personalization.add_to(Email.new(email: 'test@example.com'))
41
+ personalization.add_dynamic_template_data({
42
+ "subject" => "Testing Templates",
43
+ "name" => "Example User",
44
+ "city" => "Denver"
45
+ })
46
+ mail.add_personalization(personalization)
47
+ mail.template_id = 'd-2c214ac919e84170b21855cc129b4a5f'
48
+
49
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
50
+ begin
51
+ response = sg.client.mail._("send").post(request_body: mail.to_json)
52
+ rescue Exception => e
53
+ puts e.message
54
+ end
55
+ puts response.status_code
56
+ puts response.body
57
+ puts response.parsed_body
58
+ puts response.headers
59
+ ```
60
+
61
+ ## Without Mail Helper Class
62
+
63
+ ```ruby
64
+ require 'sendgrid-ruby'
65
+ include SendGrid
66
+
67
+ data = JSON.parse('{
68
+ "personalizations": [
69
+ {
70
+ "to": [
71
+ {
72
+ "email": "test@example.com"
73
+ }
74
+ ],
75
+ "dynamic_template_data": {
76
+ "subject": "Testing Templates",
77
+ "name": "Example User",
78
+ "city": "Denver"
79
+ }
80
+ }
81
+ ],
82
+ "from": {
83
+ "email": "test@example.com"
84
+ },
85
+ "template_id": "d-2c214ac919e84170b21855cc129b4a5f"
86
+ }')
87
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
88
+ begin
89
+ response = sg.client.mail._("send").post(request_body: data)
90
+ rescue Exception => e
91
+ puts e.message
92
+ end
93
+ puts response.status_code
94
+ puts response.body
95
+ puts response.parsed_body
96
+ puts response.headers
97
+ ```
98
+
99
+ ## Adding Attachments
100
+
101
+ ```ruby
102
+ attachment = Attachment.new
103
+ attachment.content = Base64.strict_encode64(File.open(fpath, 'rb').read)
104
+ attachment.type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
105
+ attachment.filename = fname
106
+ attachment.disposition = 'attachment'
107
+ attachment.content_id = 'Reports Sheet'
108
+ mail.add_attachment(attachment)
109
+ ```
110
+
111
+ Attachments must be base64 encoded, using Base64's strict_encode64 where no line feeds are added.
@@ -0,0 +1,13 @@
1
+ First, follow the [Twilio Setup](twilio-setup.md) guide for creating a Twilio account and setting up environment variables with the proper credentials.
2
+
3
+ Then, initialize the Twilio Email Client.
4
+
5
+ ```ruby
6
+ mail_client = TwilioEmail::API(username: ENV['TWILIO_API_KEY'], password: ENV['TWILIO_API_SECRET'])
7
+
8
+ # or
9
+
10
+ mail_client = TwilioEmail::API(username: ENV['TWILIO_ACCOUNT_SID'], password: ENV['TWILIO_AUTH_TOKEN'])
11
+ ```
12
+
13
+ This client has the same interface as the `SendGrid::API` client.
@@ -0,0 +1,54 @@
1
+ ## 1. Obtain a Free Twilio Account
2
+
3
+ Sign up for a free Twilio account [here](https://www.twilio.com/try-twilio?source=sendgrid-ruby).
4
+
5
+ ## 2. Set Up Your Environment Variables
6
+
7
+ 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).
8
+
9
+ Once you have those, follow the steps below based on your operating system.
10
+
11
+ ### Linux/Mac
12
+
13
+ ```bash
14
+ echo "export TWILIO_API_KEY='YOUR_TWILIO_API_KEY'" > twilio.env
15
+ echo "export TWILIO_API_SECRET='YOUR_TWILIO_API_SECRET'" >> twilio.env
16
+
17
+ # or
18
+
19
+ echo "export TWILIO_ACCOUNT_SID='YOUR_TWILIO_ACCOUNT_SID'" > twilio.env
20
+ echo "export TWILIO_AUTH_TOKEN='YOUR_TWILIO_AUTH_TOKEN'" >> twilio.env
21
+ ```
22
+
23
+ Then:
24
+
25
+ ```bash
26
+ echo "twilio.env" >> .gitignore
27
+ source ./twilio.env
28
+ ```
29
+
30
+ ### Windows
31
+
32
+ Temporarily set the environment variable (accessible only during the current CLI session):
33
+
34
+ ```bash
35
+ set TWILIO_API_KEY=YOUR_TWILIO_API_KEY
36
+ set TWILIO_API_SECRET=YOUR_TWILIO_API_SECRET
37
+
38
+ : or
39
+
40
+ set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID
41
+ set TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN
42
+ ```
43
+
44
+ Or permanently set the environment variable (accessible in all subsequent CLI sessions):
45
+
46
+ ```bash
47
+ setx TWILIO_API_KEY "YOUR_TWILIO_API_KEY"
48
+ setx TWILIO_API_SECRET "YOUR_TWILIO_API_SECRET"
49
+
50
+ : or
51
+
52
+ setx TWILIO_ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID"
53
+ setx TWILIO_AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN"
54
+ ```
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.3.2
4
+ version: 6.3.3
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-07-08 00:00:00.000000000 Z
13
+ date: 2020-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ruby_http_client
@@ -168,6 +168,7 @@ files:
168
168
  - ".codeclimate.yml"
169
169
  - ".env_sample"
170
170
  - ".gitignore"
171
+ - ".rubocop.yml"
171
172
  - ".travis.yml"
172
173
  - CHANGELOG.md
173
174
  - CODE_OF_CONDUCT.md
@@ -183,10 +184,7 @@ files:
183
184
  - TROUBLESHOOTING.md
184
185
  - UPGRADE.md
185
186
  - USAGE.md
186
- - USE_CASES.md
187
187
  - config.ru
188
- - docker/Dockerfile
189
- - docker/README.md
190
188
  - examples/accesssettings/accesssettings.rb
191
189
  - examples/alerts/alerts.rb
192
190
  - examples/apikeys/apikeys.rb
@@ -291,6 +289,14 @@ files:
291
289
  - test/sendgrid/helpers/mail/test_personalizations.rb
292
290
  - test/sendgrid/permissions/test_scopes.rb
293
291
  - test/sendgrid/test_sendgrid-ruby.rb
292
+ - use-cases/README.md
293
+ - use-cases/domain-authentication.md
294
+ - use-cases/email-statistics.md
295
+ - use-cases/legacy-templates.md
296
+ - use-cases/sms.md
297
+ - use-cases/transactional-templates.md
298
+ - use-cases/twilio-email.md
299
+ - use-cases/twilio-setup.md
294
300
  homepage: http://github.com/sendgrid/sendgrid-ruby
295
301
  licenses:
296
302
  - MIT
@@ -310,8 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
310
316
  - !ruby/object:Gem::Version
311
317
  version: '0'
312
318
  requirements: []
313
- rubyforge_project:
314
- rubygems_version: 2.7.7
319
+ rubygems_version: 3.0.8
315
320
  signing_key:
316
321
  specification_version: 4
317
322
  summary: Official Twilio SendGrid Gem
@@ -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).
@@ -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
@@ -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
- ```