angular-kladr
Version:
Angular 4+ package for better experience using kladr api service
207 lines (195 loc) • 5.8 kB
JavaScript
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientJsonpModule, HttpClientModule } from '@angular/common/http';
import { Jsonp, JsonpModule } from '@angular/http';
import { map } from 'rxjs/operators';
import { InjectionToken, Injectable, Inject, NgModule, defineInjectable, inject } from '@angular/core';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {string} */
var KladrContentType = {
region: 'region',
district: 'district',
city: 'city',
street: 'street',
building: 'building',
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {number} */
var KladrWithParent = {
/**
* Выдача с родительскими объектами
* @type {number}
*/
with: 1,
/**
* Выдача без родительских объектов
* @type {number}
*/
without: 0,
};
KladrWithParent[KladrWithParent.with] = 'with';
KladrWithParent[KladrWithParent.without] = 'without';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {number} */
var KladrCodeType = {
/**
* города
* @type {number}
*/
cities: 1,
/**
* поселки
* @type {number}
*/
townships: 2,
/**
* деревни
* @type {number}
*/
villages: 4,
};
KladrCodeType[KladrCodeType.cities] = 'cities';
KladrCodeType[KladrCodeType.townships] = 'townships';
KladrCodeType[KladrCodeType.villages] = 'villages';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {number} */
var KladrOneString = {
true: 1,
false: 0,
};
KladrOneString[KladrOneString.true] = 'true';
KladrOneString[KladrOneString.false] = 'false';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @type {?} */
var KLADR_OPTIONS = new InjectionToken('KLADR_OPTIONS');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var Options = /** @class */ (function () {
function Options() {
this.isSecure = false;
}
return Options;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var KladrService = /** @class */ (function () {
function KladrService(jsonp, options) {
this.jsonp = jsonp;
this.options = options;
this.baseUrl = 'kladr-api.ru/api.php';
this.HTTP = 'http://';
this.HTTPS = 'https://';
this.url = options.isSecure ? this.HTTPS + this.baseUrl : this.HTTP + this.baseUrl;
}
/**
* Makes api request
* @param query of type KladrRequestParams
* @returns Observable<KladrResponse> Observable with received data or error message
*/
/**
* Makes api request
* @param {?} query of type KladrRequestParams
* @return {?} Observable<KladrResponse> Observable with received data or error message
*/
KladrService.prototype.api = /**
* Makes api request
* @param {?} query of type KladrRequestParams
* @return {?} Observable<KladrResponse> Observable with received data or error message
*/
function (query) {
/** @type {?} */
var apiUrl = this.url + '?';
Object.keys(query).forEach(function (key) {
apiUrl += key + "=" + query[key] + "&";
});
apiUrl += 'callback=JSONP_CALLBACK';
return this.jsonp.request(apiUrl).pipe(map(function (response) {
return (/** @type {?} */ (response.json())) || response.json();
}));
};
KladrService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
KladrService.ctorParameters = function () { return [
{ type: Jsonp },
{ type: Options, decorators: [{ type: Inject, args: [KLADR_OPTIONS,] }] }
]; };
/** @nocollapse */ KladrService.ngInjectableDef = defineInjectable({ factory: function KladrService_Factory() { return new KladrService(inject(Jsonp), inject(KLADR_OPTIONS)); }, token: KladrService, providedIn: "root" });
return KladrService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var KladrModule = /** @class */ (function () {
function KladrModule() {
}
/**
* @param {?=} options
* @return {?}
*/
KladrModule.forRoot = /**
* @param {?=} options
* @return {?}
*/
function (options) {
if (options === void 0) { options = undefined; }
return {
providers: [
{
provide: KLADR_OPTIONS,
useValue: options
}
],
ngModule: KladrModule
};
};
KladrModule.decorators = [
{ type: NgModule, args: [{
declarations: [],
imports: [
CommonModule,
BrowserModule,
JsonpModule,
HttpClientJsonpModule,
HttpClientModule
],
providers: [
KladrService
]
},] }
];
return KladrModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
export { KladrContentType, KladrWithParent, KladrCodeType, KladrOneString, KladrModule, KladrService, Options, KLADR_OPTIONS };
//# sourceMappingURL=angular-kladr.js.map