ruby_http_client 3.2.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +16 -0
- data/.env_sample +1 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +47 -0
- data/.travis.yml +34 -13
- data/CHANGELOG.md +87 -0
- data/CODE_OF_CONDUCT.md +73 -0
- data/CONTRIBUTING.md +36 -50
- data/FIRST_TIMERS.md +79 -0
- data/Gemfile +3 -0
- data/ISSUE_TEMPLATE.md +30 -0
- data/{LICENSE.txt → LICENSE.md} +8 -8
- data/Makefile +7 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +54 -18
- data/Rakefile +25 -2
- data/TROUBLESHOOTING.md +17 -0
- data/USAGE.md +108 -0
- data/examples/example.rb +29 -1
- data/lib/ruby_http_client.rb +119 -22
- data/ruby_http_client.gemspec +16 -13
- data/static/img/github-fork.png +0 -0
- data/static/img/github-sign-up.png +0 -0
- data/test/test_helper.rb +7 -0
- data/test/test_ruby_http_client.rb +237 -11
- data/twilio_sendgrid_logo.png +0 -0
- data/use_cases/README.md +3 -0
- metadata +80 -9
- data/.github/ISSUE_TEMPLATE +0 -17
data/FIRST_TIMERS.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# How To Contribute to Twilio SendGrid Repositories via GitHub
|
2
|
+
Contributing to the Twilio SendGrid repositories is easy! All you need to do is find an open issue (see the bottom of this page for a list of repositories containing open issues), fix it and submit a pull request. Once you have submitted your pull request, the team can easily review it before it is merged into the repository.
|
3
|
+
|
4
|
+
To make a pull request, follow these steps:
|
5
|
+
|
6
|
+
1. Log into GitHub. If you do not already have a GitHub account, you will have to create one in order to submit a change. Click the Sign up link in the upper right-hand corner to create an account. Enter your username, password, and email address. If you are an employee of Twilio SendGrid, please use your full name with your GitHub account and enter Twilio SendGrid as your company so we can easily identify you.
|
7
|
+
|
8
|
+
<img src="/static/img/github-sign-up.png" width="800">
|
9
|
+
|
10
|
+
2. __[Fork](https://help.github.com/fork-a-repo/)__ the [ruby-http-client](https://github.com/sendgrid/ruby-http-client) repository:
|
11
|
+
|
12
|
+
<img src="/static/img/github-fork.png" width="800">
|
13
|
+
|
14
|
+
3. __Clone__ your fork via the following commands:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
# Clone your fork of the repo into the current directory
|
18
|
+
git clone https://github.com/your_username/ruby-http-client
|
19
|
+
# Navigate to the newly cloned directory
|
20
|
+
cd ruby-http-client
|
21
|
+
# Assign the original repo to a remote called "upstream"
|
22
|
+
git remote add upstream https://github.com/sendgrid/ruby-http-client
|
23
|
+
```
|
24
|
+
|
25
|
+
> Don't forget to replace *your_username* in the URL by your real GitHub username.
|
26
|
+
|
27
|
+
4. __Create a new topic branch__ (off the main project development branch) to contain your feature, change, or fix:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
git checkout -b <topic-branch-name>
|
31
|
+
```
|
32
|
+
|
33
|
+
5. __Commit your changes__ in logical chunks.
|
34
|
+
|
35
|
+
Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/interactive-rebase) feature to tidy up your commits before making them public. Probably you will also have to create tests (if needed) or create or update the example code that demonstrates the functionality of this change to the code.
|
36
|
+
|
37
|
+
6. __Locally merge (or rebase)__ the upstream development branch into your topic branch:
|
38
|
+
|
39
|
+
```bash
|
40
|
+
git pull [--rebase] upstream main
|
41
|
+
```
|
42
|
+
|
43
|
+
7. __Push__ your topic branch up to your fork:
|
44
|
+
|
45
|
+
```bash
|
46
|
+
git push origin <topic-branch-name>
|
47
|
+
```
|
48
|
+
|
49
|
+
8. __[Open a Pull Request](https://help.github.com/articles/creating-a-pull-request/#changing-the-branch-range-and-destination-repository/)__ with a clear title and description against the `main` branch. All tests must be passing before we will review the PR.
|
50
|
+
|
51
|
+
## Important notice
|
52
|
+
|
53
|
+
Before creating a pull request, make sure that you respect the repository's constraints regarding contributions. You can find them in the [CONTRIBUTING.md](CONTRIBUTING.md) file.
|
54
|
+
|
55
|
+
## Repositories with Open, Easy, Help Wanted, Issue Filters
|
56
|
+
|
57
|
+
* [Python SDK](https://github.com/sendgrid/sendgrid-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
58
|
+
* [PHP SDK](https://github.com/sendgrid/sendgrid-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
59
|
+
* [C# SDK](https://github.com/sendgrid/sendgrid-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
60
|
+
* [Ruby SDK](https://github.com/sendgrid/sendgrid-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
61
|
+
* [Node.js SDK](https://github.com/sendgrid/sendgrid-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
62
|
+
* [Java SDK](https://github.com/sendgrid/sendgrid-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
63
|
+
* [Go SDK](https://github.com/sendgrid/sendgrid-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
64
|
+
* [Python STMPAPI Client](https://github.com/sendgrid/smtpapi-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
65
|
+
* [PHP STMPAPI Client](https://github.com/sendgrid/smtpapi-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
66
|
+
* [C# STMPAPI Client](https://github.com/sendgrid/smtpapi-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
67
|
+
* [Ruby STMPAPI Client](https://github.com/sendgrid/smtpapi-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
68
|
+
* [Node.js STMPAPI Client](https://github.com/sendgrid/smtpapi-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
69
|
+
* [Java STMPAPI Client](https://github.com/sendgrid/smtpapi-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
70
|
+
* [Go STMPAPI Client](https://github.com/sendgrid/smtpapi-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
71
|
+
* [Python HTTP Client](https://github.com/sendgrid/python-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
72
|
+
* [PHP HTTP Client](https://github.com/sendgrid/php-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
73
|
+
* [C# HTTP Client](https://github.com/sendgrid/csharp-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
74
|
+
* [Java HTTP Client](https://github.com/sendgrid/java-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
75
|
+
* [Ruby HTTP Client](https://github.com/sendgrid/ruby-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
76
|
+
* [Go HTTP Client](https://github.com/sendgrid/rest/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
77
|
+
* [Open API Definition](https://github.com/sendgrid/sendgrid-oai/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
78
|
+
* [DX Automator](https://github.com/sendgrid/dx-automator/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
79
|
+
* [Documentation](https://github.com/sendgrid/docs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
|
data/Gemfile
ADDED
data/ISSUE_TEMPLATE.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
<!--
|
2
|
+
If this is a feature request, make sure you search Issues for an existing request before creating a new one!
|
3
|
+
|
4
|
+
Please utilize the template below to help us resolve your issue.
|
5
|
+
|
6
|
+
Note that many issues can be resolved by updating to the latest version.
|
7
|
+
-->
|
8
|
+
|
9
|
+
### Issue Summary
|
10
|
+
A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, or code examples.
|
11
|
+
|
12
|
+
### Steps to Reproduce
|
13
|
+
1. This is the first step
|
14
|
+
2. This is the second step
|
15
|
+
3. Further steps, etc.
|
16
|
+
|
17
|
+
### Code Snippet
|
18
|
+
```ruby
|
19
|
+
# paste code here
|
20
|
+
```
|
21
|
+
|
22
|
+
### Exception/Log
|
23
|
+
```
|
24
|
+
# paste exception/log here
|
25
|
+
```
|
26
|
+
|
27
|
+
### Technical details:
|
28
|
+
* ruby-http-client version:
|
29
|
+
* ruby version:
|
30
|
+
|
data/{LICENSE.txt → LICENSE.md}
RENAMED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
MIT License
|
2
2
|
|
3
|
-
Copyright (
|
3
|
+
Copyright (C) 2020, Twilio SendGrid, Inc. <help@twilio.com>
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
10
|
+
so, subject to the following conditions:
|
11
11
|
|
12
12
|
The above copyright notice and this permission notice shall be included in all
|
13
13
|
copies or substantial portions of the Software.
|
data/Makefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
<!--
|
2
|
+
We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines, then fill out the blanks below.
|
3
|
+
|
4
|
+
Please format the PR title appropriately based on the type of change:
|
5
|
+
<type>[!]: <description>
|
6
|
+
Where <type> is one of: docs, chore, feat, fix, test.
|
7
|
+
Add a '!' after the type for breaking changes (e.g. feat!: new breaking feature).
|
8
|
+
|
9
|
+
**All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.**
|
10
|
+
|
11
|
+
Please enter each Issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged!
|
12
|
+
e.g.
|
13
|
+
Fixes #1
|
14
|
+
Closes #2
|
15
|
+
-->
|
16
|
+
|
17
|
+
# Fixes #
|
18
|
+
|
19
|
+
A short description of what this PR does.
|
20
|
+
|
21
|
+
### Checklist
|
22
|
+
- [ ] I acknowledge that all my contributions will be made under the project's license
|
23
|
+
- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
|
24
|
+
- [ ] I have read the [Contribution Guidelines](CONTRIBUTING.md) and my PR follows them
|
25
|
+
- [ ] I have titled the PR appropriately
|
26
|
+
- [ ] I have updated my branch with the main branch
|
27
|
+
- [ ] I have added tests that prove my fix is effective or that my feature works
|
28
|
+
- [ ] I have added necessary documentation about the functionality in the appropriate .md file
|
29
|
+
- [ ] I have added inline documentation to the code I modified
|
30
|
+
|
31
|
+
If you have questions, please file a [support ticket](https://twilio.com/help/contact), or create a GitHub Issue in this repository.
|
data/README.md
CHANGED
@@ -1,18 +1,48 @@
|
|
1
|
-
|
1
|
+
![SendGrid Logo](twilio_sendgrid_logo.png)
|
2
|
+
|
3
|
+
[![BuildStatus](https://travis-ci.org/sendgrid/ruby-http-client.svg?branch=main)](https://travis-ci.org/sendgrid/ruby-http-client)
|
4
|
+
[![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/ruby_http_client.svg)](https://badge.fury.io/rb/ruby_http_client)
|
6
|
+
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)
|
7
|
+
[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
|
8
|
+
[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/ruby-http-client.svg)](https://github.com/sendgrid/ruby-http-client/graphs/contributors)
|
2
9
|
|
3
10
|
**Quickly and easily access any RESTful or RESTful-like API.**
|
4
11
|
|
5
12
|
If you are looking for the SendGrid API client library, please see [this repo](https://github.com/sendgrid/sendgrid-ruby).
|
6
13
|
|
7
14
|
# Announcements
|
15
|
+
**The default branch name for this repository has been changed to `main` as of 07/27/2020.**
|
16
|
+
|
17
|
+
All updates to this library are documented in our [CHANGELOG](CHANGELOG.md).
|
8
18
|
|
9
|
-
|
19
|
+
# Table of Contents
|
20
|
+
- [Installation](#installation)
|
21
|
+
- [Quick Start](#quick-start)
|
22
|
+
- [Usage](#usage)
|
23
|
+
- [Roadmap](#roadmap)
|
24
|
+
- [How to Contribute](#contribute)
|
25
|
+
- [About](#about)
|
26
|
+
- [License](#license)
|
10
27
|
|
28
|
+
<a name="installation"></a>
|
11
29
|
# Installation
|
12
30
|
|
13
31
|
## Prerequisites
|
14
32
|
|
15
|
-
- Ruby version 2.
|
33
|
+
- Ruby version >= 2.4
|
34
|
+
|
35
|
+
## Setup Environment Variables
|
36
|
+
|
37
|
+
### Environment Variable
|
38
|
+
|
39
|
+
Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
|
40
|
+
|
41
|
+
```bash
|
42
|
+
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
|
43
|
+
echo "sendgrid.env" >> .gitignore
|
44
|
+
source ./sendgrid.env
|
45
|
+
```
|
16
46
|
|
17
47
|
## Install Package
|
18
48
|
|
@@ -20,13 +50,14 @@ All updates to this library is documented in our [CHANGELOG](https://github.com/
|
|
20
50
|
gem install ruby_http_client
|
21
51
|
```
|
22
52
|
|
53
|
+
<a name="quick-start"></a>
|
23
54
|
# Quick Start
|
24
55
|
|
25
56
|
`GET /your/api/{param}/call`
|
26
57
|
|
27
58
|
```ruby
|
28
59
|
require 'ruby_http_client'
|
29
|
-
global_headers = {'Authorization' => '
|
60
|
+
global_headers = {'Authorization' => 'Bearer XXXXXXX' }
|
30
61
|
client = SendGrid::Client.new(host: 'base_url', request_headers: global_headers)
|
31
62
|
client.your.api._(param).call.get
|
32
63
|
puts response.status_code
|
@@ -38,7 +69,7 @@ puts response.headers
|
|
38
69
|
|
39
70
|
```ruby
|
40
71
|
require 'ruby_http_client'
|
41
|
-
global_headers = {'Authorization' => '
|
72
|
+
global_headers = {'Authorization' => 'Bearer XXXXXXX' }
|
42
73
|
client = SendGrid::Client.new(host: 'base_url', request_headers: global_headers)
|
43
74
|
query_params = { 'hello' => 0, 'world' => 1 }
|
44
75
|
request_headers = { 'X-Test' => 'test' }
|
@@ -51,31 +82,36 @@ puts response.body
|
|
51
82
|
puts response.headers
|
52
83
|
```
|
53
84
|
|
85
|
+
<a name="usage"></a>
|
54
86
|
# Usage
|
55
87
|
|
56
|
-
- [Example Code](
|
88
|
+
- [Example Code](examples)
|
57
89
|
|
58
|
-
|
90
|
+
<a name="roadmap"></a>
|
91
|
+
# Roadmap
|
59
92
|
|
60
93
|
If you are interested in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/ruby-http-client/milestones). We would love to hear your feedback.
|
61
94
|
|
62
|
-
|
95
|
+
<a name="contribute"></a>
|
96
|
+
# How to Contribute
|
63
97
|
|
64
|
-
We encourage contribution to our libraries, please see our [CONTRIBUTING](
|
98
|
+
We encourage contribution to our libraries, please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details.
|
65
99
|
|
66
100
|
Quick links:
|
67
101
|
|
68
|
-
- [Feature Request](
|
69
|
-
- [Bug Reports](
|
70
|
-
- [
|
71
|
-
- [
|
72
|
-
|
102
|
+
- [Feature Request](CONTRIBUTING.md#feature-request)
|
103
|
+
- [Bug Reports](CONTRIBUTING.md#submit-a-bug-report)
|
104
|
+
- [Improvements to the Codebase](CONTRIBUTING.md#improvements-to-the-codebase)
|
105
|
+
- [Review Pull Requests](CONTRIBUTING.md#code-reviews)
|
73
106
|
|
107
|
+
<a name="about"></a>
|
74
108
|
# About
|
75
109
|
|
76
|
-
ruby-http-client is
|
110
|
+
ruby-http-client is maintained and funded by Twilio SendGrid, Inc. The names and logos for ruby-http-client are trademarks of Twilio SendGrid, Inc.
|
111
|
+
|
112
|
+
If you need help installing or using the library, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).
|
77
113
|
|
78
|
-
|
114
|
+
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
|
79
115
|
|
80
|
-
|
81
|
-
(
|
116
|
+
# License
|
117
|
+
[The MIT License (MIT)](LICENSE.md)
|
data/Rakefile
CHANGED
@@ -4,5 +4,28 @@ Rake::TestTask.new do |t|
|
|
4
4
|
t.libs << 'test'
|
5
5
|
end
|
6
6
|
|
7
|
-
desc
|
8
|
-
task :
|
7
|
+
desc 'run rubocop'
|
8
|
+
task :rubocop do
|
9
|
+
sh 'rubocop -c .rubocop.yml --display-only-fail-level-offenses -D'
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'run rubocop w/autocorrect'
|
13
|
+
task :rubocorrect do
|
14
|
+
sh 'rubocop -c .rubocop.yml -a'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'run minitest'
|
18
|
+
task :minitest do
|
19
|
+
Rake::Task[:test].invoke
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Run tests'
|
23
|
+
task default: 'test:quick'
|
24
|
+
|
25
|
+
namespace :test do
|
26
|
+
desc 'Run all the quick tests'
|
27
|
+
task :quick do
|
28
|
+
Rake::Task['rubocop'].invoke
|
29
|
+
Rake::Task['minitest'].invoke
|
30
|
+
end
|
31
|
+
end
|
data/TROUBLESHOOTING.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
If you have a non-library SendGrid issue, please contact our [support team](https://support.sendgrid.com).
|
2
|
+
|
3
|
+
If you can't find a solution below, please open an [issue](https://github.com/sendgrid/ruby-http-client/issues).
|
4
|
+
|
5
|
+
## Table of Contents
|
6
|
+
* [Viewing the Request Body](#request-body)
|
7
|
+
|
8
|
+
<a name="request-body"></a>
|
9
|
+
## Viewing the Request Body
|
10
|
+
|
11
|
+
When debugging or testing, it may be useful to examine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
|
12
|
+
|
13
|
+
You can do this right before you call: `response = client.version('v3').api_keys.post(request_body: request_body)` like so:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
puts request_body
|
17
|
+
```
|
data/USAGE.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Usage
|
2
|
+
|
3
|
+
Usage examples for SendGrid ruby-http-client
|
4
|
+
|
5
|
+
## Initialization
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require_relative '../lib/ruby_http_client'
|
9
|
+
|
10
|
+
# This uses the SendGrid API as an example
|
11
|
+
headers = JSON.parse('
|
12
|
+
{
|
13
|
+
"Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '"
|
14
|
+
}
|
15
|
+
')
|
16
|
+
host = 'https://api.sendgrid.com'
|
17
|
+
client = SendGrid::Client.new(host: host, request_headers: headers)
|
18
|
+
```
|
19
|
+
|
20
|
+
## Table of Contents
|
21
|
+
|
22
|
+
- [GET](#get)
|
23
|
+
- [DELETE](#delete)
|
24
|
+
- [POST](#post)
|
25
|
+
- [PUT](#put)
|
26
|
+
- [PATCH](#patch)
|
27
|
+
|
28
|
+
## GET
|
29
|
+
|
30
|
+
#### GET Collection
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
query_params = { 'limit' => 100, 'offset' => 0 }
|
34
|
+
response = client.version('v3').api_keys.get(query_params: query_params)
|
35
|
+
puts response.status_code
|
36
|
+
puts response.body
|
37
|
+
puts response.headers
|
38
|
+
```
|
39
|
+
|
40
|
+
#### GET Single
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
response = client.version('v3').api_keys._(api_key_id).get
|
44
|
+
puts response.status_code
|
45
|
+
puts response.body
|
46
|
+
puts response.headers
|
47
|
+
```
|
48
|
+
|
49
|
+
## DELETE
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
response = client.api_keys._(api_key_id).delete
|
53
|
+
puts response.status_code
|
54
|
+
puts response.headers
|
55
|
+
```
|
56
|
+
|
57
|
+
## POST
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
request_body = JSON.parse('
|
61
|
+
{
|
62
|
+
"name": "My API Key Ruby Test",
|
63
|
+
"scopes": [
|
64
|
+
"mail.send",
|
65
|
+
"alerts.create",
|
66
|
+
"alerts.read"
|
67
|
+
]
|
68
|
+
}
|
69
|
+
')
|
70
|
+
response = client.version('v3').api_keys.post(request_body: request_body)
|
71
|
+
puts response.status_code
|
72
|
+
puts response.body
|
73
|
+
puts response.headers
|
74
|
+
api_key_id = JSON.parse(response.body)['api_key_id']
|
75
|
+
```
|
76
|
+
|
77
|
+
## PUT
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
request_body = JSON.parse('
|
81
|
+
{
|
82
|
+
"name": "A New Hope",
|
83
|
+
"scopes": [
|
84
|
+
"user.profile.read",
|
85
|
+
"user.profile.update"
|
86
|
+
]
|
87
|
+
}
|
88
|
+
')
|
89
|
+
|
90
|
+
response = client.api_keys._(api_key_id).put(request_body: request_body)
|
91
|
+
puts response.status_code
|
92
|
+
puts response.body
|
93
|
+
puts response.headers
|
94
|
+
```
|
95
|
+
|
96
|
+
## PATCH
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
request_body = JSON.parse('
|
100
|
+
{
|
101
|
+
"name": "A New Hope"
|
102
|
+
}
|
103
|
+
')
|
104
|
+
response = client.api_keys._(api_key_id).patch(request_body: request_body)
|
105
|
+
puts response.status_code
|
106
|
+
puts response.body
|
107
|
+
puts response.headers
|
108
|
+
```
|