Use the new angular HttpClient

This commit is contained in:
Travis Ralston 2019-06-29 00:21:56 -06:00
parent 8882f4c8f6
commit b79005d868
23 changed files with 152 additions and 242 deletions

View File

@ -1,6 +1,5 @@
import { ApplicationRef, Injector, NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { HttpModule } from "@angular/http";
import { FormsModule } from "@angular/forms";
import { AppComponent } from "./app.component";
import { HomeComponent } from "./home/home.component";
@ -112,11 +111,12 @@ import { AdminSlackApiService } from "./shared/services/admin/admin-slack-api.se
import { AdminLogoutConfirmationDialogComponent } from "./admin/home/logout-confirmation/logout-confirmation.component";
import { ReauthExampleWidgetWrapperComponent } from "./widget-wrappers/reauth-example/reauth-example.component";
import { ManagerTestWidgetWrapperComponent } from "./widget-wrappers/manager-test/manager-test.component";
import { HttpClientModule } from "@angular/common/http";
@NgModule({
imports: [
BrowserModule,
HttpModule,
HttpClientModule,
FormsModule,
routing,
NgbModule,

View File

@ -1,32 +1,27 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_DimensionConfig, FE_DimensionVersion } from "../../models/admin-responses";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public isAdmin(): Promise<any> {
return this.authedGet("/api/v1/dimension/admin/check")
.pipe(map(r => r.json())).toPromise();
return this.authedGet("/api/v1/dimension/admin/check").toPromise();
}
public getConfig(): Promise<FE_DimensionConfig> {
return this.authedGet("/api/v1/dimension/admin/config")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_DimensionConfig>("/api/v1/dimension/admin/config").toPromise();
}
public getVersion(): Promise<FE_DimensionVersion> {
return this.authedGet("/api/v1/dimension/admin/version")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_DimensionVersion>("/api/v1/dimension/admin/version").toPromise();
}
public logoutAll(): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/sessions/logout/all")
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/admin/sessions/logout/all").toPromise();
}
}

View File

@ -1,32 +1,28 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Appservice } from "../../models/admin-responses";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminAppserviceApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getAppservices(): Promise<FE_Appservice[]> {
return this.authedGet("/api/v1/dimension/admin/appservices/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_Appservice[]>("/api/v1/dimension/admin/appservices/all").toPromise();
}
public getAppservice(appserviceId: string): Promise<FE_Appservice> {
return this.authedGet("/api/v1/dimension/admin/appservices/" + appserviceId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_Appservice>("/api/v1/dimension/admin/appservices/" + appserviceId).toPromise();
}
public createAppservice(userPrefix: string): Promise<FE_Appservice> {
return this.authedPost("/api/v1/dimension/admin/appservices/new", {userPrefix: userPrefix})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_Appservice>("/api/v1/dimension/admin/appservices/new", {userPrefix: userPrefix})
.toPromise();
}
public test(appserviceId: string): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/appservices/" + appserviceId + "/test")
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/admin/appservices/" + appserviceId + "/test").toPromise();
}
}

View File

