Skip to content

Commit 1d05710

Browse files
fix api requests with post/put
1 parent 4a42a81 commit 1d05710

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ clean:
99
lint:
1010
eslint lib/
1111
test: clean lint
12-
mocha --reporter spec test/ $(MOCHAFLAGS)
12+
mocha -t 6000 --reporter spec test/ $(MOCHAFLAGS)

lib/api.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,33 @@ TestingBot.prototype.deleteLabTest = function(testID, callback) {
134134
};
135135

136136
TestingBot.prototype.request = function(req_data, callback) {
137-
var requestPath = '/v1/' + req_data.url;
137+
var requestPath = '/v1' + req_data.url;
138138
if (req_data.method === 'GET' && req_data.data) {
139139
requestPath = requestPath + '?' + querystring.stringify(req_data.data);
140140
}
141-
142-
request({
141+
var requestOptions = {
143142
method: req_data.method,
144143
uri: 'https://api.testingbot.com' + requestPath,
145144
auth: {
146145
user: this.options.api_key,
147146
pass: this.options.api_secret,
148147
sendImmediately: true
149148
}
150-
}, function(error, response) {
149+
};
150+
151+
if (req_data.method !== 'GET' && req_data.data) {
152+
requestOptions.json = req_data.data;
153+
}
154+
155+
request(requestOptions, function(error, response) {
151156
var responseBody = null;
157+
if (typeof(response.body) === 'string') {
158+
response.body = JSON.parse(response.body);
159+
}
152160
if (response.statusCode.toString().substring(0, 1) === '2') {
153-
responseBody = JSON.parse(response.body);
161+
responseBody = response.body;
154162
} else {
155-
error = JSON.parse(response.body);
163+
error = response.body;
156164
}
157165
callback(error, responseBody);
158166
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "TestingBot <[email protected]> (testingbot.com)",
33
"name": "testingbot-api",
44
"description": "A wrapper around TestingBot's REST API",
5-
"version": "1.0.2",
5+
"version": "1.0.3",
66
"scripts": {
77
"lint": "eslint .",
88
"test": "make test"

test/api_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,18 @@ describe('Api Tests', function() {
5151
});
5252
});
5353
});
54+
55+
it('should update a user object', function(done) {
56+
var that = this;
57+
var newName = "name_" + Math.round(Math.random()*10000);
58+
this.api.updateUserInfo({ user: { first_name : newName } }, function(err, response) {
59+
assert.equal(err, null);
60+
that.api.getUserInfo(function(err, response) {
61+
assert.notEqual(response, null);
62+
assert.equal(err, null);
63+
assert.equal(response.first_name, newName);
64+
done();
65+
});
66+
});
67+
});
5468
});

0 commit comments

Comments
 (0)