-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGO.js
48 lines (43 loc) · 1.41 KB
/
GO.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
const url = require('./constants/endpoints.js')
const request = require('request');
const getStops = () => new Promise((res, rej) => {
request({url: url.BASE_URL + url.STOPS, json: true}, (error, response) => {
if(error) {
rej("Unable to get stops information: " + error)
} else {
res(response.body)
}
})
})
const getBuses = () => new Promise((res, rej) => {
request({url: url.BASE_URL + url.BUSES, json: true}, (error, response) => {
if(error) {
rej("Unable to get buses information: " + error)
} else {
res(response.body)
}
})
})
const getStopETA = (stopId, routeId, position) => new Promise((res, rej) => {
let finalUrl = url.BASE_URL + url.STOPS_ETA + "&stopIds=" + stopId + "&routeID=" + routeId + "&position=" + position
console.log(finalUrl)
request({url: finalUrl, json: true}, (error, response) => {
if(error) {
rej("Unable to get stop ETA information: " + error)
} else {
res(response.body)
}
})
})
const getRoutes = () => new Promise((res, rej) => {
request({url: url.BASE_URL + url.ROUTES, json: true}, (error, response) => {
if(error) {
rej("Unable to get Routes information: " + error)
} else {
res(response.body)
}
})
})
module.exports = {
getBuses, getRoutes, getStopETA, getStops
}