blob: 5c16bcf1897ffba4fafb15c6439a196ab3ef0020 [file] [log] [blame]
Radek Krejci80e003e2017-09-21 14:20:20 +02001import { Injectable } from '@angular/core';
2import { Http, Response, RequestOptions } from '@angular/http';
3import { Observable } from 'rxjs/Observable';
4import 'rxjs/add/operator/catch';
5import 'rxjs/add/operator/map';
6
7import { Device } from './device';
8
9@Injectable()
10export class DevicesService {
11 constructor(private http: Http) {}
12
13 getDevices(): Observable<Device[]> {
14 return this.http.get('/netopeer/inventory/devices/list')
15 .map((resp: Response) => resp.json())
16 .catch((err: Response | any) => Observable.throw(err));
17 }
18
19 addDevice(device: Device) {
20 let options = new RequestOptions({ body: JSON.stringify(device) });
21 return this.http.post('/netopeer/inventory/devices', null, options)
22 .map((resp: Response) => resp.json())
23 .catch((err: Response | any) => Observable.throw(err));
24 }
25
26 rmDevice(device_id: number) {
27 let options = new RequestOptions({ body: JSON.stringify({'id':device_id}) });
28 return this.http.delete('/netopeer/inventory/devices', options)
29 .map((resp: Response) => resp.json())
30 .catch((err: Response | any) => Observable.throw(err));
31 }
32}