-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
133 lines (108 loc) · 3.51 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Generated by CoffeeScript 1.6.2
(function() {
var app, calendar, client, consumer, express, helpers, oauth, port, rkOptions, runkeeper;
express = require('express');
oauth = require('oauth');
helpers = require('./helpers').helpers;
app = express();
rkOptions = exports.options = {
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
auth_url: 'https://runkeeper.com/apps/authorize',
access_token_url: 'https://runkeeper.com/apps/token',
redirect_uri: 'http://uva.herokuapp.com/runkeeper_callback'
};
app.configure('development', function() {
return rkOptions.redirect_uri = 'http://localhost:3000/runkeeper_callback';
});
runkeeper = require(__dirname + '/runkeeper.js');
client = new runkeeper.HealthGraph(rkOptions);
calendar = require(__dirname + '/calendar_display.js');
consumer = function() {
return new oauth.OAuth2(rkOptions.client_id, rkOptions.client_secret, 'http://runkeeper.com', '/apps/authorize', '/apps/token');
};
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger());
app.use(express.bodyParser());
app.use(express.cookieParser());
return app.use(express["static"](__dirname + '/public'));
});
app.engine('jade', require('jade').__express);
app.configure('development', function() {
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
return app.use(express.session({
secret: 'sdofyi234oglkc@oydf'
}));
});
app.configure('production', function() {
app.use(express.errorHandler());
return app.use(express.session({
secret: 'sdofyi234oglkc@oydf'
}));
});
app.get('/', function(req, res) {
return res.render('index');
});
app.get('/runkeeper_login', function(req, res) {
var oa;
oa = consumer();
return res.redirect(oa.getAuthorizeUrl({
response_type: 'code',
redirect_uri: rkOptions.redirect_uri
}));
});
app.get('/runkeeper_callback', function(req, res) {
return client.getNewToken(req.param('code'), function(access_token) {
req.session.access_token = access_token;
client.access_token = access_token;
return res.redirect('/calendar');
});
});
app.get('/calendar', function(req, res) {
var errors;
if (!req.session.access_token) {
res.redirect('/');
return;
}
errors = [];
return client.profile(function(profile) {
var error, fitnessActivities, profileInfo;
fitnessActivities = [];
profileInfo = {};
try {
profileInfo = JSON.parse(profile);
} catch (_error) {
error = _error;
errors.push(error);
}
return client.fitnessActivityFeed(function(activities) {
var calDisplay;
try {
fitnessActivities = JSON.parse(activities)['items'];
calDisplay = new calendar.CalendarDisplay(fitnessActivities);
} catch (_error) {
error = _error;
console.log(error);
errors.push(error);
}
return res.render('calendar', {
title: 'calendar data!',
user: profileInfo,
activities: calDisplay.activitiesByMonth(),
calData: calDisplay.getElts(),
errors: errors,
h: helpers
});
});
});
});
port = process.env.PORT || 3000;
app.listen(port, function() {
return console.log("Express server listening on port %d in %s mode", port, app.settings.env);
});
}).call(this);