export const OPENDATA_URL = 'http://opendata.bratislava.sk/api/mhd'; export default class BratislavaOpendata { constructor(apiKey) { this.apiKey = apiKey; } async fetchOneStop(stationStopId) { return this.request('/stationstop/' + stationStopId); } 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; } } }