2017-12-20 23:28:43 -05:00
|
|
|
import { Observable } from "rxjs/Observable";
|
2017-12-22 23:08:10 -05:00
|
|
|
import { SessionStorage } from "../SessionStorage";
|
2019-06-29 02:21:56 -04:00
|
|
|
import { HttpClient } from "@angular/common/http";
|
2017-12-20 23:28:43 -05:00
|
|
|
|
|
|
|
export class AuthedApi {
|
2019-06-29 02:21:56 -04:00
|
|
|
constructor(protected http: HttpClient) {
|
2017-12-20 23:28:43 -05:00
|
|
|
}
|
|
|
|
|
2019-06-29 02:21:56 -04:00
|
|
|
protected authedGet<T>(url: string, qs?: any): Observable<T> {
|
2017-12-20 23:28:43 -05:00
|
|
|
if (!qs) qs = {};
|
2017-12-22 23:08:10 -05:00
|
|
|
qs["scalar_token"] = SessionStorage.scalarToken;
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.http.get<T>(url, {params: qs});
|
2017-12-20 23:28:43 -05:00
|
|
|
}
|
2017-12-23 23:40:01 -05:00
|
|
|
|
2019-06-29 02:21:56 -04:00
|
|
|
protected authedPost<T>(url: string, body?: any): Observable<T> {
|
2017-12-23 23:40:01 -05:00
|
|
|
if (!body) body = {};
|
|
|
|
const qs = {scalar_token: SessionStorage.scalarToken};
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.http.post<T>(url, body, {params: qs});
|
2017-12-23 23:40:01 -05:00
|
|
|
}
|
2018-03-25 18:20:15 -04:00
|
|
|
|
2019-06-29 02:21:56 -04:00
|
|
|
protected authedDelete<T>(url: string, qs?: any): Observable<T> {
|
2018-03-25 18:20:15 -04:00
|
|
|
if (!qs) qs = {};
|
|
|
|
qs["scalar_token"] = SessionStorage.scalarToken;
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.http.delete<T>(url, {params: qs});
|
2018-03-25 18:20:15 -04:00
|
|
|
}
|
2017-12-20 23:28:43 -05:00
|
|
|
}
|