Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8 from cquartier/master

Unit System option
  • Loading branch information...
commit e3993a1ce1efe78b45e9d3747802815a5cb36e78 2 parents ad93b76 + 1da34ac
@smurthas authored
Showing with 10 additions and 9 deletions.
  1. +2 −2 README.md
  2. +3 −3 example/test.js
  3. +5 −4 lib/fitbit_client.js
View
4 README.md
@@ -24,8 +24,8 @@ callback URL of `http://localhost:8553`.
```bash
npm install
-cd test
-node test.js [Consumer Key] [Consumer Secret]
+cd example
+node test.js [Consumer Key] [Consumer Secret] [Unit System (en_US or en_GB)](optional. Defaults to metric units)
```
open [http://localhost:8553](http://localhost:8553)
View
6 example/test.js
@@ -4,10 +4,10 @@ var app = express();
app.use(express.bodyParser());
app.use(express.cookieParser('sess'));
-var PORT = process.argv[4] || 8553;
+var PORT = process.argv[5] || 8553;
var fitbitClient = require('../')(process.argv[2], process.argv[3],
- 'http://localhost:' + PORT);
+ 'http://localhost:' + PORT, process.argv[4]);
var token;
app.get('/', function (req, res) {
@@ -21,7 +21,7 @@ app.get('/', function (req, res) {
});
app.get('/getStuff', function (req, res) {
- fitbitClient.apiCall('GET', '/user/-/activities/date/2011-05-25.json',
+ fitbitClient.apiCall('GET', '/user/-/profile.json',
{token: {oauth_token_secret: token.oauth_token_secret,
oauth_token: token.oauth_token}},
function(err, resp, json) {
View
9 lib/fitbit_client.js
@@ -12,16 +12,17 @@ var Serializer = require('serializer');
var baseURI = 'http://api.fitbit.com/1';
-module.exports = function (api_key, api_secret, callbackURI) {
+module.exports = function (api_key, api_secret, callbackURI, unit_system) {
var client = {version: '0.1.0'};
var serializer = Serializer.createSecureSerializer(api_key, api_secret);
+ var headers = {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version};
+
+ if (typeof unit_system !== 'undefined' && unit_system !== null) headers['Accept-Language'] = unit_system;
var oAuth = new OAuth('http://api.fitbit.com/oauth/request_token',
'http://api.fitbit.com/oauth/access_token',
api_key, api_secret, '1.0', callbackURI,
- 'HMAC-SHA1', null,
- {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version});
-
+ 'HMAC-SHA1', null, headers);
function requestCallback(callback) {
return function (err, data, response) {
Please sign in to comment.
Something went wrong with that request. Please try again.