fitbit updates
This commit is contained in:
parent
248c23de04
commit
45a8800cf1
@ -17,7 +17,7 @@ const weather = require('./today/weather');
|
||||
const trains = require('./today/trains');
|
||||
const history = require('./today/history');
|
||||
const mdMailer = require('./today/mailer');
|
||||
// const mdFitbit = require('./today/fitbit');
|
||||
const mdFitbit = require('./today/fitbit');
|
||||
const todayFTSE = require('./today/todayftse');
|
||||
const quotes = require('./today/quotes');
|
||||
//var db_name = 'silvrgit';
|
||||
@ -389,14 +389,14 @@ module.exports = {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
/*mdFitbit.getYesterdayFitbit()
|
||||
mdFitbit.getYesterdayFitbit()
|
||||
.then((d) => {
|
||||
todayCache.data.fitbit = d;
|
||||
})
|
||||
.catch((e) => {
|
||||
'use strict';
|
||||
console.error(e);
|
||||
});*/
|
||||
});
|
||||
|
||||
todayCache.date = breakDay();
|
||||
}, broadcast: function () {
|
||||
|
@ -1,21 +1,20 @@
|
||||
var jsonfile = require('jsonfile');
|
||||
var config = require('../../config/config.json');
|
||||
var Fitbit = require('fitbit-oauth2');
|
||||
var dateFormat = require('dateformat');
|
||||
const jsonfile = require('jsonfile');
|
||||
const config = require('../../config/config.json');
|
||||
const Fitbit = require('fitbit-oauth2');
|
||||
|
||||
var logger = require('log4js').getLogger();
|
||||
const logger = require('log4js').getLogger();
|
||||
|
||||
require('sugar-date');
|
||||
|
||||
var fitbit = new Fitbit(config.fitbit);
|
||||
var tokenFile = 'fb-token.json';
|
||||
const fitbit = new Fitbit(config.fitbit);
|
||||
const tokenFile = 'fb-token.json';
|
||||
|
||||
module.exports = {
|
||||
|
||||
getYesterdayFitbit: function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var yesterday = Date.create('yesterday').format('{yyyy}-{MM}-{dd}');
|
||||
var url = 'https://api.fitbit.com/1/user/-/activities/date/' + yesterday +'.json';
|
||||
const yesterday = Date.create('yesterday').format('{yyyy}-{MM}-{dd}');
|
||||
const url = 'https://api.fitbit.com/1/user/-/activities/date/' + yesterday + '.json';
|
||||
|
||||
logger.info('Getting fitbit for: ', yesterday);
|
||||
logger.debug(url);
|
||||
@ -26,7 +25,7 @@ logger.info('Getting fitbit for: ', yesterday);
|
||||
if ( err ) {
|
||||
return reject(err);
|
||||
}
|
||||
var profile = JSON.parse( body );
|
||||
const profile = JSON.parse(body);
|
||||
// if token is not null, a refesh has happened and we need to persist the new token
|
||||
if ( token )
|
||||
jsonfile.writeFile(tokenFile, token, function( err ) {
|
||||
|
@ -156,6 +156,7 @@ app.get('/fitbit', function(req, res) {
|
||||
res.redirect(fitbit.authorizeURL());
|
||||
});
|
||||
|
||||
|
||||
app.get( '/fb-profile', function( req, res, next ) {
|
||||
fitbit.request({
|
||||
uri: "https://api.fitbit.com/1/user/-/profile.json",
|
||||
@ -174,6 +175,27 @@ app.get( '/fb-profile', function( req, res, next ) {
|
||||
});
|
||||
});
|
||||
|
||||
app.get( '/fb-today', function( req, res, next ) {
|
||||
const today = Date.create('today').format('{yyyy}-{MM}-{dd}');
|
||||
const url = 'https://api.fitbit.com/1/user/-/activities/date/' + today + '.json';
|
||||
|
||||
fitbit.request({
|
||||
uri: url,
|
||||
method: 'GET',
|
||||
}, function( err, body, token ) {
|
||||
if ( err ) return next( err );
|
||||
var profile = JSON.parse( body );
|
||||
// if token is not null, a refesh has happened and we need to persist the new token
|
||||
if ( token )
|
||||
persist.write( tfile, token, function( err ) {
|
||||
if ( err ) return next( err );
|
||||
res.send( '<pre>' + JSON.stringify( profile, null, 2 ) + '</pre>' );
|
||||
});
|
||||
else
|
||||
res.send( '<pre>' + JSON.stringify( profile, null, 2 ) + '</pre>' );
|
||||
});
|
||||
});
|
||||
|
||||
// Callback service parsing the authorization token and asking for the access token. This
|
||||
// endpoint is refered to in config.fitbit.authorization_uri.redirect_uri. See example
|
||||
// config below.
|
||||
|
Loading…
Reference in New Issue
Block a user