UNPKG

@uex/web-extensions

Version:

## Installation

70 lines (69 loc) 2.48 kB
import { Http, Headers, RequestMethod, RequestOptions } from '@angular/http'; import 'rxjs/add/operator/timeout'; import { ToastService } from '../../toast/toast.service'; export declare abstract class BaseModel { private http; private toastService; constructor(http: Http, toastService: ToastService); url: string; path: string; timeout: number; buildResource(resource_params: ResourceParams): Resource; getPath(resource_params: ResourceParams): ResourcePath; parseResourcePath(resource_path: ResourcePath, request_params: RequestParams): string; headerInterceptor(headers: any, resource_params: ResourceParams, request_params: RequestParams): Headers; clearSession(): void; private getOptions(resource_params, request_params); private getHeaders(resource_params, request_params); private getLogoutOnUnauthorized(resource_params, request_params); private setParams(params, request_params, prefix?); private findParamsKey(params, key_arr, ignore_from_payload); private setResourceParamsDefaults(resource_params); private handleSuccess(response, cache_info, responseInterceptor?); private handleError(err, cache_info, logout_on_unauthorized, responseInterceptor?); } export declare type Resource = (request_params?: RequestParams, ...args: any[]) => Promise<ResourceResponse>; export interface ResourceParams { method?: RequestMethod; path?: string; requestInterceptor?: RequestInterceptor; responseInterceptor?: ResponseInterceptor; withCredentials?: boolean; logoutOnUnauthorized?: boolean; timeout?: number; cache?: CacheSettings; } export interface CacheSettings { name: string; ignore_params?: boolean; } export interface ResourcePath { template: string; keys: Array<string>; } export interface CacheInfo { enabled: boolean; replace: boolean; name: string; params: Object; } export interface RequestParams { logoutOnUnauthorized?: boolean; [key: string]: any; } export declare type RequestInterceptor = (requestData: RequestOptions) => RequestOptions; export declare type ResponseInterceptor = (response: ResourceResponse) => ResourceResponse; export interface ResourceResponse { data: any; cached: boolean; status: number; statusText: string; } export interface DefaultRequestData { [key: string]: any; } export interface DefaultResponseData { error?: string; success?: string; id?: number; }