heroku-client
Advanced tools
Comparing version 1.8.1 to 1.9.0
@@ -27,2 +27,3 @@ 'use strict'; | ||
this.deferred = q.defer(); | ||
this.parseJSON = options.hasOwnProperty('parseJSON') ? options.parseJSON : true; | ||
this.nextRange = 'id ]..; max=1000'; | ||
@@ -223,2 +224,14 @@ this.logger = logfmt.namespace({ | ||
/* | ||
* Get the request body, and parse it (or not) as appropriate. | ||
* - Parse JSON by default. | ||
* - If parseJSON is `false`, it will not parse. | ||
*/ | ||
Request.prototype.parseBody = function parseBody(body) { | ||
if (this.parseJSON) { | ||
return JSON.parse(body || '{}'); | ||
} else { | ||
return body; | ||
} | ||
}; | ||
@@ -249,3 +262,3 @@ /* | ||
err.statusCode = res.statusCode; | ||
err.body = JSON.parse(buffer || '{}'); | ||
err.body = this.parseBody(buffer); | ||
@@ -265,3 +278,3 @@ deferred.reject(err); | ||
var deferred = this.deferred; | ||
var body = JSON.parse(buffer || '{}'); | ||
var body = this.parseBody(buffer); | ||
@@ -268,0 +281,0 @@ this.setCache(res, body); |
{ | ||
"name": "heroku-client", | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"description": "A wrapper for the Heroku v3 API", | ||
@@ -5,0 +5,0 @@ "main": "./lib/heroku.js", |
@@ -29,3 +29,3 @@ # heroku-client [![Build Status](https://travis-ci.org/jclem/node-heroku-client.png?branch=master)](https://travis-ci.org/jclem/node-heroku-client) | ||
Docs are auto-generated and live in the | ||
[docs directory](https://github.com/heroku/node-heroku-client/tree/development/docs). | ||
[docs directory](https://github.com/heroku/node-heroku-client/tree/master/docs). | ||
@@ -119,3 +119,4 @@ ## Usage | ||
'Foo': 'Bar' | ||
} | ||
}, | ||
parseJSON: false | ||
}, function (err, responseBody) { | ||
@@ -122,0 +123,0 @@ }); |
@@ -193,2 +193,16 @@ 'use strict'; | ||
it('parses JSON by default', function(done) { | ||
makeRequest('/apps', {}, function(err, body) { | ||
expect(body).toEqual({ message: 'ok' }); | ||
done(); | ||
}); | ||
}); | ||
it('can accept `false` to parseJSON', function(done) { | ||
makeRequest('/apps', { parseJSON: false }, function(err, body) { | ||
expect(body).toEqual('{ "message": "ok" }'); | ||
done(); | ||
}); | ||
}); | ||
it('accepts a host', function(done) { | ||
@@ -195,0 +209,0 @@ makeRequest('/apps', { host: 'api.example.com' }, function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
255858
7172
308