Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/runkeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var API = {
};

var HealthGraph = exports.HealthGraph = function(options) {

this.client_id = options.client_id || null ;
this.client_secret = options.client_secret || null;
this.auth_url = options.auth_url || "https://runkeeper.com/apps/authorize";
Expand All @@ -51,21 +51,22 @@ HealthGraph.prototype.getNewToken = function (authorization_code, callback) {
client_secret: this.client_secret,
redirect_uri: this.redirect_uri
};

var paramlist = [];
for (pk in request_params) {
paramlist.push(pk + "=" + request_params[pk]);
};
var body_string = paramlist.join("&");
var request_details = {

var request_details = {
method: "POST",
headers: {'content-type' : 'application/x-www-form-urlencoded'},
uri: this.access_token_url,
body: body_string
};

request(request_details, function(error, response, body) {
if(error || response.statusCode >= 400) return callback(error || 'Response status code' + response.statusCode);
callback(error, JSON.parse(body)['access_token']);
});
};
Expand All @@ -83,6 +84,7 @@ HealthGraph.prototype.apiCall = function(method, media_type, endpoint, callback)
uri: "https://" + this.api_domain + endpoint
};
request(request_details, function(error, response, body) {
if(error || response.statusCode >= 400) return callback(error || 'Response status code' + response.statusCode);
var parsed;
try {
parsed = JSON.parse(body);
Expand All @@ -106,7 +108,8 @@ for (func_name in API) {
uri: "https://" + this.api_domain + API[func_name]['uri']
};
request(request_details,
function(error, response, body) {
function(error, response, body) {
if(error || response.statusCode >= 400) return callback(error || 'Response status code' + response.statusCode);
var parsed;
try {
parsed = JSON.parse(body);
Expand All @@ -117,10 +120,6 @@ for (func_name in API) {
callback(error, parsed);
}
});
};
};
})(func_name);
};