producteca-sdk
Advanced tools
Comparing version 3.0.0 to 3.1.0
(function() { | ||
var Client, Promise, RESPONSE_ELEMENT, request, | ||
var Client, Promise, request, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
@@ -9,12 +9,8 @@ | ||
Promise.promisifyAll(request, { | ||
multiArgs: true | ||
}); | ||
Promise.promisifyAll(request); | ||
RESPONSE_ELEMENT = 0; | ||
module.exports = Client = (function() { | ||
function Client(url, accessToken) { | ||
function Client(url, authMethod) { | ||
this.url = url; | ||
this.accessToken = accessToken; | ||
this.authMethod = authMethod; | ||
this._makeUrl = __bind(this._makeUrl, this); | ||
@@ -48,9 +44,7 @@ this._doRequest = __bind(this._doRequest, this); | ||
url: this._makeUrl(path), | ||
auth: { | ||
bearer: this.accessToken | ||
}, | ||
auth: this.authMethod, | ||
json: true, | ||
body: body | ||
}; | ||
return request["" + verb + "Async"](options).get(RESPONSE_ELEMENT).then(function(res) { | ||
return request["" + verb + "Async"](options).then(function(res) { | ||
if (res.statusCode > 400) { | ||
@@ -57,0 +51,0 @@ throw res.body; |
@@ -12,2 +12,3 @@ (function() { | ||
} | ||
this._buildAuthMethod = __bind(this._buildAuthMethod, this); | ||
this._makeUrlAsync = __bind(this._makeUrlAsync, this); | ||
@@ -21,4 +22,4 @@ this.respondMany = __bind(this.respondMany, this); | ||
endpoint.url = endpoint.url || "http://api.producteca.com"; | ||
this.client = new Client(endpoint.url, endpoint.accessToken); | ||
return this.asyncClient = new Client(this._makeUrlAsync(endpoint.url, endpoint.accessToken)); | ||
this.client = new Client(endpoint.url, this._buildAuthMethod(endpoint)); | ||
return this.asyncClient = new Client(this._makeUrlAsync(endpoint.url, this._buildAuthMethod(endpoint))); | ||
}; | ||
@@ -41,2 +42,17 @@ | ||
ProductecaApi.prototype._buildAuthMethod = function(_arg) { | ||
var accessToken, basicAuth; | ||
accessToken = _arg.accessToken, basicAuth = _arg.basicAuth; | ||
if (accessToken != null) { | ||
return { | ||
bearer: accessToken | ||
}; | ||
} else if (basicAuth != null) { | ||
return { | ||
user: basicAuth.companyId.toString(), | ||
pass: basicAuth.masterToken | ||
}; | ||
} | ||
}; | ||
return ProductecaApi; | ||
@@ -43,0 +59,0 @@ |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"main": "build/sdk.js", | ||
@@ -11,0 +11,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
669
58006