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