diff --git a/Connectors/Strava/lib.js b/Connectors/Strava/lib.js new file mode 100644 index 000000000..c7df6d08f --- /dev/null +++ b/Connectors/Strava/lib.js @@ -0,0 +1,77 @@ +var fs = require('fs'), + url = require('url'), + express = require('express'), + connect = require('connect'), + request = require('request'), + sys = require('sys'); + +var athleteId = 27487; + +exports.rides = function(callback, startDate, endDate) { + if(startDate && !startDate.match(/\d{4}\-\d{2}\-\d{2}/)) { + callback("startDate must be in the format of YYYY-MM-DD"); + return; + } + if(endDate && !endDate.match(/\d{4}\-\d{2}\-\d{2}/)) { + callback("endDate must be in the format of YYYY-MM-DD"); + return; + } + + //create data directory, if it doesn't exist + try { + fs.lstatSync("data"); + } catch(e) { + fs.mkdirSync("data", "0777"); + console.log("Created data directory."); + } + + //go check + request({ + uri:"http://www.strava.com/api/v1/rides?athleteId="+athleteId+(startDate ? "&startDate="+startDate : "")+(endDate ? "&endDate="+endDate : ""), + json: true, + }, function(error, response, body) { + if (!error && response.statusCode == 200) { + for(var i=0; icontinue"); +}); + +app.get('/info', function(req, res) { + res.writeHead(200); + dapp.getAccountInfo(function (err, data) { + if (err) res.end('Error: ' + err) + else res.end(data.display_name + ', ' + data.email) + }); +}); + +app.get('/save', function(req, res) { + if(!req.param('file')){ + res.writeHead(400); + res.end('whats the file yo?'); + return; + } + console.log("saving "+req.param('file') ); + res.writeHead(200); + res.end("ok, background uploading..."); + dapp.putFile(req.param('file'), '', function (err, data) { + if (err) + console.log("failed: "+err); + else + console.log("saved!"); + }); +}); + + +var stdin = process.openStdin(); +stdin.setEncoding('utf8'); +stdin.on('data', function (chunk) { + var processInfo = JSON.parse(chunk); + locker.initClient(processInfo); + process.chdir(processInfo.workingDirectory); + lfs.readObjectFromFile('auth.json', function(auth) { + if(auth.token) dapp = new dbox(auth.key, auth.ksecret, auth.token, auth.tsecret); + app.listen(processInfo.port,function() { + var returnedInfo = {port: processInfo.port}; + console.log(JSON.stringify(returnedInfo)); + }); + }); + +}); diff --git a/Connectors/Strava/test.js b/Connectors/Strava/test.js new file mode 100644 index 000000000..dffac29d7 --- /dev/null +++ b/Connectors/Strava/test.js @@ -0,0 +1,3 @@ +var s=require("./lib"); +console.log("loaded, calling rides"); +s.rides( function(a){ console.log(a) }); diff --git a/Connectors/Strava/ui/index.html b/Connectors/Strava/ui/index.html new file mode 100644 index 000000000..e4222da5f --- /dev/null +++ b/Connectors/Strava/ui/index.html @@ -0,0 +1,4 @@ + +

Strava is connected :)

+

info check + diff --git a/Connectors/Strava/ui/init.html b/Connectors/Strava/ui/init.html new file mode 100644 index 000000000..753d152f1 --- /dev/null +++ b/Connectors/Strava/ui/init.html @@ -0,0 +1,6 @@ + +

Locker needs to know your athlete ID. To find it, click the Profile link from the Strava dashboard.

+
+ Enter your athlete ID:
+ +