Comparing version 0.4.2 to 0.5.0
@@ -48,3 +48,3 @@ var request = require('request'); | ||
return tokenPromise.get('access_token'); | ||
return tokenPromise.get('body').get('access_token'); | ||
}; | ||
@@ -69,3 +69,3 @@ | ||
api.getResult = function(resource, id, parameters) { | ||
return this.get(resource, id, parameters).get('result'); | ||
return this.get(resource, id, parameters).get('body').get('result'); | ||
}; | ||
@@ -88,3 +88,3 @@ | ||
return promises[0].then(_.bind(function(firstPage) { | ||
for (var offset = this.settings.maxLimit; offset < firstPage.pagination.total; offset += this.settings.maxLimit) { | ||
for (var offset = this.settings.maxLimit; offset < firstPage.body.pagination.total; offset += this.settings.maxLimit) { | ||
promises.push(this.index(resource, _.extend({}, parameters, {offset: offset, limit: this.settings.maxLimit}))); | ||
@@ -94,3 +94,3 @@ } | ||
return q.all(promises).then(function(pages) { | ||
return _.flatten(_.pluck(pages, 'result'), true); | ||
return _.flatten(_.pluck(_.pluck(pages, 'body'), 'result'), true); | ||
}); | ||
@@ -100,2 +100,19 @@ }, this)); | ||
api.post = function(resource, parameters) { | ||
var deferred = q.defer(); | ||
return this.getToken().then(_.bind(function(token) { | ||
var req = { | ||
url: this.urlFor(resource), | ||
method: 'POST', | ||
json: parameters, | ||
headers: {'Authorization': 'Bearer ' + token} | ||
}; | ||
request(req, resolveResponse(deferred, this, req)); | ||
return deferred.promise; | ||
}, this)); | ||
} | ||
api.set = function(setting, value) { | ||
@@ -120,6 +137,6 @@ if (arguments.length == 1) { | ||
}, api)); | ||
} else if (res.statusCode != 200) { | ||
} else if (res.statusCode >= 400) { | ||
deferred.reject({res: res, body: body}); | ||
} else { | ||
deferred.resolve(body); | ||
deferred.resolve({res: res, body: body}); | ||
} | ||
@@ -126,0 +143,0 @@ }; |
{ | ||
"name": "tol-api", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "TraderOnline api client", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
5562
125