UNPKG

tickethead-sdk

Version:

SDK for the Tickethead API

121 lines 5.4 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AggregatorService = void 0; const query_string_1 = __importDefault(require("query-string")); const query_1 = require("../common/query"); class AggregatorService { constructor(client, version) { this.client = client; this.version = version; } /** * Returns true if the service is reachable * * @returns Services' online status */ health() { return __awaiter(this, void 0, void 0, function* () { try { const res = yield this.client.get(`/health`); if (res.data.status === 'ok') { return { online: true }; } } catch (e) { // Do nothing } return { online: false }; }); } /** * Returns a list of active events. * * @param req.q String value for text-based search on event * @param req.start_at Date range where the event start_at field is filtered * @param req.include_occurrences If true, in case of recurring events it includes occurrences * @param req.with Field selector query attribute * @returns */ listEvents() { return __awaiter(this, arguments, void 0, function* (req = {}) { var _a; let queryWith = undefined; if (req.with) { queryWith = (0, query_1.buildQuery)(req.with); } let queryStartAt = undefined; if (((_a = req.start_at) === null || _a === void 0 ? void 0 : _a.length) === 2 && req.start_at[0] instanceof Date && req.start_at[1] instanceof Date) { queryStartAt = `${req.start_at[0].toISOString()};${req.start_at[1].toISOString()}`; } const query = query_string_1.default.stringify(Object.assign(Object.assign({}, req), { q: req.query, public: true, with: queryWith, start_at: queryStartAt, query: undefined }), { arrayFormat: 'comma', skipNull: true, skipEmptyString: true }); const res = yield this.client.get(`${this.version}/event?${query}`); return res.data; }); } /** * Returns a list of external events. * * @param req.sort String value for sorting external events * @param req.query Textual query to find products that match the query * @param req.lat Filters the result set by latitude. Requires lng to be set as well * @param req.lng Filters the result set by longitude. Requires lat to be set as well * @param req.max_distance Maximum distance in km from the lat/lng coordinates * @param req.page Number of the page to retrieve * @param req.page_size Number of items per page. Default value is 10 * @param req.near_ip When set, events near the IP address will be returned. Overrides lat/lng * @param req.near_me When set, events near the callers IP address will be returned. Overrides lat/lng and near_ip */ listExternalEvents() { return __awaiter(this, arguments, void 0, function* (req = {}) { const query = query_string_1.default.stringify(req, { arrayFormat: 'comma', skipNull: true, skipEmptyString: true, }); const res = yield this.client.get(`${this.version}/event/external?${query}`); return res.data.data; }); } /** * Returns queried external event * * @param req.id External event ID * @param req.provider The name of the external provider */ getExternalEvent(req) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`${this.version}/event/external/${req.provider}/${req.id}`); return res.data; }); } /** * Returns available categories */ listCategories() { return __awaiter(this, arguments, void 0, function* (req = {}) { let queryWith = undefined; if (req.with) { queryWith = (0, query_1.buildQuery)(req.with); } const query = query_string_1.default.stringify(Object.assign(Object.assign({}, req), { with: queryWith }), { arrayFormat: 'comma', skipNull: true, skipEmptyString: true }); const res = yield this.client.get(`${this.version}/category?${query}`); return res.data; }); } } exports.AggregatorService = AggregatorService; //# sourceMappingURL=service.js.map