Updating observable on webscoket event
Change-Id: I8325785b8d40b646ea67f28b61b8d603803a571e
diff --git a/src/app/services/rest/xoshttp.service.ts b/src/app/services/rest/xoshttp.service.ts
new file mode 100644
index 0000000..5572683
--- /dev/null
+++ b/src/app/services/rest/xoshttp.service.ts
@@ -0,0 +1,55 @@
+import {Http, RequestOptionsArgs, Response, URLSearchParams} from '@angular/http';
+import {Injectable} from '@angular/core';
+import {Observable} from 'rxjs';
+import {AuthService} from './auth.service';
+/**
+ * Created by teone on 12/6/16.
+ */
+@Injectable()
+export class XosHttp {
+ constructor(
+ private http: Http,
+ private authService: AuthService
+ ) {
+ }
+
+ private checkOptions(options?: RequestOptionsArgs): RequestOptionsArgs {
+ // if options are not there, create them
+ if(!options){
+ options = {};
+ }
+ return options;
+ }
+
+ private getHeaders(options: RequestOptionsArgs): RequestOptionsArgs {
+ // add auth headers
+ options.headers = this.authService.getUserHeaders();
+ return options;
+ }
+
+ private getParams(options: RequestOptionsArgs): RequestOptionsArgs {
+ // add the no_hyperlinks param
+ if (!options.search) {
+ options.search = new URLSearchParams();
+ }
+
+ if (options.search instanceof URLSearchParams) {
+ options.search.set('no_hyperlinks', '1');
+ }
+ else if (typeof options.search === 'string') {
+ options.search += '&no_hyperlinks=1';
+ }
+ 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
+}