UNPKG

mobility-toolbox-js

Version:

Toolbox for JavaScript applications in the domains of mobility and logistics.

56 lines (55 loc) 1.74 kB
import HttpAPI from './HttpAPI'; /** * This class provides convenience methods to use to the [geOps Realtime REST API](https://developer.geops.io/apis/realtime/). * For the websocket see {@link RealtimeAPI}. * * @example * import { RealtimeRestAPI } from 'mobility-toolbox-js/api'; * * const api = new RealtimeRestAPI({ * apiKey: [yourApiKey], * tenant: 'trenord', * // url: 'https://api.geops.io/tracker-http/v1/', * }); * * const feeds = await api.feeds(); * * console.log('Log feeds:', JSON.stringify(feeds)); * */ class RealtimeRestAPI extends HttpAPI { /** * Constructor * * @param {Object} options Options. * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/). * @param {string} [options.url='https://api.geops.io/tracker-http/v1/'] Url of the [geOps stops API](https://developer.geops.io/apis/realtime/). */ constructor(options = {}) { super(Object.assign(Object.assign({}, options), { url: options.url || 'https://api.geops.io/tracker-http/v1/' })); if (options.tenant) { this.tenant = options.tenant; } } /** * Get list of feeds. */ feeds(params = {}, config) { return this.fetch('feeds/', params, config); } /** * Search for trains by route identifier. */ trainsByRouteIdentifier(params = { exact_match: true, }, config) { return this.fetch(`trains_by_route_identifier/${this.tenant}/`, params, config); } /** * Get trajectories for a tenant. */ trajectories(params = {}, config) { return this.fetch(`trajectories/${this.tenant}/`, params, config); } } export default RealtimeRestAPI;