Permalink
Browse files

Response JSON parsing and version bump.

  • Loading branch information...
1 parent 10cdb7e commit b724edfee8c849cb5e333d2988703fd76b70c64b Andrew Kirilenko committed Jul 16, 2012
Showing with 11 additions and 3 deletions.
  1. +7 −1 lib/client.js
  2. +1 −1 package.json
  3. +3 −1 src/client.coffee
View
@@ -168,8 +168,14 @@
return this.request(requestInfo, cb);
};
- Client.prototype.parseResponse = function(error, response, body, cb) {
+ Client.prototype.parseResponse = function(error, response, body, cb, parseJson) {
+ if (parseJson == null) {
+ parseJson = true;
+ }
if (response.statusCode === 200) {
+ if (parseJson && typeof body === 'string') {
+ body = JSON.parse(body);
+ }
return cb(null, body);
} else {
return cb(new Error(body), null);
View
@@ -1,6 +1,6 @@
{
"name": "iron_core",
- "version": "0.0.3",
+ "version": "0.1.0",
"description": "Core library for Iron products",
"homepage": "https://github.com/iron-io/iron_core_node",
"author": "Andrew Kirilenko & Iron.io, Inc",
View
@@ -109,8 +109,10 @@ class Client
@request(requestInfo, cb)
- parseResponse: (error, response, body, cb) ->
+ parseResponse: (error, response, body, cb, parseJson = true) ->
if response.statusCode == 200
+ body = JSON.parse(body) if parseJson and typeof(body) == 'string'
+
cb(null, body)
else
cb(new Error(body), null)

0 comments on commit b724edf

Please sign in to comment.