sygic-custom-url
Version:
330 lines • 10.8 kB
JavaScript
export var ACTION_TYPE = {
DRIVE: "drive",
SHOW: "show",
WALK: "walk"
};
export var ACTION = {
ACTIVATE: "activate",
ADDRESS: "address",
BACK_BUTTON: "back_button",
COORDINATE: "coordinate",
COORDINATEADDR: "coordinateaddr",
DEVICECODE: "deviceCode",
GPSLOG: "gpslog",
LOGIN: "login",
MYSYGIC: "mysygic",
MYSYGICBUY: "mysygicbuy",
MYSYGICPRODUCT: "mysygicproduct",
RESTORE: "restore",
ROUTE: "route",
SETTINGSOVERWRITE: "settingsOverwrite",
TRUCKSETTINGS: "truckSettings",
UPDATE: "update",
URL: "url"
};
export var TRUCK_ROUTING_TYPE = {
CAMPER: "cmp",
CAR: "car",
TRUCK: "tru",
VAN: "van"
};
export var SCHEME = "com.sygic.aura";
export var ACTIONS_SEPARATOR = "&&&";
export var OPTIONS_SEPARATOR = "|";
export var TRUCK_SETTINGS_SEPARATOR = "&";
/**
* Service that creates sygic custom urls
*/
var CustomUrlService = /** @class */ (function () {
function CustomUrlService() {
}
/**
* Get url to show address on map
*
* @param {string} country Country or iso code.
* @param {string} city City.
* @param {string} postal Postal code.
* @param {string} street Street.
* @param {string} houseNumber House number.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.showAddress = function (country, city, postal, street, houseNumber) {
return this.genCustomUrl(ACTION.ADDRESS, country, city, postal, street, houseNumber, ACTION_TYPE.SHOW);
};
/**
* Get url to drive to an address
*
* @param {string} country Country or iso code.
* @param {string} city City.
* @param {string} postal Postal code.
* @param {string} street Street.
* @param {string} houseNumber House number.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.driveAddress = function (country, city, postal, street, houseNumber) {
return this.genCustomUrl(ACTION.ADDRESS, country, city, postal, street, houseNumber, ACTION_TYPE.DRIVE);
};
/**
* Get url to walk to an address
*
* @param {string} country Country or iso code.
* @param {string} city City.
* @param {string} postal Postal code.
* @param {string} street Street.
* @param {string} houseNumber House number.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.walkAddress = function (country, city, postal, street, houseNumber) {
return this.genCustomUrl(ACTION.ADDRESS, country, city, postal, street, houseNumber, ACTION_TYPE.WALK);
};
/**
* Show coordinates on map
* @param {number} lon Longitude.
* @param {number} lat Latitude
*
* @returns {string} Url;
*/
CustomUrlService.prototype.showCoordinates = function (lon, lat) {
return this.genCustomUrl(ACTION.COORDINATE, lon, lat, ACTION_TYPE.SHOW);
};
/**
* Drive to coordinates
* @param {number} lon Longitude.
* @param {number} lat Latitude
*
* @returns {string} Url;
*/
CustomUrlService.prototype.driveCoordinates = function (lon, lat) {
return this.genCustomUrl(ACTION.COORDINATE, lon, lat, ACTION_TYPE.DRIVE);
};
/**
* Walk to coordinates
* @param {number} lon Longitude.
* @param {number} lat Latitude
*
* @returns {string} Url;
*/
CustomUrlService.prototype.walkCoordinates = function (lon, lat) {
return this.genCustomUrl(ACTION.COORDINATE, lon, lat, ACTION_TYPE.WALK);
};
/**
* Drive to coordinates with defining address description
* @param {number} lon Longitude.
* @param {number} lat Latitude
* @param {string} desc Description.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.driveCoordinateaddr = function (lon, lat, desc) {
return this.genCustomUrl(ACTION.COORDINATEADDR, lon, lat, desc, ACTION_TYPE.DRIVE);
};
/**
* Loads json itinerary
* @param {string} route sif or json
*
* @returns {string} Url;
*/
CustomUrlService.prototype.route = function (route) {
return this.genCustomUrl(ACTION.ROUTE, route);
};
/**
* opens web page directly in navigation
* @param {string} webpage Page to open.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.url = function (webpage) {
return this.genCustomUrl(ACTION.URL, webpage);
};
/**
* activate license with product code
* @param {string} productCode Product code
*
* @returns {string} Url;
*/
CustomUrlService.prototype.activate = function (productCode) {
return this.genCustomUrl(ACTION.ACTIVATE, productCode);
};
/**
* Start navigation and login with username
*
* @param {string} user User name.
* @param {password} password Password.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.login = function (user, password) {
return this.genCustomUrl(ACTION.LOGIN, user, password);
};
/**
* Update specific map or all maps.
* Note: the call starts downloading maps immediately
* but removes old maps with the application restart.
* This means that at the certain moment both maps
* are present in your filesystem, so your memory limits
* can be hit.
* @param {string} map Map to update or all.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.update = function (map) {
return this.genCustomUrl(ACTION.UPDATE, map);
};
/**
* Show sygic products' shop.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.mysygic = function () {
return this.genCustomUrl(ACTION.MYSYGIC);
};
/**
* Show product detail from shop.
*
* @param productId Product id.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.mysygicproduct = function (productId) {
return this.genCustomUrl(ACTION.MYSYGICPRODUCT, productId);
};
/**
* Buy a license for a product
*
* @param {string} productId Product id.
*
* @returns {string} Url;
*/
CustomUrlService.prototype.mysygicbuy = function (productId) {
return this.genCustomUrl(ACTION.MYSYGICBUY, productId);
};
/**
* Restore all purchases
*
*
* @returns {string} Url;
*/
CustomUrlService.prototype.restore = function () {
return this.genCustomUrl(ACTION.RESTORE);
};
/**
* Play gps nmea log from Res/gpslog
*
* @param {string} nmeafile
* @returns {string} Url;
*/
CustomUrlService.prototype.gpslog = function (nmeafile) {
return this.genCustomUrl(ACTION.GPSLOG, nmeafile);
};
/**
* Control truck settings
* @param {ITruckSettings} truckSettings Truck settings
* @returns {string} Url;
*/
CustomUrlService.prototype.truckSettings = function (truckSettings) {
var options = Object.keys(truckSettings)
.map(function (key) { return key + "=" + truckSettings[key]; })
.join(TRUCK_SETTINGS_SEPARATOR);
return this.genCustomUrl(ACTION.TRUCKSETTINGS, options);
};
/**
* Define back button behavior
* @param {string} applicationIdentifier
* @returns {string} Url;
*/
CustomUrlService.prototype.backButton = function (applicationIdentifier) {
return this.genCustomUrl(ACTION.BACK_BUTTON, applicationIdentifier);
};
/**
* Overwrite app settings.
*
* @param {string} filePath File path of settings.
* @returns {string} Url;
*/
CustomUrlService.prototype.settingsOverwrite = function (filePath) {
return this.genCustomUrl(ACTION.SETTINGSOVERWRITE, encodeURIComponent(filePath));
};
/**
* Get device code
*
* @returns {string} Url;
*/
CustomUrlService.prototype.deviceCode = function () {
return this.genCustomUrl(ACTION.DEVICECODE);
};
CustomUrlService.prototype.multipleActions = function (actions) {
var path = this.prepareActions(actions);
return this.getCustomUrl(path);
};
/**
* Generates a sygic custom url for given action and options.
*
* @param {action} action Url action
* @param {any} args Options for action
*
* @returns {string} Url;
*/
CustomUrlService.prototype.genCustomUrl = function (action) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
var options = this.prepareAction.apply(this, [action].concat(args));
return this.getCustomUrl(options);
};
/**
* Get custom url for path.
* @param {string} path Path of URL.
* @returns {string} Url;
*/
CustomUrlService.prototype.getCustomUrl = function (path) {
return SCHEME + "://" + path;
};
/**
* Prepare multiple actions
*
* @param {{ACTION, any[]}[]} actions Actions to prepare
* @returns {string} Actions prepared for custom url
*/
CustomUrlService.prototype.prepareActions = function (actions) {
var _this = this;
return actions
.map(function (_a) {
var action = _a.action, args = _a.args;
return _this.prepareAction.apply(_this, [action].concat(args));
})
.join(ACTIONS_SEPARATOR);
};
/**
* Prepare action for url;
*
* @param {ACTION} action Url action.
* @param {any[]} args Args for custom url. including action.
* @returns {string} Args prepared for url.
*/
CustomUrlService.prototype.prepareAction = function (action) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
args.unshift(action);
return this.prepareOptions(args);
};
/**
* Prepare options for url;
*
* @param {any[]} args Args for custom url. including action.
* @returns {string} Args prepared for url.
*/
CustomUrlService.prototype.prepareOptions = function (args) {
return args
.filter(function (arg) { return arg !== null && arg !== undefined; })
.join(OPTIONS_SEPARATOR);
};
return CustomUrlService;
}());
export { CustomUrlService };
//# sourceMappingURL=sygic.custom.url.service.js.map