/* * Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. */ import { SDKHooks } from "../hooks"; import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "../lib/config"; import * as enc$ from "../lib/encodings"; import { HTTPClient } from "../lib/http"; import * as schemas$ from "../lib/schemas"; import { ClientSDK, RequestOptions } from "../lib/sdks"; import * as errors from "../models/errors"; import * as operations from "../models/operations"; export class Sessions extends ClientSDK { private readonly options$: SDKOptions & { hooks?: SDKHooks }; constructor(options: SDKOptions = {}) { const opt = options as unknown; let hooks: SDKHooks; if ( typeof opt === "object" && opt != null && "hooks" in opt && opt.hooks instanceof SDKHooks ) { hooks = opt.hooks; } else { hooks = new SDKHooks(); } super({ client: options.httpClient || new HTTPClient(), baseURL: serverURLFromOptions(options), hooks, }); this.options$ = { ...options, hooks }; void this.options$; } /** * Get Active Sessions * * @remarks * This will retrieve the "Now Playing" Information of the PMS. */ async getSessions(options?: RequestOptions): Promise { const headers$ = new Headers(); headers$.set("user-agent", SDK_METADATA.userAgent); headers$.set("Accept", "application/json"); const path$ = this.templateURLComponent("/status/sessions")(); const query$ = ""; let security$; if (typeof this.options$.accessToken === "function") { security$ = { accessToken: await this.options$.accessToken() }; } else if (this.options$.accessToken) { security$ = { accessToken: this.options$.accessToken }; } else { security$ = {}; } const context = { operationID: "getSessions", oAuth2Scopes: [], securitySource: this.options$.accessToken, }; const securitySettings$ = this.resolveGlobalSecurity(security$); const doOptions = { context, errorCodes: ["400", "401", "4XX", "5XX"] }; const request$ = this.createRequest$( context, { security: securitySettings$, method: "GET", path: path$, headers: headers$, query: query$, }, options ); const response = await this.do$(request$, doOptions); const responseFields$ = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; if (this.matchResponse(response, 200, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return operations.GetSessionsResponse$.inboundSchema.parse({ ...responseFields$, object: val$, }); }, "Response validation failed" ); return result; } else if (this.matchResponse(response, 401, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return errors.GetSessionsResponseBody$.inboundSchema.parse({ ...responseFields$, ...val$, }); }, "Response validation failed" ); throw result; } else { const responseBody = await response.text(); throw new errors.SDKError( "Unexpected API response status or content-type", response, responseBody ); } } /** * Get Session History * * @remarks * This will Retrieve a listing of all history views. */ async getSessionHistory( options?: RequestOptions ): Promise { const headers$ = new Headers(); headers$.set("user-agent", SDK_METADATA.userAgent); headers$.set("Accept", "application/json"); const path$ = this.templateURLComponent("/status/sessions/history/all")(); const query$ = ""; let security$; if (typeof this.options$.accessToken === "function") { security$ = { accessToken: await this.options$.accessToken() }; } else if (this.options$.accessToken) { security$ = { accessToken: this.options$.accessToken }; } else { security$ = {}; } const context = { operationID: "getSessionHistory", oAuth2Scopes: [], securitySource: this.options$.accessToken, }; const securitySettings$ = this.resolveGlobalSecurity(security$); const doOptions = { context, errorCodes: ["400", "401", "4XX", "5XX"] }; const request$ = this.createRequest$( context, { security: securitySettings$, method: "GET", path: path$, headers: headers$, query: query$, }, options ); const response = await this.do$(request$, doOptions); const responseFields$ = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; if (this.matchResponse(response, 200, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return operations.GetSessionHistoryResponse$.inboundSchema.parse({ ...responseFields$, object: val$, }); }, "Response validation failed" ); return result; } else if (this.matchResponse(response, 401, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return errors.GetSessionHistoryResponseBody$.inboundSchema.parse({ ...responseFields$, ...val$, }); }, "Response validation failed" ); throw result; } else { const responseBody = await response.text(); throw new errors.SDKError( "Unexpected API response status or content-type", response, responseBody ); } } /** * Get Transcode Sessions * * @remarks * Get Transcode Sessions */ async getTranscodeSessions( options?: RequestOptions ): Promise { const headers$ = new Headers(); headers$.set("user-agent", SDK_METADATA.userAgent); headers$.set("Accept", "application/json"); const path$ = this.templateURLComponent("/transcode/sessions")(); const query$ = ""; let security$; if (typeof this.options$.accessToken === "function") { security$ = { accessToken: await this.options$.accessToken() }; } else if (this.options$.accessToken) { security$ = { accessToken: this.options$.accessToken }; } else { security$ = {}; } const context = { operationID: "getTranscodeSessions", oAuth2Scopes: [], securitySource: this.options$.accessToken, }; const securitySettings$ = this.resolveGlobalSecurity(security$); const doOptions = { context, errorCodes: ["400", "401", "4XX", "5XX"] }; const request$ = this.createRequest$( context, { security: securitySettings$, method: "GET", path: path$, headers: headers$, query: query$, }, options ); const response = await this.do$(request$, doOptions); const responseFields$ = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; if (this.matchResponse(response, 200, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return operations.GetTranscodeSessionsResponse$.inboundSchema.parse({ ...responseFields$, object: val$, }); }, "Response validation failed" ); return result; } else if (this.matchResponse(response, 401, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return errors.GetTranscodeSessionsResponseBody$.inboundSchema.parse({ ...responseFields$, ...val$, }); }, "Response validation failed" ); throw result; } else { const responseBody = await response.text(); throw new errors.SDKError( "Unexpected API response status or content-type", response, responseBody ); } } /** * Stop a Transcode Session * * @remarks * Stop a Transcode Session */ async stopTranscodeSession( sessionKey: string, options?: RequestOptions ): Promise { const input$: operations.StopTranscodeSessionRequest = { sessionKey: sessionKey, }; const headers$ = new Headers(); headers$.set("user-agent", SDK_METADATA.userAgent); headers$.set("Accept", "application/json"); const payload$ = schemas$.parse( input$, (value$) => operations.StopTranscodeSessionRequest$.outboundSchema.parse(value$), "Input validation failed" ); const body$ = null; const pathParams$ = { sessionKey: enc$.encodeSimple("sessionKey", payload$.sessionKey, { explode: false, charEncoding: "percent", }), }; const path$ = this.templateURLComponent("/transcode/sessions/{sessionKey}")(pathParams$); const query$ = ""; let security$; if (typeof this.options$.accessToken === "function") { security$ = { accessToken: await this.options$.accessToken() }; } else if (this.options$.accessToken) { security$ = { accessToken: this.options$.accessToken }; } else { security$ = {}; } const context = { operationID: "stopTranscodeSession", oAuth2Scopes: [], securitySource: this.options$.accessToken, }; const securitySettings$ = this.resolveGlobalSecurity(security$); const doOptions = { context, errorCodes: ["400", "401", "4XX", "5XX"] }; const request$ = this.createRequest$( context, { security: securitySettings$, method: "DELETE", path: path$, headers: headers$, query: query$, body: body$, }, options ); const response = await this.do$(request$, doOptions); const responseFields$ = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; if (this.matchStatusCode(response, 204)) { // fallthrough } else if (this.matchResponse(response, 401, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return errors.StopTranscodeSessionResponseBody$.inboundSchema.parse({ ...responseFields$, ...val$, }); }, "Response validation failed" ); throw result; } else { const responseBody = await response.text(); throw new errors.SDKError( "Unexpected API response status or content-type", response, responseBody ); } return schemas$.parse( undefined, () => operations.StopTranscodeSessionResponse$.inboundSchema.parse(responseFields$), "Response validation failed" ); } }