Skip to content

Commit de82aba

Browse files
Versiom Bump 2.0.0: Made the Response variables non-redundant. e.g. response.response_body becomes response.body
1 parent 89df34c commit de82aba

File tree

6 files changed

+36
-40
lines changed

6 files changed

+36
-40
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
33

44
This project adheres to [Semantic Versioning](http://semver.org/).
55

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+
613
## [1.1.0] - 2016-03-17
714
### Added
815
- Config class moved to client

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ global_headers = {'Authorization' => 'Basic XXXXXXX' }
2626
client = SendGrid::Client(host: 'base_url', request_headers: global_headers)
2727
client.your.api._(param).call.get
2828
puts response.status_code
29-
puts response.response_body
30-
puts response.response_headers
29+
puts response.body
30+
puts response.headers
3131
```
3232

3333
`POST /your/api/{param}/call` with headers, query parameters and a request body with versioning.
@@ -43,8 +43,8 @@ response = client.your.api._(param).call.post(request_body: data,
4343
query_params: query_params,
4444
request_headers: request_headers)
4545
puts response.status_code
46-
puts response.response_body
47-
puts response.response_headers
46+
puts response.body
47+
puts response.headers
4848
```
4949

5050
# Usage

Diff for: examples/example.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
require_relative '../lib/ruby_http_client'
22

3-
SendGrid::Config.new
3+
# This example uses the SendGrid API as an example
44
headers = JSON.parse('
55
{
66
"Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '",
77
"Content-Type": "application/json"
88
}
99
')
10-
host = ENV['LOCAL_HOST']
10+
host = 'https://api.sendgrid.com'
1111
client = SendGrid::Client.new(host: host, request_headers: headers)
1212

1313
# GET Collection
1414
query_params = { 'limit' => 100, 'offset' => 0 }
1515
response = client.version('v3').api_keys.get(query_params: query_params)
1616
puts response.status_code
17-
puts response.response_body
18-
puts response.response_headers
17+
puts response.body
18+
puts response.headers
1919

2020
# POST
2121
request_body = JSON.parse('
@@ -30,15 +30,15 @@
3030
')
3131
response = client.version('v3').api_keys.post(request_body: request_body)
3232
puts response.status_code
33-
puts response.response_body
34-
puts response.response_headers
35-
api_key_id = JSON.parse(response.response_body)['api_key_id']
33+
puts response.body
34+
puts response.headers
35+
api_key_id = JSON.parse(response.body)['api_key_id']
3636

3737
# GET Single
3838
response = client.version('v3').api_keys._(api_key_id).get
3939
puts response.status_code
40-
puts response.response_body
41-
puts response.response_headers
40+
puts response.body
41+
puts response.headers
4242

4343
# PATCH
4444
request_body = JSON.parse('
@@ -48,8 +48,8 @@
4848
')
4949
response = client.api_keys._(api_key_id).patch(request_body: request_body)
5050
puts response.status_code
51-
puts response.response_body
52-
puts response.response_headers
51+
puts response.body
52+
puts response.headers
5353

5454
# PUT
5555
request_body = JSON.parse('
@@ -63,10 +63,10 @@
6363
')
6464
response = client.api_keys._(api_key_id).put(request_body: request_body)
6565
puts response.status_code
66-
puts response.response_body
67-
puts response.response_headers
66+
puts response.body
67+
puts response.headers
6868

6969
# DELETE
7070
response = client.api_keys._(api_key_id).delete
7171
puts response.status_code
72-
puts response.response_headers
72+
puts response.headers

Diff for: lib/ruby_http_client.rb

+3-14
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,16 @@ module SendGrid
44
require 'net/http'
55
require 'net/https'
66

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-
187
# Holds the response from an API call.
198
class Response
209
# * *Args* :
2110
# - +response+ -> A NET::HTTP response object
2211
#
23-
attr_reader :status_code, :response_body, :response_headers
12+
attr_reader :status_code, :body, :headers
2413
def initialize(response)
2514
@status_code = response.code
26-
@response_body = response.body
27-
@response_headers = response.to_hash.inspect
15+
@body = response.body
16+
@headers = response.to_hash.inspect
2817
end
2918
end
3019

Diff for: ruby_http_client.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
44

55
Gem::Specification.new do |spec|
66
spec.name = 'ruby_http_client'
7-
spec.version = '1.1.0'
7+
spec.version = '2.0.0'
88
spec.authors = ['Elmer Thomas']
99
spec.email = '[email protected]'
1010
spec.summary = 'A simple REST client'

Diff for: test/test_ruby_http_client.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
require 'minitest/autorun'
33

44
class MockResponse
5-
attr_reader :status_code, :response_body, :response_headers
5+
attr_reader :status_code, :body, :headers
66

77
def initialize(response)
88
@status_code = response['code']
9-
@response_body = response['body']
10-
@response_headers = response['headers']
9+
@body = response['body']
10+
@headers = response['headers']
1111
end
1212
end
1313

@@ -91,8 +91,8 @@ def test_build_request
9191
args = nil
9292
response = @client.build_request(name, args)
9393
assert_equal(response.status_code, 200)
94-
assert_equal(response.response_body, 'message' => 'success')
95-
assert_equal(response.response_headers, 'headers' => 'test')
94+
assert_equal(response.body, 'message' => 'success')
95+
assert_equal(response.headers, 'headers' => 'test')
9696
end
9797

9898
def add_ssl
@@ -111,7 +111,7 @@ def test__
111111
def test_method_missing
112112
response = @client.get
113113
assert_equal(response.status_code, 200)
114-
assert_equal(response.response_body, 'message' => 'success')
115-
assert_equal(response.response_headers, 'headers' => 'test')
114+
assert_equal(response.body, 'message' => 'success')
115+
assert_equal(response.headers, 'headers' => 'test')
116116
end
117117
end

0 commit comments

Comments
 (0)