-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathParent.ts
More file actions
48 lines (42 loc) · 1.87 KB
/
Copy pathParent.ts
File metadata and controls
48 lines (42 loc) · 1.87 KB
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
44
45
46
47
48
import { Injectable, Inject } from '@angular/core';
import { Http } from '@angular/http';
// Need to import interfaces dependencies
// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938
import { Observable } from 'rxjs/Observable';
import { RequestOptionsArgs } from '@angular/http/src/interfaces';
import { Response } from '@angular/http/src/static_response';
import { WpApiLoader } from './Loaders';
import { stripTrailingSlash } from './utils';
export interface IParent {
httpGet(url: string, options?: RequestOptionsArgs): Observable<Response>;
httpHead(url: string, options?: RequestOptionsArgs): Observable<Response>;
httpDelete(url: string, options?: RequestOptionsArgs): Observable<Response>;
httpPost(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
httpPut(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
httpPatch(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
}
@Injectable()
export class WpApiParent implements IParent {
constructor(
public wpApiLoader: WpApiLoader,
public http: Http
) { }
httpGet(url: string, options = {}) {
return this.http.get(this.wpApiLoader.getWebServiceUrl(url), options);
}
httpHead(url: string, options = {}) {
return this.http.head(this.wpApiLoader.getWebServiceUrl(url), options);
}
httpDelete(url: string, options = {}) {
return this.http.delete(this.wpApiLoader.getWebServiceUrl(url), options);
}
httpPost(url: string, body = {}, options = {}) {
return this.http.post(this.wpApiLoader.getWebServiceUrl(url), body, options);
}
httpPut(url: string, body = {}, options = {}) {
return this.http.put(this.wpApiLoader.getWebServiceUrl(url), body, options);
}
httpPatch(url: string, body = {}, options = {}) {
return this.http.patch(this.wpApiLoader.getWebServiceUrl(url), body, options);
}
}