-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transantiago.js
48 lines (41 loc) · 1.27 KB
/
Transantiago.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 axios = require("axios");
class TransantiagoAPI {
constructor(options = {}) {
this.options = Object.assign(
{
baseURL: "http://www.transantiago.cl/",
timeout: 6000,
},
options
);
this.client = axios.create(this.options);
}
async getStopsNear(coordinates = {}) {
const latitude = coordinates.latitude || coordinates.lat;
const longitude = coordinates.longitude || coordinates.lng;
try {
const { data } = await this.client.get(`/restservice/rest/getpuntoparada?lat=${latitude}&lon=${longitude}&bip=1`);
return data || [];
} catch (e) {
return [];
}
}
async getStop(stop, service = "") {
const { data } = await this.client.get(`/predictor/prediccion?codsimt=${stop}&codser=${service}`);
data["valid"] = data["respuestaParadero"] !== "Paradero invalido.";
return data;
}
async getTour(tour) {
const { data } = await this.client.get(`/restservice/rest/getrecorrido/${tour}`);
return data;
}
async getTours() {
const { data } = await this.client.get(`/restservice/rest/getservicios/all`);
return data;
}
async getStops() {
const { data } = await this.client.get(`/restservice/rest/getparadas/all`);
return data;
}
}
module.exports = TransantiagoAPI;