mobility-toolbox-js
Version:
Toolbox for JavaScript applications in the domains of mobility and logistics.
68 lines (67 loc) • 2.77 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import HttpAPI from './HttpAPI';
/**
* This class provides convenience methods to use to the [geOps MOCO API](https://geops.com/de/solution/disruption-information).
*
* @example
* import { MocoAPI } from 'mobility-toolbox-js/api';
*
* const api = new MocoAPI({
* // url: 'https://moco.geops.io/api/v2/',
* // tenant: "geopstest",
* });
*
* const notifications = await api.export();
*
* console.log('Log route:', JSON.stringify(notifications));
*
* @private
*/
class MocoAPI 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://moco.geops.io/api/v2/'] Service url.
* @param {string} [options.tenant='geopstest'] SSO config to get notifications from.
*/
constructor(options) {
super(Object.assign(Object.assign({}, options), { url: options.url || 'https://moco.geops.io/api/v2/' }));
this.tenant = 'geopstest';
if (options.tenant) {
this.tenant = options.tenant;
}
}
/**
* Get paginated situations.
*/
export() {
return __awaiter(this, arguments, void 0, function* (params = {}, config = {}) {
const response = yield this.fetch(`${this.tenant}/export/`, Object.assign({}, params), config);
return response;
});
}
/**
* Get a situation. Not all parameters are
* relevant, only the text related are useful
* (contentXXX, de, fr, it, en, includeXXX).
*/
exportById(id_1) {
return __awaiter(this, arguments, void 0, function* (id, params = {}, config = {}) {
var _a, _b;
const response = yield this.fetch(`${this.tenant}/export/${id}`, params, config);
return (_b = (_a = response === null || response === void 0 ? void 0 : response.paginatedSituations) === null || _a === void 0 ? void 0 : _a.results) === null || _b === void 0 ? void 0 : _b[0];
});
}
}
export default MocoAPI;