/
test.js
39 lines (31 loc) · 1.05 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var express = require('express');
var cookieParser = require('cookie-parser');
var app = express();
app.use(cookieParser('sess'));
var PORT = process.argv[5] || 8553;
var fitbitClient = require('../')(process.argv[2], process.argv[3],
'http://localhost:' + PORT, process.argv[4]);
var token;
app.get('/', function (req, res) {
fitbitClient.getAccessToken(req, res, function (error, newToken) {
if(newToken) {
token = newToken;
res.writeHead(200, {'Content-Type':'text/html'});
res.end('<html>Now <a href="/getStuff">get stuff</a></html>');
}
});
});
app.get('/getStuff', function (req, res) {
fitbitClient.apiCall('GET', '/user/-/profile.json',
{token: {oauth_token_secret: token.oauth_token_secret,
oauth_token: token.oauth_token}},
function(err, resp, json) {
if (err) return res.send(err, 500);
res.json(json);
});
});
app.get('/cookie', function(req, res) {
res.send('wahoo!');
});
app.listen(PORT);
console.log('listening at http://localhost:' + PORT + '/');