aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/videos/services
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-03-14 13:50:19 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-03-14 13:50:19 +0100
commitdc8bc31be517a53e8fbe7100cfe45cd73f596de0 (patch)
treec0b0d6641dd352dafff93b8fd33ddb262b59aa47 /client/angular/videos/services
parentbd324a669218f9ed302f7f54b36ee535d25c9733 (diff)
downloadPeerTube-dc8bc31be517a53e8fbe7100cfe45cd73f596de0.tar.gz
PeerTube-dc8bc31be517a53e8fbe7100cfe45cd73f596de0.tar.zst
PeerTube-dc8bc31be517a53e8fbe7100cfe45cd73f596de0.zip
Angular application :first draft
Diffstat (limited to 'client/angular/videos/services')
-rw-r--r--client/angular/videos/services/videos.service.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/client/angular/videos/services/videos.service.ts b/client/angular/videos/services/videos.service.ts
new file mode 100644
index 000000000..784eec68d
--- /dev/null
+++ b/client/angular/videos/services/videos.service.ts
@@ -0,0 +1,37 @@
1import {Injectable} from 'angular2/core';
2import {Http, Response} from 'angular2/http';
3import {Observable} from 'rxjs/Rx';
4
5import {Video} from '../models/video';
6
7@Injectable()
8export class VideosService {
9 private _baseVideoUrl = '/api/v1/videos/';
10
11 constructor (private http: Http) {}
12
13 getVideos() {
14 return this.http.get(this._baseVideoUrl)
15 .map(res => <Video[]> res.json())
16 .catch(this.handleError);
17 }
18
19 getVideo(id: string) {
20 return this.http.get(this._baseVideoUrl + id)
21 .map(res => <Video> res.json())
22 .catch(this.handleError);
23 }
24
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);
30 }
31 }
32
33 private handleError (error: Response) {
34 console.error(error);
35 return Observable.throw(error.json().error || 'Server error');
36 }
37}