events and weather

This commit is contained in:
martind2000 2017-04-18 10:06:39 +01:00
parent 996c2d6d1f
commit ca1b7b15da
6 changed files with 34 additions and 14 deletions

1
.gitignore vendored
View File

@ -188,3 +188,4 @@ node_modules
/libpeerconnection.log
npm-debug.log
testem.log
/lib/newdata.json

View File

@ -7,7 +7,7 @@
*/
(function($) {
var TodayDataModel = Backbone.Model.extend({
let TodayDataModel = Backbone.Model.extend({
initialize: function() {
this.set('url', '/today/data');
@ -17,15 +17,15 @@
});
var webSocketModel = new SOCKETMANAGER();
const webSocketModel = new SOCKETMANAGER();
webSocketModel.turnOn();
var clock = new Clock({model: new ClockModel()});
var weatherModel = new WeatherModel({lat: 55.95, long: -4.5666667});
var weather = new Weather({model: weatherModel});
window.clock = new Clock({model: new ClockModel()});
let weatherModel = new WeatherModel({geo:{coords:{latitude: 55.95, longitude: -4.5666667}}});
window.weather = new Weather({model: weatherModel});
var trainModel = new TrainModel();
var train = new Train({model: trainModel});
let trainModel = new TrainModel({from:'hym', to:'dbe'});
window.train = new Train({model: trainModel});
webSocketModel.setWeather(weatherModel);
webSocketModel.setTrain(trainModel);
@ -36,3 +36,4 @@
}, 500);
})(jQuery);

View File

@ -2,13 +2,14 @@ var WEBSOCKET = function(model) {
var wsUrl = ['localhost','silvrtree.co.uk'];
var wsPort = '9000';
let useUrl = 0;
if ('https:' === document.location.protocol) {
wsUrl = 'wss://' + wsUrl[1] + '';
wsUrl = 'wss://' + wsUrl[useUrl] + '';
wsPort = '';
} else {
//wsUrl = 'ws://localhost:3001';
wsUrl = 'ws://' + wsUrl[1] + '';
wsUrl = 'ws://' + wsUrl[useUrl] + '';
wsPort = '';
}

View File

@ -12,7 +12,7 @@
"tokenPath": "/oauth2/token"
},
"authorization_uri": {
"redirect_uri": "http://www.silvrtree.co.uk/fitbit_auth_callback/",
"redirect_uri": "https://www.silvrtree.co.uk/fitbit_auth_callback/",
"response_type": "code",
"scope": "activity nutrition profile settings sleep social weight heartrate",
"state": "3(#0/!~"

File diff suppressed because one or more lines are too long

View File

@ -35,7 +35,7 @@ today.setEmitter(busEmitter);
// train = require('lib/train')
/* ,submit = require('./routes/mongo/submit') */
;
let fs = require('fs');
const config = require('./config/config.json');
@ -148,7 +148,6 @@ const tfile = 'fb-token.json';
//
/*
const fitbit = new Fitbit(config.fitbit);
// In a browser, http://localhost:4000/fitbit to authorize a user for the first time.
@ -157,6 +156,24 @@ 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",
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.
@ -180,6 +197,7 @@ app.get('/fitbit_auth_callback', function(req, res, next) {
});
});
jsonfile.readFile('./fb-token.json', function(err, obj) {
if (err) {
logger.error(err);
@ -187,7 +205,6 @@ jsonfile.readFile('./fb-token.json', function(err, obj) {
fitbit.setToken(obj);
}
});
*/
// });