initial commit

This commit is contained in:
2022-06-28 13:02:50 +02:00
commit a4e6b655b7
16 changed files with 7870 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
export const OPENDATA_URL = 'http://opendata.bratislava.sk/api/mhd';
export default class BratislavaOpendata {
constructor(apiKey) {
this.apiKey = apiKey;
}
async fetchOneStop(stationId) {
return this.request('/stationstop/' + stationId);
}
async fetchAllStops() {
return this.request('/stationstop');
}
async fetchAllVehicles() {
return this.request('/vehicle');
}
async request(uri) {
let url = OPENDATA_URL + '/' + uri;
let resp = await fetch(url, {
cache: 'no-cache',
headers: {
'User-Agent': 'node_mhdmap/1.0',
'Key': this.apiKey,
},
});
if (!resp.ok) {
console.warn('Error while fetching', url, 'status:', resp.status, resp.statusText);
return null;
}
try {
resp = await resp.json();
return resp;
} catch (e) {
console.warn('Incorrect response for fetching', url, e);
return null;
}
}
}