diff --git a/lib/ClientBase.js b/lib/ClientBase.js index 35b0da6..dff0e8b 100644 --- a/lib/ClientBase.js +++ b/lib/ClientBase.js @@ -15,6 +15,12 @@ var request = require("request"), var BASE_URI = "https://api.coinbase.com/v1/"; var TOKEN_ENDPOINT_URI = 'https://www.coinbase.com/oauth/token'; +var generateExpireTime = function () { + + var timestamp = String(Math.floor(new Date().getTime()/1000) + 15); + + return timestamp; +}; // // constructor @@ -53,29 +59,21 @@ ClientBase.prototype = Object.create(Base.prototype); // private methods // -ClientBase.prototype._generateExpire = function () { - - var timestamp = String(Math.floor(new Date().getTime()/1000) + 15); - - return timestamp; -}; - ClientBase.prototype._setAccessTokenOrExpire = function (url) { + // OAuth access token if (this.accessToken) { - // OAuth access token if (url.indexOf("?") > -1) { return url + '&access_token=' + this.accessToken; } return url + '?access_token=' + this.accessToken; - } else { - // Expire for API key - if (url.indexOf("?") > -1) { - return url + '&expire=' + this._generateExpire(); - } - return url + '?expire=' + this._generateExpire(); } - return url; + + // Expire for API key + if (url.indexOf("?") > -1) { + return url + '&expire=' + generateExpireTime(); + } + return url + '?expire=' + generateExpireTime(); }; ClientBase.prototype._generateSignature = function (url, bodyStr) { @@ -146,7 +144,7 @@ ClientBase.prototype._postHttp = function (path, body, callback, headers) { if (path.indexOf('http') === 0) { url = path; body = body || {}; - body = _.merge(body, {"expire": this._generateExpire()}) + body = _.merge(body, {"expire": generateExpireTime()}) } else { url = this._setAccessTokenOrExpire(this.baseApiUri + path); }