Client: add basic support to report video abuses
[oweals/peertube.git] / client / src / app / admin / friends / shared / friend.service.ts
1 import { Injectable } from '@angular/core';
2 import { Observable } from 'rxjs/Observable';
3 import 'rxjs/add/operator/catch';
4 import 'rxjs/add/operator/map';
5
6 import { Friend } from './friend.model';
7 import { AuthHttp, RestExtractor, ResultList } from '../../../shared';
8
9 @Injectable()
10 export class FriendService {
11   private static BASE_FRIEND_URL: string = '/api/v1/pods/';
12
13   constructor (
14     private authHttp: AuthHttp,
15     private restExtractor: RestExtractor
16   ) {}
17
18   getFriends() {
19     return this.authHttp.get(FriendService.BASE_FRIEND_URL)
20                         .map(this.restExtractor.extractDataList)
21                         .map(this.extractFriends)
22                         .catch((res) => this.restExtractor.handleError(res));
23   }
24
25   makeFriends(notEmptyHosts) {
26     const body = {
27       hosts: notEmptyHosts
28     };
29
30     return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
31                         .map(this.restExtractor.extractDataBool)
32                         .catch((res) => this.restExtractor.handleError(res));
33   }
34
35   quitFriends() {
36     return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
37                         .map(res => res.status)
38                         .catch((res) => this.restExtractor.handleError(res));
39   }
40
41   private extractFriends(result: ResultList) {
42     const friends: Friend[] = result.data;
43     const totalFriends = result.total;
44
45     return { friends, totalFriends };
46   }
47 }