]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/app/friends/friend.service.ts
Add authentication tokens to make friends/quit friends
[github/Chocobozzz/PeerTube.git] / client / app / friends / friend.service.ts
1 import { Injectable } from '@angular/core';
2 import { Http, Response } from '@angular/http';
3 import { Observable } from 'rxjs/Rx';
4
5 import { AuthService } from '../shared/index';
6
7 @Injectable()
8 export class FriendService {
9 private static BASE_FRIEND_URL: string = '/api/v1/pods/';
10
11 constructor (private http: Http, private authService: AuthService) {}
12
13 makeFriends() {
14 const headers = this.authService.getRequestHeader();
15 return this.http.get(FriendService.BASE_FRIEND_URL + 'makefriends', { headers })
16 .map(res => res.status)
17 .catch(this.handleError);
18 }
19
20 quitFriends() {
21 const headers = this.authService.getRequestHeader();
22 return this.http.get(FriendService.BASE_FRIEND_URL + 'quitfriends', { headers })
23 .map(res => res.status)
24 .catch(this.handleError);
25 }
26
27 private handleError (error: Response): Observable<number> {
28 console.error(error);
29 return Observable.throw(error.json().error || 'Server error');
30 }
31 }