1 import {Injectable} from 'angular2/core';
2 import {Http, Response} from 'angular2/http';
3 import {Observable} from 'rxjs/Rx';
5 import {Video} from '../models/video';
8 export class VideosService {
9 private _baseVideoUrl = '/api/v1/videos/';
11 constructor (private http: Http) {}
14 return this.http.get(this._baseVideoUrl)
15 .map(res => <Video[]> res.json())
16 .catch(this.handleError);
19 getVideo(id: string) {
20 return this.http.get(this._baseVideoUrl + id)
21 .map(res => <Video> res.json())
22 .catch(this.handleError);
25 removeVideo(id: string) {
26 if (confirm('Are you sure?')) {
27 return this.http.delete(this._baseVideoUrl + id)
28 .map(res => <number> res.status)
29 .catch(this.handleError);
33 private handleError (error: Response) {
35 return Observable.throw(error.json().error || 'Server error');