]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/friends/shared/friend.service.ts
Share models between server and client
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / friends / shared / friend.service.ts
CommitLineData
df98563e
C
1import { Injectable } from '@angular/core'
2import { Observable } from 'rxjs/Observable'
3import 'rxjs/add/operator/catch'
4import 'rxjs/add/operator/map'
e2f555ca 5
df98563e 6import { ServerDataSource } from 'ng2-smart-table'
28798b5d 7
df98563e 8import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared'
e2f555ca
C
9
10@Injectable()
11export class FriendService {
df98563e 12 private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/'
e2f555ca
C
13
14 constructor (
15 private authHttp: AuthHttp,
de59c48f 16 private restExtractor: RestExtractor
e2f555ca
C
17 ) {}
18
df98563e
C
19 getDataSource () {
20 return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL)
e2f555ca
C
21 }
22
df98563e 23 makeFriends (notEmptyHosts) {
e105c19c 24 const body = {
49abbbbe 25 hosts: notEmptyHosts
df98563e 26 }
e105c19c
C
27
28 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
de59c48f 29 .map(this.restExtractor.extractDataBool)
df98563e 30 .catch((res) => this.restExtractor.handleError(res))
e2f555ca
C
31 }
32
df98563e 33 quitFriends () {
e2f555ca
C
34 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
35 .map(res => res.status)
df98563e 36 .catch((res) => this.restExtractor.handleError(res))
e2f555ca
C
37 }
38}