aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/friends/friend.service.ts
blob: f956a5ece7d36541169fcfe757f91a360d658f98 (plain) (tree)
1
2
3
4
5
6
7
8
9

                                               
                                             
 
                                        
 
             
                            
                                                           
 
                                                                       

                 

                                                                                    
                                           



                                             

                                                                                    
                                           


                                             
                                                             



                                                                  
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';

import { AuthService } from '../shared';

@Injectable()
export class FriendService {
  private static BASE_FRIEND_URL: string = '/api/v1/pods/';

  constructor (private http: Http, private authService: AuthService) {}

  makeFriends() {
    const headers = this.authService.getRequestHeader();
    return this.http.get(FriendService.BASE_FRIEND_URL + 'makefriends', { headers })
                    .map(res => res.status)
                    .catch(this.handleError);
  }

  quitFriends() {
    const headers = this.authService.getRequestHeader();
    return this.http.get(FriendService.BASE_FRIEND_URL + 'quitfriends', { headers })
                    .map(res => res.status)
                    .catch(this.handleError);
  }

  private handleError (error: Response): Observable<number> {
    console.error(error);
    return Observable.throw(error.json().error || 'Server error');
  }
}