Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from coinbase/jori-api-key-tweaks
Browse files Browse the repository at this point in the history
Tweaks based on Roman's comments
  • Loading branch information
jorilallo committed Mar 17, 2015
2 parents 1a6561c + 5c61589 commit 8fbe59f
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/ClientBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8fbe59f

Please sign in to comment.