Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit 6fa986b

Browse files
Version Bump 2.0.0: Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.body
1 parent a12cfd7 commit 6fa986b

File tree

6 files changed

+69
-65
lines changed

6 files changed

+69
-65
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ 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-06
7+
### Changed
8+
- Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.body
9+
610
## [1.0.1] - 2016-04-08
711
### Added
812
- We are live!

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ request.method = 'GET'
2727
request.path = '/your/api/' + param + '/call'
2828
client.API(request, function (response) {
2929
console.log(response.statusCode)
30-
console.log(response.responseBody)
31-
console.log(response.responseHeaders)
30+
console.log(response.body)
31+
console.log(response.headers)
3232
})
3333
```
3434

@@ -51,11 +51,11 @@ requestBody = {
5151
'awesome': 1,
5252
'data': 3
5353
}
54-
request.requestBody = requestBody
54+
request.body = requestBody
5555
client.API(request, function (response) {
5656
console.log(response.statusCode)
57-
console.log(response.responseBody)
58-
console.log(response.responseHeaders)
57+
console.log(response.body)
58+
console.log(response.headers)
5959
})
6060
```
6161

examples/example.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ requestGet.queryParams['limit'] = 100
1717
requestGet.queryParams['offset'] = 0
1818
client.API(requestGet, function (response) {
1919
console.log(response.statusCode)
20-
console.log(response.responseBody)
21-
console.log(response.responseHeaders)
20+
console.log(response.body)
21+
console.log(response.headers)
2222
})
2323