@ -1,37 +1,31 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_CustomSimpleBot, FE_CustomSimpleBotTemplate, FE_UserProfile } from "../../models/admin-responses";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminCustomSimpleBotsApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getBots(): Promise<FE_CustomSimpleBot[]> {
return this.authedGet("/api/v1/dimension/admin/bots/simple/custom/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_CustomSimpleBot[]>("/api/v1/dimension/admin/bots/simple/custom/all").toPromise();
}
public getBot(id: number): Promise<FE_CustomSimpleBot> {
return this.authedGet("/api/v1/dimension/admin/bots/simple/custom/" + id)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_CustomSimpleBot>("/api/v1/dimension/admin/bots/simple/custom/" + id).toPromise();
}
public updateBot(id: number, config: FE_CustomSimpleBotTemplate): Promise<FE_CustomSimpleBot> {
return this.authedPost("/api/v1/dimension/admin/bots/simple/custom/" + id, config)
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_CustomSimpleBot>("/api/v1/dimension/admin/bots/simple/custom/" + id, config).toPromise();
}
public createBot(config: FE_CustomSimpleBotTemplate): Promise<FE_CustomSimpleBot> {
return this.authedPost("/api/v1/dimension/admin/bots/simple/custom/new", config)
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_CustomSimpleBot>("/api/v1/dimension/admin/bots/simple/custom/new", config).toPromise();
}
public getProfile(userId: string): Promise<FE_UserProfile> {
return this.authedGet("/api/v1/dimension/admin/bots/simple/custom/profile/" + userId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_UserProfile>("/api/v1/dimension/admin/bots/simple/custom/profile/" + userId).toPromise();
}
}

View File

@ -1,40 +1,36 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Upstream } from "../../models/admin-responses";
import { FE_GitterBridge } from "../../models/gitter";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminGitterApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getBridges(): Promise<FE_GitterBridge[]> {
return this.authedGet("/api/v1/dimension/admin/gitter/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_GitterBridge[]>("/api/v1/dimension/admin/gitter/all").toPromise();
}
public getBridge(bridgeId: number): Promise<FE_GitterBridge> {
return this.authedGet("/api/v1/dimension/admin/gitter/" + bridgeId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_GitterBridge>("/api/v1/dimension/admin/gitter/" + bridgeId).toPromise();
}
public newFromUpstream(upstream: FE_Upstream): Promise<FE_GitterBridge> {
return this.authedPost("/api/v1/dimension/admin/gitter/new/upstream", {upstreamId: upstream.id})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_GitterBridge>("/api/v1/dimension/admin/gitter/new/upstream", {upstreamId: upstream.id}).toPromise();
}
public newSelfhosted(provisionUrl: string): Promise<FE_GitterBridge> {
return this.authedPost("/api/v1/dimension/admin/gitter/new/selfhosted", {
return this.authedPost<FE_GitterBridge>("/api/v1/dimension/admin/gitter/new/selfhosted", {
provisionUrl: provisionUrl,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
public updateSelfhosted(bridgeId: number, provisionUrl: string): Promise<FE_GitterBridge> {
return this.authedPost("/api/v1/dimension/admin/gitter/" + bridgeId, {
return this.authedPost<FE_GitterBridge>("/api/v1/dimension/admin/gitter/" + bridgeId, {
provisionUrl: provisionUrl,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
}

View File

@ -1,32 +1,27 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Bridge, FE_Widget } from "../../models/integration";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminIntegrationsApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getAllWidgets(): Promise<FE_Widget[]> {
return this.authedGet("/api/v1/dimension/admin/integrations/widget/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_Widget[]>("/api/v1/dimension/admin/integrations/widget/all").toPromise();
}
public getAllBridges(): Promise<FE_Bridge<any>[]> {
return this.authedGet("/api/v1/dimension/admin/integrations/bridge/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_Bridge<any>[]>("/api/v1/dimension/admin/integrations/bridge/all").toPromise();
}
public toggleIntegration(category: string, type: string, enabled: boolean): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/integrations/" + category + "/" + type + "/enabled", {enabled: enabled})
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/admin/integrations/" + category + "/" + type + "/enabled", {enabled: enabled}).toPromise();
}
public setIntegrationOptions(category: string, type: string, options: any): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/integrations/" + category + "/" + type + "/options", {options: options})
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/admin/integrations/" + category + "/" + type + "/options", {options: options}).toPromise();
}
}

View File

@ -1,39 +1,34 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Upstream } from "../../models/admin-responses";
import { FE_IrcBridge } from "../../models/irc";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminIrcApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getBridges(): Promise<FE_IrcBridge[]> {
return this.authedGet("/api/v1/dimension/admin/irc/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_IrcBridge[]>("/api/v1/dimension/admin/irc/all").toPromise();
}
public getBridge(bridgeId: number): Promise<FE_IrcBridge> {
return this.authedGet("/api/v1/dimension/admin/irc/" + bridgeId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_IrcBridge>("/api/v1/dimension/admin/irc/" + bridgeId).toPromise();
}
public newFromUpstream(upstream: FE_Upstream): Promise<FE_IrcBridge> {
return this.authedPost("/api/v1/dimension/admin/irc/new/upstream", {upstreamId: upstream.id})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_IrcBridge>("/api/v1/dimension/admin/irc/new/upstream", {upstreamId: upstream.id}).toPromise();
}
public newSelfhosted(provisionUrl: string): Promise<FE_IrcBridge> {
return this.authedPost("/api/v1/dimension/admin/irc/new/selfhosted", {provisionUrl: provisionUrl})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_IrcBridge>("/api/v1/dimension/admin/irc/new/selfhosted", {provisionUrl: provisionUrl}).toPromise();
}
public setNetworkEnabled(bridgeId: number, networkId: string, isEnabled: boolean): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/irc/" + bridgeId + "/network/" + networkId + "/enabled", {
isEnabled: isEnabled,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
}

View File

@ -1,49 +1,42 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Appservice, FE_NebConfiguration, FE_Upstream } from "../../models/admin-responses";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminNebApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getConfigurations(): Promise<FE_NebConfiguration[]> {
return this.authedGet("/api/v1/dimension/admin/neb/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_NebConfiguration[]>("/api/v1/dimension/admin/neb/all").toPromise();
}
public getConfiguration(nebId: number): Promise<FE_NebConfiguration> {
return this.authedGet("/api/v1/dimension/admin/neb/" + nebId + "/config")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_NebConfiguration>("/api/v1/dimension/admin/neb/" + nebId + "/config").toPromise();
}
public newUpstreamConfiguration(upstream: FE_Upstream): Promise<FE_NebConfiguration> {
return this.authedPost("/api/v1/dimension/admin/neb/new/upstream", {upstreamId: upstream.id})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_NebConfiguration>("/api/v1/dimension/admin/neb/new/upstream", {upstreamId: upstream.id}).toPromise();
}
public newAppserviceConfiguration(adminUrl: string, appservice: FE_Appservice): Promise<FE_NebConfiguration> {
return this.authedPost("/api/v1/dimension/admin/neb/new/appservice", {
return this.authedPost<FE_NebConfiguration>("/api/v1/dimension/admin/neb/new/appservice", {
adminUrl: adminUrl,
appserviceId: appservice.id
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
public toggleIntegration(nebId: number, integrationType: string, setEnabled: boolean): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/neb/" + nebId + "/integration/" + integrationType + "/enabled", {enabled: setEnabled})
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/admin/neb/" + nebId + "/integration/" + integrationType + "/enabled", {enabled: setEnabled}).toPromise();
}
public setIntegrationConfiguration(nebId: number, integrationType: string, configuration: any): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/neb/" + nebId + "/integration/" + integrationType + "/config", configuration)
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/admin/neb/" + nebId + "/integration/" + integrationType + "/config", configuration).toPromise();
}
public getIntegrationConfiguration(nebId: number, integrationType: string): Promise<any> {
return this.authedGet("/api/v1/dimension/admin/neb/" + nebId + "/integration/" + integrationType + "/config")
.pipe(map(r => r.json())).toPromise();
return this.authedGet("/api/v1/dimension/admin/neb/" + nebId + "/integration/" + integrationType + "/config").toPromise();
}
}

View File

@ -1,40 +1,36 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Upstream } from "../../models/admin-responses";
import { FE_SlackBridge } from "../../models/slack";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminSlackApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getBridges(): Promise<FE_SlackBridge[]> {
return this.authedGet("/api/v1/dimension/admin/slack/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_SlackBridge[]>("/api/v1/dimension/admin/slack/all").toPromise();
}
public getBridge(bridgeId: number): Promise<FE_SlackBridge> {
return this.authedGet("/api/v1/dimension/admin/slack/" + bridgeId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_SlackBridge>("/api/v1/dimension/admin/slack/" + bridgeId).toPromise();
}
public newFromUpstream(upstream: FE_Upstream): Promise<FE_SlackBridge> {
return this.authedPost("/api/v1/dimension/admin/slack/new/upstream", {upstreamId: upstream.id})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_SlackBridge>("/api/v1/dimension/admin/slack/new/upstream", {upstreamId: upstream.id}).toPromise();
}
public newSelfhosted(provisionUrl: string): Promise<FE_SlackBridge> {
return this.authedPost("/api/v1/dimension/admin/slack/new/selfhosted", {
return this.authedPost<FE_SlackBridge>("/api/v1/dimension/admin/slack/new/selfhosted", {
provisionUrl: provisionUrl,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
public updateSelfhosted(bridgeId: number, provisionUrl: string): Promise<FE_SlackBridge> {
return this.authedPost("/api/v1/dimension/admin/slack/" + bridgeId, {
return this.authedPost<FE_SlackBridge>("/api/v1/dimension/admin/slack/" + bridgeId, {
provisionUrl: provisionUrl,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
}

View File

@ -1,27 +1,23 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_StickerPack } from "../../models/integration";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminStickersApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getAllPacks(): Promise<FE_StickerPack[]> {
return this.authedGet("/api/v1/dimension/admin/stickers/packs")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_StickerPack[]>("/api/v1/dimension/admin/stickers/packs").toPromise();
}
public togglePack(packId: number, isEnabled: boolean): Promise<any> {
return this.authedPost("/api/v1/dimension/admin/stickers/packs/" + packId + "/enabled", {isEnabled: isEnabled})
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/admin/stickers/packs/" + packId + "/enabled", {isEnabled: isEnabled}).toPromise();
}
public importFromTelegram(packUrl: string): Promise<FE_StickerPack> {
return this.authedPost("/api/v1/dimension/admin/stickers/packs/import/telegram", {packUrl: packUrl})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_StickerPack>("/api/v1/dimension/admin/stickers/packs/import/telegram", {packUrl: packUrl}).toPromise();
}
}

View File

@ -1,44 +1,40 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Upstream } from "../../models/admin-responses";
import { FE_TelegramBridge, FE_TelegramBridgeOptions } from "../../models/telegram";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminTelegramApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getBridges(): Promise<FE_TelegramBridge[]> {
return this.authedGet("/api/v1/dimension/admin/telegram/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_TelegramBridge[]>("/api/v1/dimension/admin/telegram/all").toPromise();
}
public getBridge(bridgeId: number): Promise<FE_TelegramBridge> {
return this.authedGet("/api/v1/dimension/admin/telegram/" + bridgeId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_TelegramBridge>("/api/v1/dimension/admin/telegram/" + bridgeId).toPromise();
}
public newFromUpstream(upstream: FE_Upstream): Promise<FE_TelegramBridge> {
return this.authedPost("/api/v1/dimension/admin/telegram/new/upstream", {upstreamId: upstream.id})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_TelegramBridge>("/api/v1/dimension/admin/telegram/new/upstream", {upstreamId: upstream.id}).toPromise();
}
public newSelfhosted(provisionUrl: string, sharedSecret: string, options: FE_TelegramBridgeOptions): Promise<FE_TelegramBridge> {
return this.authedPost("/api/v1/dimension/admin/telegram/new/selfhosted", {
return this.authedPost<FE_TelegramBridge>("/api/v1/dimension/admin/telegram/new/selfhosted", {
provisionUrl: provisionUrl,
sharedSecret: sharedSecret,
options: options,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
public updateSelfhosted(bridgeId: number, provisionUrl: string, sharedSecret: string, options: FE_TelegramBridgeOptions): Promise<FE_TelegramBridge> {
return this.authedPost("/api/v1/dimension/admin/telegram/" + bridgeId, {
return this.authedPost<FE_TelegramBridge>("/api/v1/dimension/admin/telegram/" + bridgeId, {
provisionUrl: provisionUrl,
sharedSecret: sharedSecret,
options: options,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
}

View File

@ -1,26 +1,24 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Upstream } from "../../models/admin-responses";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminUpstreamApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getUpstreams(): Promise<FE_Upstream[]> {
return this.authedGet("/api/v1/dimension/admin/upstreams/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_Upstream[]>("/api/v1/dimension/admin/upstreams/all").toPromise();
}
public newUpstream(name: string, type: string, scalarUrl: string, apiUrl: string): Promise<FE_Upstream> {
return this.authedPost("/api/v1/dimension/admin/upstreams/new", {
return this.authedPost<FE_Upstream>("/api/v1/dimension/admin/upstreams/new", {
name: name,
type: type,
scalarUrl: scalarUrl,
apiUrl: apiUrl,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
}

View File

@ -1,42 +1,38 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Upstream } from "../../models/admin-responses";
import { FE_WebhooksBridge } from "../../models/webhooks";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminWebhooksApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getBridges(): Promise<FE_WebhooksBridge[]> {
return this.authedGet("/api/v1/dimension/admin/webhooks/all")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_WebhooksBridge[]>("/api/v1/dimension/admin/webhooks/all").toPromise();
}
public getBridge(bridgeId: number): Promise<FE_WebhooksBridge> {
return this.authedGet("/api/v1/dimension/admin/webhooks/" + bridgeId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_WebhooksBridge>("/api/v1/dimension/admin/webhooks/" + bridgeId).toPromise();
}
public newFromUpstream(upstream: FE_Upstream): Promise<FE_WebhooksBridge> {
return this.authedPost("/api/v1/dimension/admin/webhooks/new/upstream", {upstreamId: upstream.id})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_WebhooksBridge>("/api/v1/dimension/admin/webhooks/new/upstream", {upstreamId: upstream.id}).toPromise();
}
public newSelfhosted(provisionUrl: string, sharedSecret: string): Promise<FE_WebhooksBridge> {
return this.authedPost("/api/v1/dimension/admin/webhooks/new/selfhosted", {
return this.authedPost<FE_WebhooksBridge>("/api/v1/dimension/admin/webhooks/new/selfhosted", {
provisionUrl: provisionUrl,
sharedSecret: sharedSecret,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
public updateSelfhosted(bridgeId: number, provisionUrl: string, sharedSecret: string): Promise<FE_WebhooksBridge> {
return this.authedPost("/api/v1/dimension/admin/webhooks/" + bridgeId, {
return this.authedPost<FE_WebhooksBridge>("/api/v1/dimension/admin/webhooks/" + bridgeId, {
provisionUrl: provisionUrl,
sharedSecret: sharedSecret,
}).pipe(map(r => r.json())).toPromise();
}).toPromise();
}
}

View File

@ -1,26 +1,26 @@
import { Http, Response } from "@angular/http";
import { Observable } from "rxjs/Observable";
import { SessionStorage } from "../SessionStorage";
import { HttpClient } from "@angular/common/http";
export class AuthedApi {
constructor(protected http: Http) {
constructor(protected http: HttpClient) {
}
protected authedGet(url: string, qs?: any): Observable<Response> {
protected authedGet<T>(url: string, qs?: any): Observable<T> {
if (!qs) qs = {};
qs["scalar_token"] = SessionStorage.scalarToken;
return this.http.get(url, {params: qs});
return this.http.get<T>(url, {params: qs});
}
protected authedPost(url: string, body?: any): Observable<Response> {
protected authedPost<T>(url: string, body?: any): Observable<T> {
if (!body) body = {};
const qs = {scalar_token: SessionStorage.scalarToken};
return this.http.post(url, body, {params: qs});
return this.http.post<T>(url, body, {params: qs});
}
protected authedDelete(url: string, qs?: any): Observable<Response> {
protected authedDelete<T>(url: string, qs?: any): Observable<T> {
if (!qs) qs = {};
qs["scalar_token"] = SessionStorage.scalarToken;
return this.http.delete(url, {params: qs});
return this.http.delete<T>(url, {params: qs});
}
}

View File

@ -1,27 +1,23 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_GitterLink } from "../../models/gitter";
import { map } from 'rxjs/operators';
import { HttpClient } from "@angular/common/http";
@Injectable()
export class GitterApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public bridgeRoom(roomId: string, gitterRoomName: string): Promise<FE_GitterLink> {
return this.authedPost("/api/v1/dimension/gitter/room/" + roomId + "/link", {gitterRoomName})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_GitterLink>("/api/v1/dimension/gitter/room/" + roomId + "/link", {gitterRoomName}).toPromise();
}
public unbridgeRoom(roomId: string): Promise<any> {
return this.authedDelete("/api/v1/dimension/gitter/room/" + roomId + "/link")
.pipe(map(r => r.json())).toPromise();
return this.authedDelete("/api/v1/dimension/gitter/room/" + roomId + "/link").toPromise();
}
public getLink(roomId: string): Promise<FE_GitterLink> {
return this.authedGet("/api/v1/dimension/gitter/room/" + roomId + "/link")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_GitterLink>("/api/v1/dimension/gitter/room/" + roomId + "/link").toPromise();
}
}

View File

@ -1,38 +1,32 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_IntegrationsResponse } from "../../models/dimension-responses";
import { FE_Integration } from "../../models/integration";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class IntegrationsApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getIntegrations(roomId: string): Promise<FE_IntegrationsResponse> {
return this.authedGet("/api/v1/dimension/integrations/room/" + roomId)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_IntegrationsResponse>("/api/v1/dimension/integrations/room/" + roomId).toPromise();
}
public getIntegration(category: string, type: string): Promise<FE_Integration> {
return this.http.get("/api/v1/dimension/integrations/" + category + "/" + type)
.pipe(map(r => r.json())).toPromise();
return this.http.get<FE_Integration>("/api/v1/dimension/integrations/" + category + "/" + type).toPromise();
}
public getIntegrationInRoom(category: string, type: string, roomId: string): Promise<FE_Integration> {
return this.authedGet("/api/v1/dimension/integrations/room/" + roomId + "/integrations/" + category + "/" + type)
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_Integration>("/api/v1/dimension/integrations/room/" + roomId + "/integrations/" + category + "/" + type).toPromise();
}
public setIntegrationConfiguration(category: string, type: string, roomId: string, newConfig: any): Promise<any> {
return this.authedPost("/api/v1/dimension/integrations/room/" + roomId + "/integrations/" + category + "/" + type + "/config", newConfig)
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/integrations/room/" + roomId + "/integrations/" + category + "/" + type + "/config", newConfig).toPromise();
}
public removeIntegration(category: string, type: string, roomId: string): Promise<any> {
return this.authedDelete("/api/v1/dimension/integrations/room/" + roomId + "/integrations/" + category + "/" + type)
.pipe(map(r => r.json())).toPromise();
return this.authedDelete("/api/v1/dimension/integrations/room/" + roomId + "/integrations/" + category + "/" + type).toPromise();
}
}

View File

@ -1,26 +1,22 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class IrcApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getOperators(networkId: string, channelNoHash: string): Promise<string[]> {
return this.authedGet("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/ops")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<string[]>("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/ops").toPromise();
}
public requestLink(roomId: string, networkId: string, channelNoHash: string, op: string): Promise<any> {
return this.authedPost("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/link/" + roomId, {op: op})
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/link/" + roomId, {op: op}).toPromise();
}
public removeLink(roomId: string, networkId: string, channelNoHash: string): Promise<any> {
return this.authedPost("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/unlink/" + roomId)
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/irc/" + networkId + "/channel/" + channelNoHash + "/unlink/" + roomId).toPromise();
}
}

View File

@ -1,43 +1,39 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_SlackChannel, FE_SlackLink, FE_SlackTeam } from "../../models/slack";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class SlackApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public bridgeRoom(roomId: string, teamId: string, channelId: string): Promise<FE_SlackLink> {
return this.authedPost("/api/v1/dimension/slack/room/" + roomId + "/link", {teamId, channelId})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_SlackLink>("/api/v1/dimension/slack/room/" + roomId + "/link", {
teamId,
channelId
}).toPromise();
}
public unbridgeRoom(roomId: string): Promise<any> {
return this.authedDelete("/api/v1/dimension/slack/room/" + roomId + "/link")
.pipe(map(r => r.json())).toPromise();
return this.authedDelete("/api/v1/dimension/slack/room/" + roomId + "/link").toPromise();
}
public getLink(roomId: string): Promise<FE_SlackLink> {
return this.authedGet("/api/v1/dimension/slack/room/" + roomId + "/link")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_SlackLink>("/api/v1/dimension/slack/room/" + roomId + "/link").toPromise();
}
public getTeams(): Promise<FE_SlackTeam[]> {
return this.authedGet("/api/v1/dimension/slack/teams")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_SlackTeam[]>("/api/v1/dimension/slack/teams").toPromise();
}
public getChannels(teamId: string): Promise<FE_SlackChannel[]> {
return this.authedGet("/api/v1/dimension/slack/teams/" + teamId + "/channels")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_SlackChannel[]>("/api/v1/dimension/slack/teams/" + teamId + "/channels").toPromise();
}
public getAuthUrl(): Promise<string> {
return this.authedGet("/api/v1/dimension/slack/auth")
.pipe(map(r => r.json())).toPromise()
return this.authedGet("/api/v1/dimension/slack/auth").toPromise()
.then(r => r["authUrl"]);
}
}

View File

@ -1,32 +1,27 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_StickerConfig, FE_UserStickerPack } from "../../models/integration";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class StickerApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getConfig(): Promise<FE_StickerConfig> {
return this.authedGet("/api/v1/dimension/stickers/config")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_StickerConfig>("/api/v1/dimension/stickers/config").toPromise();
}
public getPacks(): Promise<FE_UserStickerPack[]> {
return this.authedGet("/api/v1/dimension/stickers/packs")
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_UserStickerPack[]>("/api/v1/dimension/stickers/packs").toPromise();
}
public togglePackSelection(packId: number, isSelected: boolean): Promise<any> {
return this.authedPost("/api/v1/dimension/stickers/packs/" + packId + "/selected", {isSelected: isSelected})
.pipe(map(r => r.json())).toPromise();
return this.authedPost("/api/v1/dimension/stickers/packs/" + packId + "/selected", {isSelected: isSelected}).toPromise();
}
public importStickerpack(packUrl: string): Promise<FE_UserStickerPack> {
return this.authedPost("/api/v1/dimension/stickers/packs/import", {packUrl})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_UserStickerPack>("/api/v1/dimension/stickers/packs/import", {packUrl}).toPromise();
}
}

View File

@ -1,27 +1,23 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_PortalInfo } from "../../models/telegram";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class TelegramApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public getPortalInfo(chatId: number, roomId: string): Promise<FE_PortalInfo> {
return this.authedGet("/api/v1/dimension/telegram/chat/" + chatId, {roomId: roomId})
.pipe(map(r => r.json())).toPromise();
return this.authedGet<FE_PortalInfo>("/api/v1/dimension/telegram/chat/" + chatId, {roomId: roomId}).toPromise();
}
public bridgeRoom(roomId: string, chatId: number, unbridgeOtherPortals = false): Promise<FE_PortalInfo> {
return this.authedPost("/api/v1/dimension/telegram/chat/" + chatId + "/room/" + roomId, {unbridgeOtherPortals})
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_PortalInfo>("/api/v1/dimension/telegram/chat/" + chatId + "/room/" + roomId, {unbridgeOtherPortals}).toPromise();
}
public unbridgeRoom(roomId: string): Promise<FE_PortalInfo> {
return this.authedDelete("/api/v1/dimension/telegram/room/" + roomId)
.pipe(map(r => r.json())).toPromise();
return this.authedDelete<FE_PortalInfo>("/api/v1/dimension/telegram/room/" + roomId).toPromise();
}
}

View File

@ -1,27 +1,23 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Webhook, FE_WebhookOptions } from "../../models/webhooks";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class WebhooksApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http);
}
public createWebhook(roomId: string, options: FE_WebhookOptions): Promise<FE_Webhook> {
return this.authedPost("/api/v1/dimension/webhooks/room/" + roomId + "/webhooks/new", options)
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_Webhook>("/api/v1/dimension/webhooks/room/" + roomId + "/webhooks/new", options).toPromise();
}
public updateWebhook(roomId: string, hookId: string, options: FE_WebhookOptions): Promise<FE_Webhook> {
return this.authedPost("/api/v1/dimension/webhooks/room/" + roomId + "/webhooks/" + hookId, options)
.pipe(map(r => r.json())).toPromise();
return this.authedPost<FE_Webhook>("/api/v1/dimension/webhooks/room/" + roomId + "/webhooks/" + hookId, options).toPromise();
}
public deleteWebhook(roomId: string, hookId: string): Promise<any> {
return this.authedDelete("/api/v1/dimension/webhooks/room/" + roomId + "/webhooks/" + hookId)
.pipe(map(r => r.json())).toPromise();
return this.authedDelete("/api/v1/dimension/webhooks/room/" + roomId + "/webhooks/" + hookId).toPromise();
}
}

View File

@ -1,13 +1,12 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthedApi } from "../authed-api";
import { FE_Widget } from "../../models/integration";
import { IntegrationsApiService } from "./integrations-api.service";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class WidgetApiService extends AuthedApi {
constructor(http: Http, private integrationsApi: IntegrationsApiService) {
constructor(http: HttpClient, private integrationsApi: IntegrationsApiService) {
super(http);
}
@ -16,7 +15,6 @@ export class WidgetApiService extends AuthedApi {
}
public isEmbeddable(url: string): Promise<any> { // 200 = success, anything else = error
return this.http.get("/api/v1/dimension/widgets/embeddable", {params: {url: url}})
.pipe(map(r => r.json())).toPromise();
return this.http.get("/api/v1/dimension/widgets/embeddable", {params: {url: url}}).toPromise();
}
}

View File

@ -1,5 +1,4 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import {
FE_ScalarAccountResponse,
FE_ScalarOpenIdRequestBody,
@ -7,27 +6,25 @@ import {
} from "../../models/scalar-server-responses";
import { AuthedApi } from "../authed-api";
import { SCALAR_API_VERSION } from "../../../../../src/utils/common-constants";
import { map } from "rxjs/operators";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class ScalarServerApiService extends AuthedApi {
constructor(http: Http) {
constructor(http: HttpClient) {
super(http)
}
public ping(): Promise<any> {
return this.http.get("/api/v1/scalar/ping")
.pipe(map(res => res.json())).toPromise();
return this.http.get("/api/v1/scalar/ping").toPromise();
}
public getAccount(): Promise<FE_ScalarAccountResponse> {
return this.authedGet("/api/v1/scalar/account", {v: SCALAR_API_VERSION})
.pipe(map(res => res.json())).toPromise();
return this.authedGet<FE_ScalarAccountResponse>("/api/v1/scalar/account", {v: SCALAR_API_VERSION}).toPromise();
}
public register(openId: FE_ScalarOpenIdRequestBody): Promise<FE_ScalarRegisterResponse> {
return this.http.post("/api/v1/scalar/register", openId, {
return this.http.post<FE_ScalarRegisterResponse>("/api/v1/scalar/register", openId, {
params: {v: SCALAR_API_VERSION},
}).pipe(map(res => res.json())).toPromise();
}).toPromise();
}
}