ruby_http_client 3.3.0 → 3.5.2

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.
@@ -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 SMTPAPI 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 SMTPAPI 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# SMTPAPI 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 SMTPAPI 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 SMTPAPI 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 SMTPAPI 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 SMTPAPI 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
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -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
+
@@ -1,13 +1,13 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2016-2017 SendGrid, Inc.
3
+ Copyright (C) 2021, Twilio SendGrid, Inc. <help@twilio.com>
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
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.
@@ -0,0 +1,7 @@
1
+ .PHONY: install test
2
+
3
+ install:
4
+ gem install bundler:1.14.6; bundle install
5
+
6
+ test:
7
+ rake test
@@ -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
+ - [x] 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](https://github.com/sendgrid/ruby-http-client/blob/main/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 the 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://support.sendgrid.com), or create a GitHub Issue in this repository.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- ![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
1
+ ![SendGrid Logo](twilio_sendgrid_logo.png)
2
2
 
3
- [![BuildStatus](https://travis-ci.org/sendgrid/ruby-http-client.svg?branch=master)](https://travis-ci.org/sendgrid/ruby-http-client)
3
+ [![BuildStatus](https://travis-ci.com/sendgrid/ruby-http-client.svg?branch=main)](https://travis-ci.com/sendgrid/ruby-http-client)
4
4
  [![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby)
5
- [![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby)
6
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt)
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)
7
7
  [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
8
8
  [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/ruby-http-client.svg)](https://github.com/sendgrid/ruby-http-client/graphs/contributors)
9
9
 
@@ -12,14 +12,14 @@
12
12
  If you are looking for the SendGrid API client library, please see [this repo](https://github.com/sendgrid/sendgrid-ruby).
13
13
 
14
14
  # Announcements
15
+ **The default branch name for this repository has been changed to `main` as of 07/27/2020.**
15
16
 
16
- All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/ruby-http-client/blob/master/CHANGELOG.md).
17
+ All updates to this library are documented in our [CHANGELOG](CHANGELOG.md).
17
18
 
18
19
  # Table of Contents
19
20
  - [Installation](#installation)
20
21
  - [Quick Start](#quick-start)
21
22
  - [Usage](#usage)
22
- - [Roadmap](#roadmap)
23
23
  - [How to Contribute](#contribute)
24
24
  - [About](#about)
25
25
  - [License](#license)
@@ -29,7 +29,19 @@ All updates to this library is documented in our [CHANGELOG](https://github.com/
29
29
 
30
30
  ## Prerequisites
31
31
 
32
- - Ruby version 2.2+
32
+ - Ruby version >= 2.4
33
+
34
+ ## Setup Environment Variables
35
+
36
+ ### Environment Variable
37
+
38
+ Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
39
+
40
+ ```bash
41
+ echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
42
+ echo "sendgrid.env" >> .gitignore
43
+ source ./sendgrid.env
44
+ ```
33
45
 
34
46
  ## Install Package
35
47
 
@@ -44,7 +56,7 @@ gem install ruby_http_client
44
56
 
45
57
  ```ruby
46
58
  require 'ruby_http_client'
47
- global_headers = {'Authorization' => 'Basic XXXXXXX' }
59
+ global_headers = {'Authorization' => 'Bearer XXXXXXX' }
48
60
  client = SendGrid::Client.new(host: 'base_url', request_headers: global_headers)
49
61
  client.your.api._(param).call.get
50
62
  puts response.status_code
@@ -56,7 +68,7 @@ puts response.headers
56
68
 
57
69
  ```ruby
58
70
  require 'ruby_http_client'
59
- global_headers = {'Authorization' => 'Basic XXXXXXX' }
71
+ global_headers = {'Authorization' => 'Bearer XXXXXXX' }
60
72
  client = SendGrid::Client.new(host: 'base_url', request_headers: global_headers)
61
73
  query_params = { 'hello' => 0, 'world' => 1 }
62
74
  request_headers = { 'X-Test' => 'test' }
@@ -72,31 +84,28 @@ puts response.headers
72
84
  <a name="usage"></a>
73
85
  # Usage
74
86
 
75
- - [Example Code](https://github.com/sendgrid/ruby-http-client/tree/master/examples)
76
-
77
- <a name="roadmap"></a>
78
- # Roadmap
79
-
80
- 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.
87
+ - [Example Code](examples)
81
88
 
82
89
  <a name="contribute"></a>
83
90
  # How to Contribute
84
91
 
85
- We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md) guide for details.
92
+ We encourage contribution to our libraries, please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details.
86
93
 
87
94
  Quick links:
88
95
 
89
- - [Feature Request](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#feature-request)
90
- - [Bug Reports](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#submit-a-bug-report)
91
- - [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md)
92
- - [Improvements to the Codebase](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#improvements-to-the-codebase)
96
+ - [Feature Request](CONTRIBUTING.md#feature-request)
97
+ - [Bug Reports](CONTRIBUTING.md#submit-a-bug-report)
98
+ - [Improvements to the Codebase](CONTRIBUTING.md#improvements-to-the-codebase)
99
+ - [Review Pull Requests](CONTRIBUTING.md#code-reviews)
93
100
 
94
101
  <a name="about"></a>
95
102
  # About
96
103
 
97
- ruby-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
104
+ 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.
105
+
106
+ If you need help installing or using the library, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).
98
107
 
99
- ruby-http-client is maintained and funded by SendGrid, Inc. The names and logos for ruby-http-client are trademarks of SendGrid, Inc.
108
+ 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!
100
109
 
101
110
  # License
102
- [The MIT License (MIT)](LICENSE.txt)
111
+ [The MIT License (MIT)](LICENSE)
data/Rakefile CHANGED
@@ -4,5 +4,28 @@ Rake::TestTask.new do |t|
4
4
  t.libs << 'test'
5
5
  end
6
6
 
7
- desc "Run tests"
8
- task :default => :test
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
@@ -8,7 +8,7 @@ If you can't find a solution below, please open an [issue](https://github.com/se
8
8
  <a name="request-body"></a>
9
9
  ## Viewing the Request Body
10
10
 
11
- When debugging or testing, it may be useful to exampine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
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
12
 
13
13
  You can do this right before you call: `response = client.version('v3').api_keys.post(request_body: request_body)` like so:
14
14
 
@@ -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
+ ```
@@ -6,9 +6,28 @@ headers = JSON.parse('
6
6
  "Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '"
7
7
  }
8
8
  ')
9
- host = 'https://api.sendgrid.com'
9
+ host = 'https://api.sendgrid.com'
10
10
  client = SendGrid::Client.new(host: host, request_headers: headers)
11
11
 
12
+ # You can pass in an http_options hash to set values for NET::HTTP attributes
13
+ # https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html
14
+ # client = SendGrid::Client.new(host: host,
15
+ # request_headers: headers,
16
+ # http_options: {open_timeout: 15, read_timeout: 30})
17
+
18
+ # If you want to make request via proxy, you can set your proxy server in two ways.
19
+ #
20
+ # (1) Pass proxy_options hash
21
+ #
22
+ # client = SendGrid::Client.new(host: host,
23
+ # request_headers: headers,
24
+ # proxy_options: { host: '127.0.0.1', port: 8080 })
25
+ #
26
+ # (2) Set 'http_proxy' environment variable
27
+ #
28
+ # ENV['http_proxy'] = 'user:pass@127.0.0.1:8080'
29
+ # client = SendGrid::Client.new(host: host, request_headers: headers)
30
+
12
31
  # GET Collection
13
32
  query_params = { 'limit' => 100, 'offset' => 0 }
14
33
  response = client.version('v3').api_keys.get(query_params: query_params)
@@ -69,3 +88,12 @@ puts response.headers
69
88
  response = client.api_keys._(api_key_id).delete
70
89
  puts response.status_code
71
90
  puts response.headers
91
+
92
+ # Rate limit information
93
+ response = client.version('v3').api_keys._(api_key_id).get
94
+ puts response.ratelimit.limit
95
+ puts response.ratelimit.remaining
96
+ puts response.ratelimit.reset
97
+ puts response.ratelimit.exceeded?
98
+ # Sleep the current thread until the reset has happened
99
+ response.ratelimit.wait!