Delete Rule WIP

This commit is contained in:
Brandon Thomas committed 2022-02-22 04:59:52 -05:00
1 parent ea6f09565f
commit ecc8fd405e
6 files changed
+181 -29

No files matched your search

+7 -3
View File
@@ -357,12 +357,16 @@ class ApiConfig {
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/create`;
}
deleteTwitchEventRule(eventRuleToken: string) : string {
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/delete/${eventRuleToken}`;
getTwitchEventRule(eventRuleToken: string) : string {
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/${eventRuleToken}/info`;
}
editTwitchEventRule(eventRuleToken: string) : string {
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/update/${eventRuleToken}`;
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/${eventRuleToken}/update`;
}
deleteTwitchEventRule(eventRuleToken: string) : string {
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/${eventRuleToken}/delete`;
}
obsEventsWebsocket(twitchUsername: string) : string {
@@ -0,0 +1,62 @@
import { ApiConfig } from "../../ApiConfig";
import { EventMatchPredicate } from "./shared/EventMatchPredicate";
import { EventResponse } from "./shared/EventResponse";
import { TwitchEventCategory } from "./shared/TwitchEventCategory";
export interface GetTwitchEventRuleSuccessResponse {
success: boolean,
twitch_event_rule: TwitchEventRule
}
export interface TwitchEventRule {
token: string,
event_category: TwitchEventCategory,
event_match_predicate: EventMatchPredicate,
event_response: EventResponse,
user_specified_rule_order: number,
rule_is_disabled: boolean,
created_at: Date,
updated_at: Date,
}
export interface GetTwitchEventRuleErrorResponse {
success: boolean,
}
type GetTwitchEventRuleResponse = GetTwitchEventRuleSuccessResponse | GetTwitchEventRuleErrorResponse;
export function GetTwitchEventRuleIsOk(response: GetTwitchEventRuleResponse): response is GetTwitchEventRuleSuccessResponse {
return response?.success === true;
}
export function GetTwitchEventRuleIsError(response: GetTwitchEventRuleResponse): response is GetTwitchEventRuleErrorResponse {
return response?.success === false;
}
export async function GetTwitchEventRule(ruleToken: string) : Promise<GetTwitchEventRuleResponse>
{
const endpoint = new ApiConfig().getTwitchEventRule(ruleToken);
return await fetch(endpoint, {
method: 'GET',
headers: {
'Accept': 'application/json',
},
credentials: 'include',
})
.then(res => res.json())
.then(res => {
if (!res) {
return { success : false }; // TODO: This loses error semantics and is deprecated
}
if (res && 'success' in res) {
return res;
} else {
return { success : false };
}
})
.catch(e => {
return { success : false };
});
}