Skip to content

Commit

Permalink
add missing Helix Schedule methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d-fischer committed Jun 24, 2021
1 parent 2c683f1 commit 338782c
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -25,7 +25,7 @@ const memberNames = [
'^click_action$',
'^(image_)?url_\\dx$',
'^emoticon_sets?$',
'^is_(anonymous|gift|user_input_required|sub_only|mature|enabled|paused|in_stock|previewable|playlist|(verified|known)_bot|live|auto|permanent|recurring|vacation_enabled)$',
'^is_(anonymous|gift|user_input_required|sub_only|mature|enabled|paused|in_stock|previewable|playlist|(verified|known)_bot|live|auto|permanent|recurring|vacation_enabled|canceled)$',
'^minimum_allowed_role$',
'^(chatter|view(er)?)_count$',
'^min_bits$',
Expand Down
158 changes: 158 additions & 0 deletions packages/twitch/src/API/Helix/Schedule/HelixScheduleApi.ts
Expand Up @@ -76,6 +76,76 @@ export interface HelixScheduleSettingsUpdate {
vacation?: HelixScheduleSettingsUpdateVacation | null;
}

/**
* The data required to create a schedule segment.
*/
export interface HelixCreateScheduleSegmentData {
/**
* The date when the segment starts.
*/
startDate: string;

/**
* The timezone the `startDate` is in.
*/
timezone: string;

/**
* Whether the segment is recurring every week.
*/
isRecurring: boolean;

/**
* The planned duration of the segment, in minutes. Defaults to 240 (4 hours).
*/
duration?: number;

/**
* The ID of the category of the segment.
*/
categoryId?: string;

/**
* The title of the segment.
*/
title?: string;
}

/**
* The data required to update a schedule segment.
*/
export interface HelixUpdateScheduleSegmentData {
/**
* The date when the segment starts.
*/
startDate: string;

/**
* The timezone the `startDate` is in.
*/
timezone: string;

/**
* The planned duration of the segment, in minutes. Defaults to 240 (4 hours).
*/
duration?: number;

/**
* The ID of the category of the segment.
*/
categoryId?: string;

/**
* The title of the segment.
*/
title?: string;

/**
* Whether the schedule broadcast is canceled.
*/
isCanceled?: boolean;
}

/**
* The Helix API methods that deal with schedules.
*/
Expand Down Expand Up @@ -200,4 +270,92 @@ export class HelixScheduleApi extends BaseApi {
}
});
}

/**
* Creates a new segment in a given broadcaster's schedule.
*
* @param broadcaster The broadcaster to create a new schedule segment for.
* @param data
*
* @expandParams
*/
async createScheduleSegment(
broadcaster: UserIdResolvable,
data: HelixCreateScheduleSegmentData
): Promise<HelixScheduleSegment> {
const result = await this._client.callApi<HelixScheduleResponse>({
type: TwitchApiCallType.Helix,
url: 'schedule/segment',
method: 'POST',
scope: 'channel:manage:schedule',
query: {
broadcaster_id: extractUserId(broadcaster)
},
jsonBody: {
start_time: data.startDate,
timezone: data.timezone,
is_recurring: data.isRecurring,
duration: data.duration,
category_id: data.categoryId,
title: data.title
}
});

return new HelixScheduleSegment(result.data.segments[0], this._client);
}

/**
* Updates a segment in a given broadcaster's schedule.
*
* @param broadcaster The broadcaster to create a new schedule segment for.
* @param segmentId The ID of the segment to update.
* @param data
*
* @expandParams
*/
async updateScheduleSegment(
broadcaster: UserIdResolvable,
segmentId: string,
data: HelixUpdateScheduleSegmentData
): Promise<HelixScheduleSegment> {
const result = await this._client.callApi<HelixScheduleResponse>({
type: TwitchApiCallType.Helix,
url: 'schedule/segment',
method: 'PATCH',
scope: 'channel:manage:schedule',
query: {
broadcaster_id: extractUserId(broadcaster),
id: segmentId
},
jsonBody: {
start_time: data.startDate,
timezone: data.timezone,
is_canceled: data.isCanceled,
duration: data.duration,
category_id: data.categoryId,
title: data.title
}
});

return new HelixScheduleSegment(result.data.segments[0], this._client);
}

/**
* Deletes a segment in a given broadcaster's schedule.
*
* @param broadcaster The broadcaster to create a new schedule segment for.
* @param segmentId The ID of the segment to update.
*/
async deleteScheduleSegment(broadcaster: UserIdResolvable, segmentId: string): Promise<void> {
await this._client.callApi<HelixScheduleResponse>({
type: TwitchApiCallType.Helix,
url: 'schedule/segment',
method: 'DELETE',
scope: 'channel:manage:schedule',
query: {
broadcaster_id: extractUserId(broadcaster),
id: segmentId
}
});
}
}
8 changes: 7 additions & 1 deletion packages/twitch/src/index.ts
Expand Up @@ -98,7 +98,13 @@ export { HelixPredictor } from './API/Helix/Prediction/HelixPredictor';

export { HelixUserRelation } from './API/Helix/Relations/HelixUserRelation';

export type { HelixScheduleFilter, HelixPaginatedScheduleFilter } from './API/Helix/Schedule/HelixScheduleApi';
export type {
HelixScheduleFilter,
HelixPaginatedScheduleFilter,
HelixScheduleSettingsUpdate,
HelixCreateScheduleSegmentData,
HelixUpdateScheduleSegmentData
} from './API/Helix/Schedule/HelixScheduleApi';
export { HelixSchedule } from './API/Helix/Schedule/HelixSchedule';
export { HelixScheduleSegment } from './API/Helix/Schedule/HelixScheduleSegment';
export { HelixPaginatedScheduleSegmentRequest } from './API/Helix/Schedule/HelixPaginatedScheduleSegmentRequest';
Expand Down

0 comments on commit 338782c

Please sign in to comment.