forked from nz-Mark-Y/Hackfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.js
More file actions
61 lines (53 loc) · 1.81 KB
/
node.js
File metadata and controls
61 lines (53 loc) · 1.81 KB
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
var express = require('express');
var app = express();
var OAuth = require('oauth-request');
app.set('port', (process.env.PORT || 3000));// checks for environment variable port
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
app.get('/getdealsforlocation', function (req, res) {
var twitter = OAuth({
consumer: {
public: 'zyiAgV9Jbea1BSrpVPFl0w',
secret: 's-jcY90vXvG9UOx8pYE8g0WOosw'
}
});
twitter.setToken({
public: 'vfZcastyjgwkfXaDKtczSLY8JVBW943B',
secret: 'F8-P5ZsXTkhEH_brQfVdeZAPLDs'
});
//list user timeline
twitter.get('https://api.yelp.com/v2/search?cll='+ req.query.lat + ',' + req.query.lon +'&location=' + req.query.location + '&deals_filter=true&term=food&radius_filter='+req.query.radius_filter, function(err, thing, data) {
res.setHeader('Content-Type','application/json');
res.addHeader("Access-Control-Allow-Origin", "*");
if(err){
console.log(err);
}
var filteredData = filterData(JSON.parse(data))//(data);
res.send(filteredData);//data);
});
});
app.get('/hello', function(request, response) {
response.send('Hello World!')
});
function filterData(data) {
//console.log('data', data);
var filteredData = [];
if (data.length === 0) {
return filteredData;
}
var businesses = data.businesses;
businesses.map(function(business){
var newObject = {};
newObject.name = business.name;
newObject.deals = business.deals;
newObject.address = business.location.display_address;
newObject.coordinates = business.location.coordinate
filteredData.push(newObject);
});
return filteredData;
}
app.listen(app.get('port'), function () {//listens on allocated port
console.log('Example app listening on port ' + app.get('port') + '!');
});