all files / src/ config.ts

100% Statements 19/19
100% Branches 0/0
100% Functions 8/8
100% Lines 19/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43    28× 28× 28×                             13×                
import { RestangularPath } from './path';
import { Http, Headers, Request, Response, URLSearchParams } from '@angular/http';
 
export type responseInterceptor = (res: any, operation?: string, path?: RestangularPath, url?: string, response?: Response) => any;
export type requestInterceptor = (req: Request, operation?: string, path?: RestangularPath) => Request;
 
export class RestangularConfig {
  private _baseUrl: string = '';
  private _requestInterceptors: Array<requestInterceptor> = [];
  private _responseInterceptors: Array<responseInterceptor> = [];
 
  public defaultHeaders: Headers;
  public defaultParams: URLSearchParams;
 
  public http: Http;
 
  addResponseInterceptors(interceptor: responseInterceptor): RestangularConfig {
    this._responseInterceptors.push(interceptor);
    return this;
  }
 
  addRequestInterceptors(interceptor: requestInterceptor): RestangularConfig {
    this._requestInterceptors.push(interceptor);
    return this;
  }
 
  get responseInterceptors(): Array<responseInterceptor> {
    return this._responseInterceptors;
  }
 
  get requestInterceptors(): Array<requestInterceptor> {
    return this._requestInterceptors;
  }
 
  set baseUrl(baseUrl: string) {
    this._baseUrl = baseUrl.replace(/\/$/g, '');
  }
 
  get baseUrl(): string {
    return this._baseUrl;
  }
}