fitbit-client-oauth2
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "fitbit-client-oauth2", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A fitbit client using OAuth 2.0 authentication.", | ||
@@ -23,4 +23,4 @@ "main": "src/index.js", | ||
"homepage": "https://github.com/thegameofcode/fitbit-client-oauth2#readme", | ||
"license": "MIT", | ||
"dependencies": { | ||
"moment": "^2.10.6", | ||
"object-assign": "^3.0.0", | ||
@@ -27,0 +27,0 @@ "promise": "^7.0.3", |
@@ -48,1 +48,9 @@ # Fitbit client | ||
## Other implementations | ||
This package exists because Fitbit's newest endpoints works only with OAuth 2.0 and all other existing packages works only with OAuth 1.0. Some examples: | ||
- [fitbit-node](https://github.com/lukasolson/fitbit-node) | ||
- [fitbit-js](https://github.com/smurthas/fitbit-js) | ||
- [node-fitbit](https://github.com/p-m-p/node-fitbit) | ||
@@ -56,2 +56,11 @@ var oauth2 = require('simple-oauth2'); | ||
proto.getDailyActivitySummary = function(options) { | ||
options = helper.buildDailyActivitySummaryOptions(options); | ||
//TODO: improve this way of getting the token | ||
options.access_token = this.token.token.access_token; | ||
return helper.createRequestPromise(options); | ||
}; | ||
proto.getTimeSeries = function(options) { | ||
@@ -58,0 +67,0 @@ options = helper.buildTimeSeriesOptions(options); |
var assign = require('object-assign'); | ||
var request = require('request-promise'); | ||
var moment = require('moment'); | ||
@@ -9,7 +10,9 @@ var config = require('./config'); | ||
buildTimeSeriesOptions: buildTimeSeriesOptions, | ||
buildIntradayTimeSeriesOptions: buildIntradayTimeSeriesOptions | ||
buildIntradayTimeSeriesOptions: buildIntradayTimeSeriesOptions, | ||
buildDailyActivitySummaryOptions: buildDailyActivitySummaryOptions | ||
}; | ||
function createRequestPromise(options) { | ||
return request.get({ | ||
var acceptLanguage = options.units === 'METRIC' ? 'es_ES' : 'en_US'; | ||
options = assign({ | ||
url: options.url, | ||
@@ -19,6 +22,12 @@ method: 'GET', | ||
headers: { | ||
Authorization: 'Bearer ' + options.access_token | ||
Authorization: 'Bearer ' + options.access_token, | ||
'Accept-Language': acceptLanguage | ||
} | ||
}).then(function(res) { | ||
res.requestedResource = options.resourcePath.replace('/', '-'); | ||
}, options); | ||
delete options.units; | ||
return request.get(options).then(function(res) { | ||
if (options.resourcePath) { | ||
res.requestedResource = options.resourcePath.replace('/', '-'); | ||
} | ||
return res; | ||
@@ -35,3 +44,4 @@ }); | ||
baseDate: 'today', | ||
period: '1d' | ||
period: '1d', | ||
units: 'IMPERIAL' | ||
}, options); | ||
@@ -61,3 +71,4 @@ | ||
endDate: 'today', | ||
detailLevel: '1min' | ||
detailLevel: '1min', | ||
units: 'IMPERIAL' | ||
}, options); | ||
@@ -80,1 +91,15 @@ | ||
} | ||
function buildDailyActivitySummaryOptions(options) { | ||
var uri = config.FITBIT_BASE_API_URL + '/1/user/{userId}/activities/date/{date}.json'; | ||
options = assign({ | ||
userId: '-', | ||
date: moment().format('YYYY-MM-DD'), | ||
units: 'IMPERIAL' | ||
}, options); | ||
options.uri = uri.replace('{userId}', options.userId).replace('{date}', options.date); | ||
return options; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7959
147
56
5
+ Addedmoment@^2.10.6
+ Addedmoment@2.30.1(transitive)