aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/friends/services/friends.service.ts
blob: a34ef0d6fb951ae374f3760392974c8558b264bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {Injectable} from 'angular2/core';
import {Http, Response, Headers, RequestOptions} from 'angular2/http';
import {Observable} from 'rxjs/Rx';

@Injectable()
export class FriendsService {
  private _baseFriendsUrl = '/api/v1/pods/';

  constructor (private http: Http) {}

  makeFriends() {
    return this.http.get(this._baseFriendsUrl + 'makefriends')
                    .map(res => <number> res.status)
                    .catch(this.handleError);
  }

  quitFriends() {
    return this.http.get(this._baseFriendsUrl + 'quitfriends')
                    .map(res => <number> res.status)
                    .catch(this.handleError);
  }

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