]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/admin/friends/shared/friend.service.ts
Client: support the new make friends method
[github/Chocobozzz/PeerTube.git] / client / src / app / admin / friends / shared / friend.service.ts
1 import { Injectable } from '@angular/core';
2 import { Response } from '@angular/http';
3 import { Observable } from 'rxjs/Observable';
4
5 import { Friend } from './friend.model';
6 import { AuthHttp, AuthService } from '../../../shared';
7
8 @Injectable()
9 export class FriendService {
10 private static BASE_FRIEND_URL: string = '/api/v1/pods/';
11
12 constructor (
13 private authHttp: AuthHttp,
14 private authService: AuthService
15 ) {}
16
17 getFriends(): Observable<Friend[]> {
18 return this.authHttp.get(FriendService.BASE_FRIEND_URL)
19 .map(res => <Friend[]>res.json())
20 .catch(this.handleError);
21 }
22
23 makeFriends(notEmptyUrls) {
24 const body = {
25 urls: notEmptyUrls
26 };
27
28 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
29 .map(res => res.status)
30 .catch(this.handleError);
31 }
32
33 quitFriends() {
34 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
35 .map(res => res.status)
36 .catch(this.handleError);
37 }
38
39 private handleError (error: Response) {
40 console.error(error);
41 return Observable.throw(error.json().error || 'Server error');
42 }
43 }