-
Notifications
You must be signed in to change notification settings - Fork 0
/
BusStop.ts
29 lines (25 loc) · 1.02 KB
/
BusStop.ts
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
import Bus from "./Bus";
import ArrivalResponseFormat from "./ArrivalDataFormat";
import ArrivalsParser from "./ArrivalsParser";
import nodeFetch from "node-fetch";
export default class BusStop {
private arrivals: Bus[] = [];
private id: string;
private indicator: string
private name: string;
constructor(id: string, indicator: string, name: string) {
this.id = id;
this.indicator = indicator;
this.name = name;
}
async updateArrivals(): Promise<void> {
const response = await nodeFetch(`https://api.tfl.gov.uk/StopPoint/${this.id}/Arrivals`);
const data: ArrivalResponseFormat[] = await response.json() as ArrivalResponseFormat[];
const parser: ArrivalsParser = new ArrivalsParser();
const arrivals = parser.GetBusesFromJSON(data).slice(0, 5);
this.arrivals = arrivals;
}
toString(){
return `${this.name} (${this.indicator}): \n` + this.arrivals.map((bus: Bus) => bus.toString()).join('\n') + '\n'
}
}