]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/admin/friends/shared/friend.service.ts
Client: add friends page
[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() {
24 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'makefriends')
25 .map(res => res.status)
26 .catch(this.handleError);
27 }
28
29 quitFriends() {
30 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
31 .map(res => res.status)
32 .catch(this.handleError);
33 }
34
35 private handleError (error: Response) {
36 console.error(error);
37 return Observable.throw(error.json().error || 'Server error');
38 }
39 }