Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version bump to 0.3.1 and linting.

  • Loading branch information...
commit 0b337a6d5a7b56de3851e9e44ca6e1146974e7d3 1 parent a99cc36
@smurthas authored
Showing with 58 additions and 23 deletions.
  1. +2 −0  .gitignore
  2. +54 −21 lib/fitbit_client.js
  3. +2 −2 package.json
View
2  .gitignore
@@ -1,2 +1,4 @@
node_modules
.env
+.DS_Store
+npm-debug.log
View
75 lib/fitbit_client.js
@@ -1,11 +1,8 @@
/*
* Fitbit-js
- *
- * Copyright (c) 2011 Simon Murtha-Smith <simon@murtha-smith.com>
*/
var url = require('url');
-var http = require('http');
var OAuth = require('oauth').OAuth;
var querystring = require('querystring');
var Serializer = require('serializer');
@@ -13,11 +10,19 @@ var Serializer = require('serializer');
var baseURI = 'https://api.fitbit.com/1';
module.exports = function (api_key, api_secret, callbackURI, unit_system) {
- var client = {version: '0.2.1'};
+ var client = {
+ version: '0.3.1'
+ };
var serializer = Serializer.createSecureSerializer(api_key, api_secret);
- var headers = {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version};
+ var headers = {
+ Accept: '*/*',
+ Connection: 'close',
+ 'User-Agent': 'fitbit-js ' + client.version
+ };
- if (typeof unit_system !== 'undefined' && unit_system !== null) headers['Accept-Language'] = unit_system;
+ if (typeof unit_system !== 'undefined' && unit_system !== null) {
+ headers['Accept-Language'] = unit_system;
+ }
var oAuth = new OAuth('https://api.fitbit.com/oauth/request_token',
'https://api.fitbit.com/oauth/access_token',
@@ -30,23 +35,34 @@ module.exports = function (api_key, api_secret, callbackURI, unit_system) {
var exception = null;
try {
data = JSON.parse(data);
- } catch (e) { exception = e; }
+ } catch (e) {
+ exception = e;
+ }
callback(exception, response, data);
};
}
function get(path, params, token, callback) {
oAuth.get(baseURI + path + '?' + querystring.stringify(params),
- token.oauth_token, token.oauth_token_secret, requestCallback(callback));
+ token.oauth_token,
+ token.oauth_token_secret,
+ requestCallback(callback));
}
function post(path, params, token, callback) {
- oAuth.post(baseURI + path, token.oauth_token, token.oauth_token_secret,
- params, null, requestCallback(callback));
+ oAuth.post(baseURI + path,
+ token.oauth_token,
+ token.oauth_token_secret,
+ params,
+ null,
+ requestCallback(callback));
}
-
+
function oAuthDelete(path, params, token, callback){
- oAuth.delete(baseURI + path, token.oauth_token, token.oauth_token_secret, requestCallback(callback));
+ oAuth.delete(baseURI + path,
+ token.oauth_token,
+ token.oauth_token_secret,
+ requestCallback(callback));
}
// PUBLIC
@@ -60,30 +76,47 @@ module.exports = function (api_key, api_secret, callbackURI, unit_system) {
client.getAccessToken = function (req, res, callback) {
var sess;
- if(req.cookies && req.cookies.fitbit_client) {
- try { sess = serializer.parse(req.cookies.fitbit_client); }catch(E){ }
+ if (req.cookies && req.cookies.fitbit_client) {
+ try {
+ sess = serializer.parse(req.cookies.fitbit_client);
+ } catch(E) { }
}
+
var qs = url.parse(req.url, true).query;
var has_token = qs && qs.oauth_token,
has_secret = sess && sess.token_secret;
- if(has_token && has_secret) { // Access token
+ if (has_token && has_secret) { // Access token
oAuth.getOAuthAccessToken(qs.oauth_token,
sess.token_secret,
qs.oauth_verifier,
- function (error, oauth_token, oauth_token_secret, additionalParameters) {
+ function (error, oauth_token, oauth_token_secret) {
if (error) return callback(error, null);
- callback(null, {oauth_token: oauth_token, oauth_token_secret: oauth_token_secret});
+
+ callback(null, {
+ oauth_token: oauth_token,
+ oauth_token_secret: oauth_token_secret
+ });
});
} else { // Request token
oAuth.getOAuthRequestToken({oauth_callback: callbackURI},
- function (error, oauth_token, oauth_token_secret, oauth_authorize_url, additionalParameters) {
+ function (error, oauth_token, oauth_token_secret) {
if (error) return callback(error, null);
+
+ // stash the secret
res.cookie('fitbit_client',
- serializer.stringify({token_secret:oauth_token_secret}),
- { path: '/', httpOnly: false }); // stash the secret
- res.redirect('https://www.fitbit.com/oauth/authorize?oauth_token=' + oauth_token);
+ serializer.stringify({
+ token_secret: oauth_token_secret
+ }),
+ {
+ path: '/',
+ httpOnly: false
+ }
+ );
+
+ res.redirect('https://www.fitbit.com/oauth/authorize?oauth_token=' +
+ oauth_token);
});
}
};
View
4 package.json
@@ -1,7 +1,7 @@
{
"name": "fitbit-js",
"description": "Simple FitBit API client",
- "version": "0.3.0",
+ "version": "0.3.1",
"author": "Simon Murtha Smith <simon@murtha-smith.com>",
"keywords": ["fitbit"],
"main" : "lib/fitbit_client.js",
@@ -20,6 +20,6 @@
"url": "http://github.com/smurthas/fitbit-js.git"
},
"engines": {
- "node": ">=0.8.0 <0.9.0"
+ "node": ">=0.8.0 <0.11.0"
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.