mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-07 20:47:49 +00:00
234 lines
7.5 KiB
TypeScript
234 lines
7.5 KiB
TypeScript
/*
|
|
* 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 Activities 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 Server Activities
|
|
*
|
|
* @remarks
|
|
* Get Server Activities
|
|
*/
|
|
async getServerActivities(
|
|
options?: RequestOptions
|
|
): Promise<operations.GetServerActivitiesResponse> {
|
|
const headers$ = new Headers();
|
|
headers$.set("user-agent", SDK_METADATA.userAgent);
|
|
headers$.set("Accept", "application/json");
|
|
|
|
const path$ = this.templateURLComponent("/activities")();
|
|
|
|
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: "getServerActivities",
|
|
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.GetServerActivitiesResponse$.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.GetServerActivitiesResponseBody$.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
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Cancel Server Activities
|
|
*
|
|
* @remarks
|
|
* Cancel Server Activities
|
|
*/
|
|
async cancelServerActivities(
|
|
activityUUID: string,
|
|
options?: RequestOptions
|
|
): Promise<operations.CancelServerActivitiesResponse> {
|
|
const input$: operations.CancelServerActivitiesRequest = {
|
|
activityUUID: activityUUID,
|
|
};
|
|
const headers$ = new Headers();
|
|
headers$.set("user-agent", SDK_METADATA.userAgent);
|
|
headers$.set("Accept", "application/json");
|
|
|
|
const payload$ = schemas$.parse(
|
|
input$,
|
|
(value$) => operations.CancelServerActivitiesRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const pathParams$ = {
|
|
activityUUID: enc$.encodeSimple("activityUUID", payload$.activityUUID, {
|
|
explode: false,
|
|
charEncoding: "percent",
|
|
}),
|
|
};
|
|
const path$ = this.templateURLComponent("/activities/{activityUUID}")(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: "cancelServerActivities",
|
|
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, 200)) {
|
|
// fallthrough
|
|
} else if (this.matchResponse(response, 401, "application/json")) {
|
|
const responseBody = await response.json();
|
|
const result = schemas$.parse(
|
|
responseBody,
|
|
(val$) => {
|
|
return errors.CancelServerActivitiesResponseBody$.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.CancelServerActivitiesResponse$.inboundSchema.parse(responseFields$),
|
|
"Response validation failed"
|
|
);
|
|
}
|
|
}
|