forked from apis-is/apis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
deb5950
commit 1d122db
Showing
25 changed files
with
226 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
.DS_Store | ||
.gitignore | ||
node_modules | ||
endpoints/sms.js | ||
endpoints/phone.js | ||
endpoints/phone2.js | ||
endpoints/phone | ||
endpoints/sms | ||
endpoints/closed_endpoints | ||
index.php | ||
docs | ||
config/*.config.json | ||
repos | ||
config/*.config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"host": "localhost", | ||
"port": 3100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,7 @@ | ||
var request = require('request'); | ||
var h = require('../../lib/helpers.js'); | ||
var request = require('request'), | ||
h = require('../../lib/helpers.js'), | ||
app = require('../../server'); | ||
|
||
exports.setup = function(server){ | ||
server.post({path: '/bus/search', version: '1.0.0'}, search); | ||
} | ||
|
||
var search = function(req, res, next) { | ||
res.header("Access-Control-Allow-Origin", "*"); | ||
res.header("Access-Control-Allow-Headers", "X-Requested-With"); | ||
res.json(404,{error:"This api endpoint has been closed temporarily, because Bus.is changed it's markup."}); | ||
return next(); | ||
} | ||
|
||
realtime = function(req, res, next){ | ||
res.header("Access-Control-Allow-Origin", "*"); | ||
res.header("Access-Control-Allow-Headers", "X-Requested-With"); | ||
|
||
var data = req.params; | ||
|
||
request('http://straeto.is/bitar/bus/livemap/json.jsp', function (error, response, body) { | ||
if(error) { | ||
res.json(500,{error:'Something went wrong',code:3}); | ||
return next(); | ||
} | ||
if(response.statusCode !== 200){ | ||
res.json(500,{error:"Something went wrong code 1",code:4}); | ||
return next(); | ||
} | ||
|
||
try{ | ||
obj = JSON.parse(body); | ||
}catch(error){ | ||
res.json(500,{error:"Something is wrong with the data provided from the data source"}); | ||
return next(); | ||
} | ||
|
||
var activeBusses = [], | ||
requestedBusses = []; | ||
|
||
obj.routes.forEach(function(object, key){ | ||
activeBusses.push(object.id); | ||
}); | ||
|
||
if(data.busses){ //Post busses = 1,2,3,4,5 | ||
requestedBusses = data.busses.split(","); | ||
|
||
for(var i in requestedBusses){ //Prevent requested to busses that are not available | ||
if(activeBusses.indexOf(requestedBusses[i]) == -1){ | ||
requestedBusses.splice(requestedBusses.indexOf(requestedBusses[i]),1); | ||
} | ||
} | ||
}else{ | ||
//No bus was posted, use all active busses | ||
requestedBusses = activeBusses; | ||
} | ||
|
||
objString = requestedBusses.join('%2C'); | ||
|
||
request('http://straeto.is/bitar/bus/livemap/json.jsp?routes='+objString, function (error, response, body) { | ||
|
||
if(error) { | ||
res.json(500,{error:'Something went wrong',code:3}); | ||
return next(); | ||
} | ||
if(response.statusCode !== 200){ | ||
res.json(500,{error:"Something went wrong code 1",code:4}); | ||
return next(); | ||
} | ||
|
||
var data = JSON.parse(body), | ||
routes = data.routes; | ||
|
||
var objRoutes = { | ||
results: [] | ||
}; | ||
routes.forEach(function(route, key){ | ||
|
||
var objRoute = { | ||
busNr: route.id, | ||
busses: [] | ||
}; | ||
route.busses.forEach(function(bus, key){ | ||
|
||
var location = h.ISN93_To_WGS84(bus.X,bus.Y), | ||
oneRoute = { | ||
'unixTime': Date.parse(bus.TIMESTAMPREAL)/1000, | ||
'x': location.lat, | ||
'y': location.lng, | ||
'from': bus.FROMSTOP, | ||
'to': bus.TOSTOP | ||
}; | ||
objRoute.busses.push(oneRoute); | ||
|
||
}); | ||
|
||
objRoutes.results.push(objRoute); | ||
}); | ||
|
||
res.json(200,objRoutes) | ||
return next(); | ||
}); | ||
}); | ||
} | ||
app.post('/bus/search', function(req, res) { | ||
return res.json(404,{error:"This api endpoint has been closed, because Bus.is changed it's markup."}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
app.post({path: '/bus/search', version: '1.0.0'}, function(req,res){ | ||
res.inactive(error: 'This api endpoint has been closed temporarily, because Bus.is changed it's markup.'); | ||
}); //Old | ||
app.get({path: '/bus/search', version: '1.0.0'}, function(req,res){ | ||
res.inactive(error: 'This api endpoint has been closed temporarily, because Bus.is changed it's markup.'); | ||
}); | ||
var app = require('../../server'); | ||
|
||
var search = function(req, res, next) { | ||
res.json(404,{error:"This api endpoint has been closed temporarily, because Bus.is changed it's markup."}); | ||
return next(); | ||
} | ||
app.post('/bus/search', function(req,res){ | ||
res.json(404,{error: 'This api endpoint has been closed temporarily, because Bus.is changed it\'s markup.'}); | ||
}); //Old | ||
app.get('/bus/search', function(req,res){ | ||
res.json(404,{error: 'This api endpoint has been closed temporarily, because Bus.is changed it\'s markup.'}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.