@spasea/uz-booking-client
Version:
Unofficial UZ api client
60 lines (59 loc) • 2.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FirebaseTokenGenerator = require("firebase-token-generator");
const station_1 = require("./station");
const train_1 = require("./train");
const wagon_1 = require("./wagon");
const auth_1 = require("./auth");
class UZ {
/**
* Create a new UZ.
* @constructor
* @param {string} [lang=Language.EN] - language
* @param {string} [auth] - the credentials to authenticate to UzBooking. If auth token is
* not provided requests will be made unauthenticated
* @param {string} [fcmToken]
* @param userId
* @param {string} [deviceName]
* @param {string} [apiBase='https://app.uz.gov.ua'] - the base UzBooking API URL
*/
constructor(lang, auth, fcmToken, userId, deviceName = 'iPhone12.1', apiBase = 'https://app.uz.gov.ua') {
this.lang = lang;
this.apiBase = apiBase;
let _fcmToken = fcmToken;
if (!_fcmToken) {
const tokenGenerator = new FirebaseTokenGenerator('<YOUR_FIREBASE_SECRET>');
_fcmToken = tokenGenerator.createToken({ uid: '1', some: 'arbitrary', data: 'here' });
}
this.authClient = new auth_1.default(_fcmToken, deviceName, auth, userId, this.lang, this.apiBase);
}
/**
* Get Auth wrapper
* @returns {Auth}
*/
get Auth() {
return this.authClient;
}
/**
* Create a new Station wrapper
* @returns {Station}
*/
get Station() {
return new station_1.default(this.lang, this.authClient.accessToken, this.apiBase, this.authClient.userId);
}
/**
* Create a new Train wrapper
* @returns {Train}
*/
get Train() {
return new train_1.default(this.lang, this.authClient.accessToken, this.apiBase, this.authClient.userId);
}
/**
* Create a new Wagon wrapper
* @returns {Wagon}
*/
get Wagon() {
return new wagon_1.default(this.lang, this.authClient.accessToken, this.apiBase, this.authClient.userId);
}
}
exports.default = UZ;