Added slices

Change-Id: I9dfaa9348fa82da844a04c0c2a58ce07e9fa3a28
diff --git a/src/app/services/rest/auth.service.ts b/src/app/services/rest/auth.service.ts
index b5b00fb..978825f 100644
--- a/src/app/services/rest/auth.service.ts
+++ b/src/app/services/rest/auth.service.ts
@@ -2,7 +2,7 @@
 
 // Imports
 import {AppConfig} from '../../config/app.config';
-import {Injectable}     from '@angular/core';
+import {Injectable} from '@angular/core';
 import {Http, Response, Headers} from '@angular/http';
 import {Observable} from 'rxjs/Rx';
 import {IAuthRequest, IAuthResponse} from '../../interfaces/auth.interface';
@@ -28,13 +28,35 @@
   }
 
   // get auth info to authenticate API
-  getUserHeaders(): Headers{
+  getUserHeaders(): Headers {
     const headers = new Headers();
     headers.append('x-csrftoken', this.cookieService.get('xoscsrftoken'));
     headers.append('x-sessionid', this.cookieService.get('xossessionid'));
     return headers;
   }
 
+  // log the user in
+  login(auth: IAuthRequest): Observable<IAuthResponse> {
+    return this.http.post(`${AppConfig.apiEndpoint}/utility/login/`, auth)
+      .map((res: Response) => res.json())
+      .map((auth: IAuthResponse) => {
+        this.storeAuth(auth);
+        auth.user = JSON.parse(auth.user);
+        return auth;
+      })
+      .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
+  }
+
+  // logout the user
+  logout(): Observable<any> {
+    return this.http.post(`${AppConfig.apiEndpoint}/utility/logout/`, {xossessionid: this.xosSessionId})
+      .map((res: Response) => {
+        this.removeAuth();
+        return res.text();
+      })
+      .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
+  }
+
   // save cookies
   private storeAuth(auth: IAuthResponse): void {
     this.cookieService.put('xoscsrftoken', auth.xoscsrftoken);
@@ -46,27 +68,5 @@
     this.cookieService.remove('xoscsrftoken');
     this.cookieService.remove('xossessionid');
   }
-
-  // log the user in
-  login(auth: IAuthRequest): Observable<IAuthResponse> {
-    return this.http.post(`${AppConfig.apiEndpoint}/utility/login/`, auth)
-      .map((res: Response) => res.json())
-      .map((auth: IAuthResponse) => {
-        this.storeAuth(auth);
-        auth.user = JSON.parse(auth.user);
-        return auth;
-      })
-      .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
-  }
-
-  // logout the user
-  logout(): Observable<any> {
-    return this.http.post(`${AppConfig.apiEndpoint}/utility/logout/`, {xossessionid: this.xosSessionId})
-      .map((res: Response) => {
-        this.removeAuth();
-        return res.text();
-      })
-      .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
-  }
 }
 
diff --git a/src/app/services/rest/core.service.ts b/src/app/services/rest/core.service.ts
index 3890c47..a283024 100644
--- a/src/app/services/rest/core.service.ts
+++ b/src/app/services/rest/core.service.ts
@@ -20,7 +20,7 @@
   constructor (private http: XosHttp) {}
 
   // Fetch all existing comments
-  getCoreEndpoints() : Observable<any[]> {
+  getCoreEndpoints(): Observable<any[]> {
 
     const search = 'some=param';
 
@@ -29,7 +29,7 @@
     // ...and calling .json() on the response to return data
       .map((res: Response) => res.json())
       // ...errors if any
-      .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
+      .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
 
   }
 }
diff --git a/src/app/services/rest/instance.service.ts b/src/app/services/rest/instance.service.ts
index c864e54..899b484 100644
--- a/src/app/services/rest/instance.service.ts
+++ b/src/app/services/rest/instance.service.ts
@@ -3,8 +3,8 @@
 // Imports
 import {AppConfig} from '../../config/app.config';
 import {AuthService} from './auth.service';
-import { Injectable }     from '@angular/core';
-import { Http, Response, Headers } from '@angular/http';
+import {Injectable}     from '@angular/core';
+import {Response} from '@angular/http';
 import {XosHttp} from './xoshttp.service';
 import {Observable} from 'rxjs/Rx';
 
diff --git a/src/app/services/rest/slices.service.ts b/src/app/services/rest/slices.service.ts
new file mode 100644
index 0000000..2b71d7a
--- /dev/null
+++ b/src/app/services/rest/slices.service.ts
@@ -0,0 +1,24 @@
+/// <reference path="../../../../typings/index.d.ts"/>
+
+// Imports
+import {AppConfig} from '../../config/app.config';
+import { Injectable }     from '@angular/core';
+import { Response} from '@angular/http';
+import {XosHttp} from './xoshttp.service';
+import {Observable} from 'rxjs/Rx';
+
+// Import RxJs required methods
+import 'rxjs/add/operator/map';
+import 'rxjs/add/operator/catch';
+
+@Injectable()
+export class SliceService {
+  private baseUrl = AppConfig.apiEndpoint;
+  constructor (private http: XosHttp) {}
+  // Fetch all existing instances
+  query() : Observable<any[]> {
+    return this.http.get(`${this.baseUrl}/core/slices/`)
+      .map((res: Response) => res.json())
+      .catch((error: any) => Observable.throw(error.response.json().error || 'Server error'));
+  }
+}
diff --git a/src/app/services/rest/xoshttp.service.ts b/src/app/services/rest/xoshttp.service.ts
index 5572683..a300ee3 100644
--- a/src/app/services/rest/xoshttp.service.ts
+++ b/src/app/services/rest/xoshttp.service.ts
@@ -13,9 +13,20 @@
   ) {
   }
 
+  // TODO intercept non authenticated calls and send to login (remove cookies)
+  // TODO add POST, PUT, DELETE declaration
+  get(url: string, options?: RequestOptionsArgs): Observable<Response> {
+
+    options = this.checkOptions(options);
+    options = this.getHeaders(options);
+    options = this.getParams(options);
+
+    return this.http.get(url, options);
+  }
+
   private checkOptions(options?: RequestOptionsArgs): RequestOptionsArgs {
     // if options are not there, create them
-    if(!options){
+    if (!options) {
       options = {};
     }
     return options;
@@ -41,15 +52,4 @@
     }
     return options;
   }
-
-  get(url: string, options?: RequestOptionsArgs): Observable<Response> {
-
-    options = this.checkOptions(options);
-    options = this.getHeaders(options);
-    options = this.getParams(options);
-
-    return this.http.get(url, options)
-  }
-
-  // TODO add POST, PUT, DELETE declaration
 }