ruby_http_client 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/CONTRIBUTING.md +56 -52
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +35 -91
- data/examples/example.rb +14 -14
- data/lib/ruby_http_client.rb +3 -14
- data/ruby_http_client.gemspec +1 -1
- data/test/test_ruby_http_client.rb +7 -7
- metadata +3 -4
- data/.env_sample +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 890828c72f8180fafeff5f0a3b8d6af9e0cdc325
|
4
|
+
data.tar.gz: e0c13a22556aa5e2b32401db7cca447128a67d73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d78da08c2efdb0b95177f77c9baae83a6fbca1c5c0f950b7d19ef966f5a81449edd7267f2169119b6ed29bb37517d68f45a5c50326027feecfdd805fce23ebf
|
7
|
+
data.tar.gz: 47639cffff96c33af158a6e7a0f891bc6b8d97fb522a6e0b16337d732da385d80ede0eabe134c0f216e8c9657da474c30c6e77e253ec44f0be6e903f12379308
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
|
+
|
3
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
5
|
|
6
|
+
## [2.0.0] - 2016-06-03
|
7
|
+
### Changed
|
8
|
+
- Made the Response variables non-redundant. e.g. response.response_body becomes response.body
|
9
|
+
|
10
|
+
### Removed
|
11
|
+
- Config class
|
12
|
+
|
13
|
+
## [1.1.0] - 2016-03-17
|
14
|
+
### Added
|
15
|
+
- Config class moved to client
|
16
|
+
|
5
17
|
## [1.0.0] - 2016-03-17
|
6
18
|
### Added
|
7
19
|
- We are live!
|
data/CONTRIBUTING.md
CHANGED
@@ -1,14 +1,28 @@
|
|
1
|
-
Hello! Thank you for choosing to help contribute to the
|
2
|
-
|
1
|
+
Hello! Thank you for choosing to help contribute to one of the SendGrid open source libraries. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies.
|
2
|
+
|
3
|
+
- [CLAs and CCLAs](#cla)
|
4
|
+
- [Roadmap & Milestones](#roadmap)
|
5
|
+
- [Feature Request](#feature_request)
|
6
|
+
- [Submit a Bug Report](#submit_a_bug_report)
|
7
|
+
- [Improvements to the Codebase](#improvements_to_the_codebase)
|
8
|
+
- [Understanding the Code Base](#understanding_the_codebase)
|
9
|
+
- [Testing](#testing)
|
10
|
+
- [Style Guidelines & Naming Conventions](#style_guidelines_and_naming_conventions)
|
11
|
+
- [Creating a Pull Request](#creating_a_pull_request)
|
12
|
+
|
13
|
+
<a name="roadmap"></a>
|
3
14
|
We use [Milestones](https://github.com/sendgrid/ruby-http-client/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community review, comments, suggestions and additional PRs are welcomed and encouraged.
|
4
15
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
<a name="cla"></a>
|
17
|
+
## CLAs and CCLAs
|
18
|
+
|
19
|
+
Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) or a SendGrid Company Contributor Licensing Agreement (CCLA) be filled out by every contributor to a SendGrid open source project.
|
20
|
+
|
21
|
+
Our goal with the CLA and CCLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA and CCLA encourage broad participation by our open source community and help us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution.
|
22
|
+
|
23
|
+
SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA (or CCLA). Copies of the CLA and CCLA are available [here](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view).
|
24
|
+
|
25
|
+
You may submit your completed [CLA or CCLA](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view) to SendGrid at [dx@sendgrid.com](mailto:dx@sendgrid.com). SendGrid will then confirm you are ready to begin making contributions.
|
12
26
|
|
13
27
|
There are a few ways to contribute, which we'll enumerate below:
|
14
28
|
|
@@ -37,58 +51,50 @@ Before you decide to create a new issue, please try the following:
|
|
37
51
|
|
38
52
|
### Please use our Bug Report Template
|
39
53
|
|
40
|
-
In order to make the process easier, we've included a sample bug report template (borrowed from [Ghost](https://github.com/TryGhost/Ghost/)). The template uses [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown/) for formatting.
|
41
|
-
|
42
|
-
```
|
43
|
-
Short and descriptive example bug report title
|
44
|
-
|
45
|
-
#### Issue Summary
|
46
|
-
|
47
|
-
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, code examples.
|
48
|
-
|
49
|
-
|
50
|
-
#### Steps to Reproduce
|
51
|
-
|
52
|
-
1. This is the first step
|
53
|
-
2. This is the second step
|
54
|
-
3. Further steps, etc.
|
55
|
-
|
56
|
-
Any other information you want to share that is relevant to the issue being reported. Especially, why do you consider this to be a bug? What do you expect to happen instead?
|
57
|
-
|
58
|
-
#### Technical details:
|
59
|
-
|
60
|
-
* ruby-http-client Version: master (latest commit: 2cb34372ef0f31352f7c90015a45e1200cb849da)
|
61
|
-
* Ruby Version: 2.2
|
62
|
-
```
|
54
|
+
In order to make the process easier, we've included a [sample bug report template](https://github.com/sendgrid/ruby-http-client/.github/ISSUE_TEMPLATE) (borrowed from [Ghost](https://github.com/TryGhost/Ghost/)). The template uses [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown/) for formatting.
|
63
55
|
|
64
56
|
<a name="improvements_to_the_codebase"></a>
|
65
57
|
## Improvements to the Codebase
|
66
58
|
|
67
|
-
We welcome direct contributions to the
|
59
|
+
We welcome direct contributions to the ruby-http-client code base. Thank you!
|
68
60
|
|
69
61
|
### Development Environment ###
|
70
62
|
|
71
|
-
#### Install and
|
63
|
+
#### Install and Run Locally ####
|
72
64
|
|
73
65
|
##### Prerequisites #####
|
74
66
|
|
75
|
-
|
76
|
-
* There are no external dependencies
|
67
|
+
- Ruby 2.2 or higher
|
77
68
|
|
78
69
|
##### Initial setup: #####
|
79
70
|
|
80
|
-
```
|
71
|
+
```bash
|
81
72
|
git clone https://github.com/sendgrid/ruby-http-client.git
|
82
73
|
cd ruby-http-client
|
83
|
-
cp .env_sample .env
|
84
74
|
```
|
85
75
|
|
86
|
-
Update your settings in `.env`
|
87
|
-
|
88
76
|
##### Execute: #####
|
89
77
|
|
90
78
|
See the [examples folder](https://github.com/sendgrid/ruby-http-client/tree/master/examples) to get started quickly.
|
91
79
|
|
80
|
+
To try the SendGrid example:
|
81
|
+
|
82
|
+
First, get your free SendGrid account [here](https://sendgrid.com/free?source=ruby-http-client).
|
83
|
+
|
84
|
+
Next, update your environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys).
|
85
|
+
|
86
|
+
```bash
|
87
|
+
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
|
88
|
+
echo "sendgrid.env" >> .gitignore
|
89
|
+
source ./sendgrid.env
|
90
|
+
```
|
91
|
+
|
92
|
+
To run the example (after updating the emails):
|
93
|
+
|
94
|
+
```bash
|
95
|
+
ruby examples/example.rb
|
96
|
+
```
|
97
|
+
|
92
98
|
<a name="understanding_the_codebase"></a>
|
93
99
|
## Understanding the Code Base
|
94
100
|
|
@@ -109,30 +115,28 @@ This allows for the following mapping from a URL to a method chain:
|
|
109
115
|
|
110
116
|
All PRs require passing tests before the PR will be reviewed.
|
111
117
|
|
112
|
-
All test files are in the `
|
118
|
+
All test files are in the [`test`](https://github.com/sendgrid/ruby-http-client/tree/master/test) directory.
|
113
119
|
|
114
120
|
For the purposes of contributing to this repo, please update the [`test_ruby_http_client.rb`](https://github.com/sendgrid/ruby-http-client/blob/master/test/test_ruby_http_client.rb) file with unit tests as you modify the code.
|
115
121
|
|
116
122
|
To run the tests:
|
117
123
|
|
118
|
-
|
119
|
-
|
120
|
-
|
124
|
+
```bash
|
125
|
+
rake
|
126
|
+
```
|
121
127
|
|
122
128
|
<a name="style_guidelines_and_naming_conventions"></a>
|
123
129
|
## Style Guidelines & Naming Conventions
|
124
130
|
|
125
131
|
Generally, we follow the style guidelines as suggested by the official language. However, we ask that you conform to the styles that already exist in the library. If you wish to deviate, please explain your reasoning.
|
126
132
|
|
127
|
-
|
133
|
+
Generally, we follow the style guidelines as suggested by the official language. However, we ask that you conform to the styles that already exist in the library. If you wish to deviate, please explain your reasoning.
|
128
134
|
|
129
|
-
|
135
|
+
- [Community Driven Style Guide](https://github.com/bbatsov/ruby-style-guide)
|
130
136
|
|
131
|
-
|
137
|
+
Please run your code through:
|
132
138
|
|
133
|
-
|
134
|
-
* `test`, for all tests
|
135
|
-
* `libs`, for the client library
|
139
|
+
- [rubocop](https://github.com/bbatsov/rubocop).
|
136
140
|
|
137
141
|
## Creating a Pull Request<a name="creating_a_pull_request"></a>
|
138
142
|
|
@@ -143,7 +147,7 @@ Please run your code through [rubocop](https://github.com/bbatsov/rubocop).
|
|
143
147
|
# Clone your fork of the repo into the current directory
|
144
148
|
git clone https://github.com/sendgrid/ruby-http-client
|
145
149
|
# Navigate to the newly cloned directory
|
146
|
-
cd
|
150
|
+
cd sendgrid-python
|
147
151
|
# Assign the original repo to a remote called "upstream"
|
148
152
|
git remote add upstream https://github.com/sendgrid/ruby-http-client
|
149
153
|
```
|
@@ -187,4 +191,4 @@ Please run your code through [rubocop](https://github.com/bbatsov/rubocop).
|
|
187
191
|
7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
|
188
192
|
with a clear title and description against the `master` branch. All tests must be passing before we will review the PR.
|
189
193
|
|
190
|
-
If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.
|
194
|
+
If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.
|
data/{LICENSE → LICENSE.txt}
RENAMED
data/README.md
CHANGED
@@ -1,25 +1,39 @@
|
|
1
|
-
[![Travis Badge](https://travis-ci.org/sendgrid/
|
1
|
+
[![Travis Badge](https://travis-ci.org/sendgrid/ruby-http-client.svg?branch=master)](https://travis-ci.org/sendgrid/ruby-http-client)
|
2
2
|
|
3
3
|
**Quickly and easily access any REST or REST-like API.**
|
4
4
|
|
5
|
-
|
5
|
+
# Announcements
|
6
|
+
|
7
|
+
All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/ruby-http-client/blob/master/CHANGELOG.md).
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install ruby_http_client
|
13
|
+
```
|
14
|
+
|
15
|
+
## Dependencies
|
16
|
+
|
17
|
+
- Ruby 2.2 or higher
|
18
|
+
|
19
|
+
# Quick Start
|
6
20
|
|
7
21
|
`GET /your/api/{param}/call`
|
8
22
|
|
9
23
|
```ruby
|
10
|
-
require ruby_http_client
|
24
|
+
require 'ruby_http_client'
|
11
25
|
global_headers = {'Authorization' => 'Basic XXXXXXX' }
|
12
26
|
client = SendGrid::Client(host: 'base_url', request_headers: global_headers)
|
13
27
|
client.your.api._(param).call.get
|
14
28
|
puts response.status_code
|
15
|
-
puts response.
|
16
|
-
puts response.
|
29
|
+
puts response.body
|
30
|
+
puts response.headers
|
17
31
|
```
|
18
32
|
|
19
33
|
`POST /your/api/{param}/call` with headers, query parameters and a request body with versioning.
|
20
34
|
|
21
35
|
```ruby
|
22
|
-
|
36
|
+
require 'ruby_http_client'
|
23
37
|
global_headers = {'Authorization' => 'Basic XXXXXXX' }
|
24
38
|
client = SendGrid::Client(host: 'base_url', request_headers: global_headers)
|
25
39
|
query_params = { 'hello' => 0, 'world' => 1 }
|
@@ -29,105 +43,35 @@ response = client.your.api._(param).call.post(request_body: data,
|
|
29
43
|
query_params: query_params,
|
30
44
|
request_headers: request_headers)
|
31
45
|
puts response.status_code
|
32
|
-
puts response.
|
33
|
-
puts response.
|
34
|
-
```
|
35
|
-
|
36
|
-
# Installation
|
37
|
-
|
38
|
-
`gem install ruby_http_client`
|
39
|
-
|
40
|
-
## Usage ##
|
41
|
-
|
42
|
-
Following is an example using SendGrid. You can get your free account [here](https://sendgrid.com/free?source=python-http-client).
|
43
|
-
|
44
|
-
First, update your .env with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys) and HOST. For this example HOST=https://api.sendgrid.com.
|
45
|
-
|
46
|
-
Following is an abridged example, here is the [full working code](https://github.com/sendgrid/ruby-http-client/tree/master/examples).
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
require ruby_http_client
|
50
|
-
|
51
|
-
SendGrid::Config.new
|
52
|
-
headers = JSON.parse('
|
53
|
-
{
|
54
|
-
"Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '",
|
55
|
-
"Content-Type": "application/json"
|
56
|
-
}
|
57
|
-
')
|
58
|
-
host = ENV['LOCAL_HOST']
|
59
|
-
client = SendGrid::Client.new(host: host, request_headers: headers)
|
60
|
-
|
61
|
-
# GET Collection
|
62
|
-
query_params = { 'limit' => 100, 'offset' => 0 }
|
63
|
-
response = client.version('v3').api_keys.get(query_params: query_params)
|
64
|
-
|
65
|
-
# POST
|
66
|
-
request_body = JSON.parse('
|
67
|
-
{
|
68
|
-
"name": "My API Key Ruby Test",
|
69
|
-
"scopes": [
|
70
|
-
"mail.send",
|
71
|
-
"alerts.create",
|
72
|
-
"alerts.read"
|
73
|
-
]
|
74
|
-
}
|
75
|
-
')
|
76
|
-
response = client.version('v3').api_keys.post(request_body: request_body)
|
77
|
-
api_key_id = JSON.parse(response.response_body)['api_key_id']
|
78
|
-
|
79
|
-
# GET Single
|
80
|
-
response = client.version('v3').api_keys._(api_key_id).get
|
81
|
-
|
82
|
-
# PATCH
|
83
|
-
request_body = JSON.parse('
|
84
|
-
{
|
85
|
-
"name": "A New Hope"
|
86
|
-
}
|
87
|
-
')
|
88
|
-
response = client.api_keys._(api_key_id).patch(request_body: request_body)
|
89
|
-
|
90
|
-
# PUT
|
91
|
-
request_body = JSON.parse('
|
92
|
-
{
|
93
|
-
"name": "A New Hope",
|
94
|
-
"scopes": [
|
95
|
-
"user.profile.read",
|
96
|
-
"user.profile.update"
|
97
|
-
]
|
98
|
-
}
|
99
|
-
')
|
100
|
-
response = client.api_keys._(api_key_id).put(request_body: request_body)
|
101
|
-
|
102
|
-
# DELETE
|
103
|
-
response = client.api_keys._(api_key_id).delete
|
46
|
+
puts response.body
|
47
|
+
puts response.headers
|
104
48
|
```
|
105
49
|
|
106
|
-
#
|
50
|
+
# Usage
|
107
51
|
|
108
|
-
[
|
52
|
+
- [Example Code](https://github.com/sendgrid/ruby-http-client/tree/master/examples)
|
109
53
|
|
110
|
-
|
54
|
+
## Roadmap
|
111
55
|
|
112
|
-
[
|
56
|
+
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.
|
113
57
|
|
114
|
-
|
58
|
+
## How to Contribute
|
115
59
|
|
116
60
|
We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md) guide for details.
|
117
61
|
|
118
|
-
|
119
|
-
* [Bug Reports](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#submit_a_bug_report)
|
120
|
-
* [Improvements to the Codebase](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#improvements_to_the_codebase)
|
62
|
+
Quick links:
|
121
63
|
|
122
|
-
#
|
64
|
+
- [Feature Request](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#feature_request)
|
65
|
+
- [Bug Reports](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#submit_a_bug_report)
|
66
|
+
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md)
|
67
|
+
- [Improvements to the Codebase](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#improvements_to_the_codebase)
|
123
68
|
|
124
|
-
We were inspired by the work done on [birdy](https://github.com/inueni/birdy) and [universalclient](https://github.com/dgreisen/universalclient).
|
125
69
|
|
126
70
|
# About
|
127
71
|
|
128
|
-
![SendGrid Logo]
|
129
|
-
(https://assets3.sendgrid.com/mkt/assets/logos_brands/small/sglogo_2015_blue-9c87423c2ff2ff393ebce1ab3bd018a4.png)
|
130
|
-
|
131
72
|
ruby-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
|
132
73
|
|
133
74
|
ruby-http-client is maintained and funded by SendGrid, Inc. The names and logos for ruby-http-client are trademarks of SendGrid, Inc.
|
75
|
+
|
76
|
+
![SendGrid Logo]
|
77
|
+
(https://assets3.sendgrid.com/mkt/assets/logos_brands/small/sglogo_2015_blue-9c87423c2ff2ff393ebce1ab3bd018a4.png)
|
data/examples/example.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require_relative '../lib/ruby_http_client'
|
2
2
|
|
3
|
-
SendGrid
|
3
|
+
# This example uses the SendGrid API as an example
|
4
4
|
headers = JSON.parse('
|
5
5
|
{
|
6
6
|
"Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '",
|
7
7
|
"Content-Type": "application/json"
|
8
8
|
}
|
9
9
|
')
|
10
|
-
host =
|
10
|
+
host = 'https://api.sendgrid.com'
|
11
11
|
client = SendGrid::Client.new(host: host, request_headers: headers)
|
12
12
|
|
13
13
|
# GET Collection
|
14
14
|
query_params = { 'limit' => 100, 'offset' => 0 }
|
15
15
|
response = client.version('v3').api_keys.get(query_params: query_params)
|
16
16
|
puts response.status_code
|
17
|
-
puts response.
|
18
|
-
puts response.
|
17
|
+
puts response.body
|
18
|
+
puts response.headers
|
19
19
|
|
20
20
|
# POST
|
21
21
|
request_body = JSON.parse('
|
@@ -30,15 +30,15 @@ request_body = JSON.parse('
|
|
30
30
|
')
|
31
31
|
response = client.version('v3').api_keys.post(request_body: request_body)
|
32
32
|
puts response.status_code
|
33
|
-
puts response.
|
34
|
-
puts response.
|
35
|
-
api_key_id = JSON.parse(response.
|
33
|
+
puts response.body
|
34
|
+
puts response.headers
|
35
|
+
api_key_id = JSON.parse(response.body)['api_key_id']
|
36
36
|
|
37
37
|
# GET Single
|
38
38
|
response = client.version('v3').api_keys._(api_key_id).get
|
39
39
|
puts response.status_code
|
40
|
-
puts response.
|
41
|
-
puts response.
|
40
|
+
puts response.body
|
41
|
+
puts response.headers
|
42
42
|
|
43
43
|
# PATCH
|
44
44
|
request_body = JSON.parse('
|
@@ -48,8 +48,8 @@ request_body = JSON.parse('
|
|
48
48
|
')
|
49
49
|
response = client.api_keys._(api_key_id).patch(request_body: request_body)
|
50
50
|
puts response.status_code
|
51
|
-
puts response.
|
52
|
-
puts response.
|
51
|
+
puts response.body
|
52
|
+
puts response.headers
|
53
53
|
|
54
54
|
# PUT
|
55
55
|
request_body = JSON.parse('
|
@@ -63,10 +63,10 @@ request_body = JSON.parse('
|
|
63
63
|
')
|
64
64
|
response = client.api_keys._(api_key_id).put(request_body: request_body)
|
65
65
|
puts response.status_code
|
66
|
-
puts response.
|
67
|
-
puts response.
|
66
|
+
puts response.body
|
67
|
+
puts response.headers
|
68
68
|
|
69
69
|
# DELETE
|
70
70
|
response = client.api_keys._(api_key_id).delete
|
71
71
|
puts response.status_code
|
72
|
-
puts response.
|
72
|
+
puts response.headers
|
data/lib/ruby_http_client.rb
CHANGED
@@ -4,27 +4,16 @@ module SendGrid
|
|
4
4
|
require 'net/http'
|
5
5
|
require 'net/https'
|
6
6
|
|
7
|
-
# Loads environment variables from a .env file.
|
8
|
-
class Config
|
9
|
-
def initialize
|
10
|
-
File.open('./.env').readlines.each do |line|
|
11
|
-
key, value = line.split '='
|
12
|
-
ENV[key] = value.chomp
|
13
|
-
end
|
14
|
-
ENV
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
7
|
# Holds the response from an API call.
|
19
8
|
class Response
|
20
9
|
# * *Args* :
|
21
10
|
# - +response+ -> A NET::HTTP response object
|
22
11
|
#
|
23
|
-
attr_reader :status_code, :
|
12
|
+
attr_reader :status_code, :body, :headers
|
24
13
|
def initialize(response)
|
25
14
|
@status_code = response.code
|
26
|
-
@
|
27
|
-
@
|
15
|
+
@body = response.body
|
16
|
+
@headers = response.to_hash.inspect
|
28
17
|
end
|
29
18
|
end
|
30
19
|
|
data/ruby_http_client.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'ruby_http_client'
|
7
|
-
spec.version = '
|
7
|
+
spec.version = '2.0.0'
|
8
8
|
spec.authors = ['Elmer Thomas']
|
9
9
|
spec.email = 'dx@sendgrid.com'
|
10
10
|
spec.summary = 'A simple REST client'
|
@@ -2,12 +2,12 @@ require_relative '../lib/ruby_http_client'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
4
|
class MockResponse
|
5
|
-
attr_reader :status_code, :
|
5
|
+
attr_reader :status_code, :body, :headers
|
6
6
|
|
7
7
|
def initialize(response)
|
8
8
|
@status_code = response['code']
|
9
|
-
@
|
10
|
-
@
|
9
|
+
@body = response['body']
|
10
|
+
@headers = response['headers']
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -91,8 +91,8 @@ class TestClient < Minitest::Test
|
|
91
91
|
args = nil
|
92
92
|
response = @client.build_request(name, args)
|
93
93
|
assert_equal(response.status_code, 200)
|
94
|
-
assert_equal(response.
|
95
|
-
assert_equal(response.
|
94
|
+
assert_equal(response.body, 'message' => 'success')
|
95
|
+
assert_equal(response.headers, 'headers' => 'test')
|
96
96
|
end
|
97
97
|
|
98
98
|
def add_ssl
|
@@ -111,7 +111,7 @@ class TestClient < Minitest::Test
|
|
111
111
|
def test_method_missing
|
112
112
|
response = @client.get
|
113
113
|
assert_equal(response.status_code, 200)
|
114
|
-
assert_equal(response.
|
115
|
-
assert_equal(response.
|
114
|
+
assert_equal(response.body, 'message' => 'success')
|
115
|
+
assert_equal(response.headers, 'headers' => 'test')
|
116
116
|
end
|
117
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_http_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elmer Thomas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,13 +30,12 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
- ".env_sample"
|
34
33
|
- ".github/ISSUE_TEMPLATE"
|
35
34
|
- ".gitignore"
|
36
35
|
- ".travis.yml"
|
37
36
|
- CHANGELOG.md
|
38
37
|
- CONTRIBUTING.md
|
39
|
-
- LICENSE
|
38
|
+
- LICENSE.txt
|
40
39
|
- README.md
|
41
40
|
- Rakefile
|
42
41
|
- examples/example.rb
|
data/.env_sample
DELETED