1/**
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { HttpClient } from '@angular/common/http';
17import { Injectable } from '@angular/core';
18
19import { catchError } from 'rxjs/operators';
20import { Observable } from 'rxjs';
21
22import { environment } from '../../../environments/environment';
23import { DeviceWrapper } from '../../model/device_wrapper';
24import { ServiceBase } from '../../shared/servicebase';
25
26
27@Injectable()
28export class DeviceService extends ServiceBase {
29  constructor(public httpClient: HttpClient) {
30    super(httpClient);
31    this.url = environment['baseURL'] + '/host/v1/';
32  }
33
34  getDevices(size: number,
35             offset: number,
36             filterInfo: string,
37             sort: string,
38             direction: string): Observable<DeviceWrapper> {
39    const url = this.url + 'get';
40    return this.httpClient.post<DeviceWrapper>(url,  {size: size, offset: offset, filter: filterInfo, sort: sort, direction: direction})
41      .pipe(catchError(this.handleError));
42  }
43}
44