blob: a2830249fa3690ea356715682bc17a40f90776d5 [file] [log] [blame]
Matteo Scandolo43ffb672016-12-02 14:49:58 -08001/// <reference path="../../../../typings/index.d.ts"/>
2
3// Imports
4import {AppConfig} from '../../config/app.config';
Matteo Scandolo0f77c502016-12-06 16:46:00 -08005import {Injectable} from '@angular/core';
6import {Response} from '@angular/http';
Matteo Scandolo43ffb672016-12-02 14:49:58 -08007import {Observable} from 'rxjs/Rx';
Matteo Scandolo0f77c502016-12-06 16:46:00 -08008import {XosHttp} from './xoshttp.service';
Matteo Scandolo43ffb672016-12-02 14:49:58 -08009
10// Import RxJs required methods
11import 'rxjs/add/operator/map';
12import 'rxjs/add/operator/catch';
13
14@Injectable()
15export class CoreService {
Matteo Scandolo43ffb672016-12-02 14:49:58 -080016 // private instance variable to hold base url
17 private baseUrl = AppConfig.apiEndpoint;
18
Matteo Scandolo0f77c502016-12-06 16:46:00 -080019 // Resolve HTTP using the constructor
20 constructor (private http: XosHttp) {}
21
Matteo Scandolo43ffb672016-12-02 14:49:58 -080022 // Fetch all existing comments
Matteo Scandolo40f8fa92016-12-07 09:21:35 -080023 getCoreEndpoints(): Observable<any[]> {
Matteo Scandolo43ffb672016-12-02 14:49:58 -080024
Matteo Scandolo0f77c502016-12-06 16:46:00 -080025 const search = 'some=param';
26
Matteo Scandolo43ffb672016-12-02 14:49:58 -080027 // ...using get request
Matteo Scandolo0f77c502016-12-06 16:46:00 -080028 return this.http.get(`${this.baseUrl}/core/`, {search})
Matteo Scandolo43ffb672016-12-02 14:49:58 -080029 // ...and calling .json() on the response to return data
Matteo Scandolo0f77c502016-12-06 16:46:00 -080030 .map((res: Response) => res.json())
31 // ...errors if any
Matteo Scandolo40f8fa92016-12-07 09:21:35 -080032 .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
Matteo Scandolo43ffb672016-12-02 14:49:58 -080033
34 }
35}