2017-05-27 03:27:36 -04:00
|
|
|
import { Injectable } from "@angular/core";
|
|
|
|
import { Http } from "@angular/http";
|
2017-05-28 02:35:40 -04:00
|
|
|
import { Integration } from "./models/integration";
|
2017-05-27 03:27:36 -04:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ApiService {
|
|
|
|
constructor(private http: Http) {
|
|
|
|
}
|
|
|
|
|
2017-06-10 20:58:05 -04:00
|
|
|
checkScalarToken(scalarToken: string): Promise<boolean> {
|
2017-05-28 16:33:57 -04:00
|
|
|
return this.http.get("/api/v1/scalar/checkToken", {params: {scalar_token: scalarToken}})
|
2017-05-27 03:27:36 -04:00
|
|
|
.map(res => res.status === 200).toPromise();
|
|
|
|
}
|
|
|
|
|
2017-12-14 23:25:15 -05:00
|
|
|
getTokenOwner(scalarToken: String): Promise<string> {
|
|
|
|
return this.http.get("/api/v1/dimension/whoami", {params:{scalar_token:scalarToken}})
|
|
|
|
.map(res => res.status === 200 ? res.json()["userId"] : null).toPromise();
|
|
|
|
}
|
|
|
|
|
2017-06-10 20:58:05 -04:00
|
|
|
getIntegrations(roomId: string, scalarToken: string): Promise<Integration[]> {
|
2017-05-28 16:33:57 -04:00
|
|
|
return this.http.get("/api/v1/dimension/integrations/" + roomId, {params: {scalar_token: scalarToken}})
|
2017-05-27 03:27:36 -04:00
|
|
|
.map(res => res.json()).toPromise();
|
|
|
|
}
|
2017-05-27 19:45:07 -04:00
|
|
|
|
2017-05-28 19:39:02 -04:00
|
|
|
removeIntegration(roomId: string, type: string, integrationType: string, scalarToken: string): Promise<any> {
|
2017-05-29 00:51:04 -04:00
|
|
|
const url = "/api/v1/dimension/integrations/" + roomId + "/" + type + "/" + integrationType;
|
|
|
|
return this.http.delete(url, {params: {scalar_token: scalarToken}})
|
|
|
|
.map(res => res.json()).toPromise();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateIntegrationState(roomId: string, type: string, integrationType: string, scalarToken: string, newState: any): Promise<any> {
|
|
|
|
const url = "/api/v1/dimension/integrations/" + roomId + "/" + type + "/" + integrationType + "/state";
|
|
|
|
return this.http.put(url, {scalar_token: scalarToken, state: newState})
|
2017-05-27 19:45:07 -04:00
|
|
|
.map(res => res.json()).toPromise();
|
|
|
|
}
|
2017-06-10 21:09:51 -04:00
|
|
|
|
|
|
|
getIntegrationState(roomId: string, type: string, integrationType: string, scalarToken: string): Promise<any> {
|
|
|
|
const url = "/api/v1/dimension/integrations/" + roomId + "/" + type + "/" + integrationType + "/state";
|
|
|
|
return this.http.get(url, {params: {scalar_token: scalarToken}})
|
|
|
|
.map(res => res.json()).toPromise();
|
|
|
|
}
|
2017-10-09 22:26:46 -04:00
|
|
|
|
|
|
|
isEmbeddable(checkUrl: string): Promise<any> {
|
|
|
|
const url = "/api/v1/dimension/widgets/embeddable";
|
|
|
|
return this.http.get(url, {params: {url: checkUrl}})
|
|
|
|
.map(res => res.json()).toPromise();
|
|
|
|
}
|
2017-12-10 02:59:36 -05:00
|
|
|
|
|
|
|
getIntegration(type: string, integrationType: string): Promise<Integration> {
|
|
|
|
const url = "/api/v1/dimension/integration/" + type + "/" + integrationType;
|
|
|
|
return this.http.get(url).map(res => res.json()).toPromise();
|
|
|
|
}
|
2017-05-27 03:27:36 -04:00
|
|
|
}
|