UNPKG

pd-api

Version:
66 lines (65 loc) 1.59 kB
import { Http, RequestOptionsArgs, Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { AuthService } from './auth/auth.service'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; /** * Api response interface */ export interface ApiResponse { data: any | { items: any[]; count: number; }; success: boolean; error?: { message: string; code: number; }; } /** * Hosts * @type {{analytics: string; platform: (string|string)}} */ export declare const HOSTS: { analytics: string; platform: string; hub: any; }; export declare class ApiService { private http; private auth; private env; /** * Constructor method * @param http * @param auth * @param env Inject 'api.env' environment */ constructor(http: Http, auth: AuthService, env: any); /** * Make GET Request * @param host: string * @param method: string * @param query: any * @return {Observable<ApiResponse>} */ get(host: string, method: string, query: any): Observable<ApiResponse>; /** * Make POST Request * @param host * @param method * @param body * @return {Observable<ApiResponse>} */ post(host: string, method: string, body: any): Observable<ApiResponse>; /** * Generate request options => headers, token, etc */ generateOptions(host: string): RequestOptionsArgs; /** * Response errors handler * @param error */ handleResponseError(error: Response): void; }