2424
// POST
@@ -33,14 +33,14 @@ var requestBody = {
3333
var requestPost = JSON.parse(JSON.stringify(emptyRequest));
3434
requestPost.method = 'POST'
3535
requestPost.path = '/v3/api_keys'
36-
requestPost.requestBody = requestBody
36+
requestPost.body = requestBody
3737
requestPost.headers['X-Test'] = 'test'
3838
function createAPIKey (callback) {
3939
client.API(requestPost, function (response) {
4040
console.log(response.statusCode)
41-
console.log(response.responseBody)
42-
console.log(response.responseHeaders)
43-
var body = JSON.parse(response.responseBody)
41+
console.log(response.body)
42+
console.log(response.headers)
43+
var body = JSON.parse(response.body)
4444
callback(body.api_key_id)
4545
})
4646
}
@@ -54,8 +54,8 @@ createAPIKey(function (returnValue) { // This ensures we POST a new key first, t
5454
requestGetSingle.path = '/v3/api_keys'.concat(api_key_id)
5555
client.API(requestGetSingle, function (response) {
5656
console.log(response.statusCode)
57-
console.log(response.responseBody)
58-
console.log(response.responseHeaders)
57+
console.log(response.body)
58+
console.log(response.headers)
5959
})
6060

6161
// PATCH
@@ -65,11 +65,11 @@ createAPIKey(function (returnValue) { // This ensures we POST a new key first, t
6565
var requestPatch = JSON.parse(JSON.stringify(emptyRequest))
6666
requestPatch.method = 'PATCH'
6767
requestPatch.path = '/v3/api_keys'.concat(api_key_id)
68-
requestPatch.requestBody = requestBody
68+
requestPatch.body = requestBody
6969
client.API(requestPatch, function (response) {
7070
console.log(response.statusCode)
71-
console.log(response.responseBody)
72-
console.log(response.responseHeaders)
71+
console.log(response.body)
72+
console.log(response.headers)
7373
})
7474

7575
// PUT
@@ -83,11 +83,11 @@ createAPIKey(function (returnValue) { // This ensures we POST a new key first, t
8383
var requestPut = JSON.parse(JSON.stringify(emptyRequest))
8484
requestPut.method = 'PUT'
8585
requestPut.path = '/v3/api_keys'.concat(api_key_id)
86-
requestPut.requestBody = requestBody
86+
requestPut.body = requestBody
8787
client.API(requestPut, function (response) {
8888
console.log(response.statusCode)
89-
console.log(response.responseBody)
90-
console.log(response.responseHeaders)
89+
console.log(response.body)
90+
console.log(response.headers)
9191
})
9292

9393
// DELETE
@@ -96,7 +96,7 @@ createAPIKey(function (returnValue) { // This ensures we POST a new key first, t
9696
requestDelete.path = '/v3/api_keys'.concat(api_key_id)
9797
client.API(requestDelete, function (response) {
9898
console.log(response.statusCode)
99-
console.log(response.responseBody)
100-
console.log(response.responseHeaders)
99+
console.log(response.body)
100+
console.log(response.headers)
101101
})
102102
})

lib/client.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ var request = {
1010
method: '',
1111
path: '',
1212
headers: {},
13-
requestBody: {},
13+
body: {},
1414
queryParams: {}
1515
}
1616

1717
// response holds the response from an API call, use this as an initializer
1818
// like so: JSON.parse(JSON.stringify(response))
1919
var response = {
2020
'statusCode': '',
21-
'responseBody': {},
22-
'responseHeaders': {}
21+
'body': {},
22+
'headers': {}
2323
}
2424

2525
// Client allows for quick and easy access any REST or REST-like API.
2626
function Client (globalRequest) {
2727
var emptyResponse = JSON.parse(JSON.stringify(response))
28-
var requestBody = ''
28+
var body = ''
2929

3030
// utility function to detect empty objects
3131
function isEmpty (obj) {
@@ -62,9 +62,9 @@ function Client (globalRequest) {
6262
}
6363

6464
// add the request body's content length
65-
if (!isEmpty(endpointRequest.requestBody)) {
66-
requestBody = JSON.stringify(endpointRequest.requestBody)
67-
request.headers['Content-Length'] = requestBody.length
65+
if (!isEmpty(endpointRequest.body)) {
66+
body = JSON.stringify(endpointRequest.body)
67+
request.headers['Content-Length'] = body.length
6868
}
6969

7070
return request
@@ -86,8 +86,8 @@ function Client (globalRequest) {
8686
httpResponse.on('end', function () {
8787
var response = JSON.parse(JSON.stringify(emptyResponse))
8888
response.statusCode = httpResponse.statusCode
89-
response.responseBody = responseBody
90-
response.responseHeaders = httpResponse.headers
89+
response.body = responseBody
90+
response.headers = httpResponse.headers
9191
callback(response)
9292
})
9393
})
@@ -97,8 +97,8 @@ function Client (globalRequest) {
9797
})
9898

9999
// if thre is a request body, sent it
100-
if (!isEmpty(endpointRequest.requestBody)) {
101-
httpRequest.write(requestBody)
100+
if (!isEmpty(endpointRequest.body)) {
101+
httpRequest.write(body)
102102
}
103103

104104
httpRequest.end()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"name": "sendgrid-rest",
77
"description": "HTTP REST client, simplified for Node.js.",
8-
"version": "1.0.1",
8+
"version": "2.0.0",
99
"homepage": "https://sendgrid.com",
1010
"repository": {
1111
"type": "git",

test/test.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ describe('Client', function () {
2727
requestGet.queryParams['offset'] = 0
2828
client.API(requestGet, function (response) {
2929
assert.equal(response.statusCode, '200', 'response.StatusCode equal 200')
30-
assert.equal(response.responseBody,
31-
'{"message":"Success"}', 'response.responseBody equal {"message":"Success"}')
32-
assert.equal(JSON.stringify(response.responseHeaders),
30+
assert.equal(response.body,
31+
'{"message":"Success"}', 'response.body equal {"message":"Success"}')
32+
assert.equal(JSON.stringify(response.headers),
3333
'{"content-type":"application/json"}',
34-
'response.responseHeaders equal {"content-type": "application/json"}')
34+
'response.headers equal {"content-type": "application/json"}')
3535
done()
3636
})
3737
})
@@ -56,21 +56,21 @@ describe('Client', function () {
5656
var requestPost = JSON.parse(JSON.stringify(emptyRequest))
5757
requestPost.method = 'POST'
5858
requestPost.path = '/test'
59-
requestPost.requestBody = requestBody
59+
requestPost.body = requestBody
6060
requestPost.queryParams['limit'] = 100
6161
requestPost.queryParams['offset'] = 0
6262
requestPost.headers['X-Test'] = 'test'
6363
client.API(requestPost, function (response) {
6464
assert.equal(response.statusCode, '201', 'response.StatusCode equal 200')
65-
assert.equal(JSON.parse(response.responseBody).path,
65+
assert.equal(JSON.parse(response.body).path,
6666
'/test?limit=100&offset=0',
6767
'path equal to /test?limit=100&offset=0')
68-
assert.equal(JSON.stringify(JSON.parse(response.responseBody).headers),
68+
assert.equal(JSON.stringify(JSON.parse(response.body).headers),
6969
'{"x-test":"test","content-length":20,"host":"api.test.com"}',
7070
'headers equal {"x-test":"test","content-length":20,"host":"api.test.com"}')
71-
assert.equal(JSON.stringify(response.responseHeaders),
71+
assert.equal(JSON.stringify(response.headers),
7272
'{"content-type":"application/json"}',
73-
'response.responseHeaders equal {"content-type":"application/json"}')
73+
'response.headers equal {"content-type":"application/json"}')
7474
done()
7575
})
7676
})
@@ -89,11 +89,11 @@ describe('Client', function () {
8989
requestGet.path = '/test'
9090
client.API(requestGet, function (response) {
9191
assert.equal(response.statusCode, '200', 'response.StatusCode equal 200')
92-
assert.equal(response.responseBody, '{"message":"Success"}',
93-
'response.responseBody equal {"message":"Success"}')
94-
assert.equal(JSON.stringify(response.responseHeaders),
92+
assert.equal(response.body, '{"message":"Success"}',
93+
'response.body equal {"message":"Success"}')
94+
assert.equal(JSON.stringify(response.headers),
9595
'{"content-type":"application/json"}',
96-
'response.responseHeaders equal {"content-type":"application/json"}')
96+
'response.headers equal {"content-type":"application/json"}')
9797
})
9898

9999
nock(TEST_HOST)
@@ -105,33 +105,33 @@ describe('Client', function () {
105105
'test': 'Test Body'
106106
}
107107
var requestPost = JSON.parse(JSON.stringify(emptyRequest))
108-
requestPost.requestBody = requestBody
108+
requestPost.body = requestBody
109109
requestPost.method = 'POST'
110110
requestPost.path = '/test'
111111
client.API(requestPost, function (response) {
112112
assert.equal(response.statusCode, '201', 'response.StatusCode equal 201')
113-
assert.equal(response.responseBody, '{"message":"Success"}',
114-
'response.responseBody equal {"message":"Success"}')
115-
assert.equal(JSON.stringify(response.responseHeaders),
113+
assert.equal(response.body, '{"message":"Success"}',
114+
'response.body equal {"message":"Success"}')
115+
assert.equal(JSON.stringify(response.headers),
116116
'{"content-type":"application/json"}',
117-
'response.responseHeaders equal {"content-type":"application/json"}')
117+
'response.headers equal {"content-type":"application/json"}')
118118
})
119119
nock(TEST_HOST)
120120
.patch('/test')
121121
.reply(200, {
122122
message: 'Success'
123123
})
124124
var requestPatch = JSON.parse(JSON.stringify(emptyRequest))
125-
requestPatch.requestBody = requestBody
125+
requestPatch.body = requestBody
126126
requestPatch.method = 'PATCH'
127127
requestPatch.path = '/test'
128128
client.API(requestPatch, function (response) {
129129
assert.equal(response.statusCode, '200', 'response.StatusCode equal 200')
130-
assert.equal(response.responseBody, '{"message":"Success"}',
131-
'response.responseBody equal {"message":"Success"}')
132-
assert.equal(JSON.stringify(response.responseHeaders),
130+
assert.equal(response.body, '{"message":"Success"}',
131+
'response.body equal {"message":"Success"}')
132+
assert.equal(JSON.stringify(response.headers),
133133
'{"content-type":"application/json"}',
134-
'response.responseHeaders equal {"content-type":"application/json"}')
134+
'response.headers equal {"content-type":"application/json"}')
135135
})
136136

137137
nock(TEST_HOST)
@@ -140,16 +140,16 @@ describe('Client', function () {
140140
message: 'Success'
141141
})
142142
var requestPut = JSON.parse(JSON.stringify(emptyRequest))
143-
requestPut.requestBody = requestBody
143+
requestPut.body = requestBody
144144
requestPut.method = 'PUT'
145145
requestPut.path = '/test'
146146
client.API(requestPut, function (response) {
147147
assert.equal(response.statusCode, '200', 'response.StatusCode equal 200')
148-
assert.equal(response.responseBody, '{"message":"Success"}',
149-
'response.responseBody equal {"message":"Success"}')
150-
assert.equal(JSON.stringify(response.responseHeaders),
148+
assert.equal(response.body, '{"message":"Success"}',
149+
'response.body equal {"message":"Success"}')
150+
assert.equal(JSON.stringify(response.headers),
151151
'{"content-type":"application/json"}',
152-
'response.responseHeaders equal {"content-type":"application/json"}')
152+
'response.headers equal {"content-type":"application/json"}')
153153
})
154154

155155
nock(TEST_HOST)
@@ -162,11 +162,11 @@ describe('Client', function () {
162162
requestDelete.path = '/test'
163163
client.API(requestDelete, function (response) {
164164
assert.equal(response.statusCode, '204', 'response.StatusCode equal 204')
165-
assert.equal(response.responseBody, '{"message":"Success"}',
166-
'response.responseBody equal {"message":"Success"}')
167-
assert.equal(JSON.stringify(response.responseHeaders),
165+
assert.equal(response.body, '{"message":"Success"}',
166+
'response.body equal {"message":"Success"}')
167+
assert.equal(JSON.stringify(response.headers),
168168
'{"content-type":"application/json"}',
169-
'response.responseHeaders equal {"content-type":"application/json"}')
169+
'response.headers equal {"content-type":"application/json"}')
170170
})
171171
done()
172172
})

0 commit comments

Comments
 (0)