Files
discoursejs/src/sdk/topics.ts

1103 lines
39 KiB
TypeScript

/*
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
*/
import * as utils from "../internal/utils";
import * as errors from "../sdk/models/errors";
import * as operations from "../sdk/models/operations";
import * as shared from "../sdk/models/shared";
import { SDKConfiguration } from "./sdk";
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from "axios";
export class Topics {
private sdkConfiguration: SDKConfiguration;
constructor(sdkConfig: SDKConfiguration) {
this.sdkConfiguration = sdkConfig;
}
/**
* Bookmark topic
*/
async bookmarkTopic(
apiKey: string,
apiUsername: string,
id: string,
config?: AxiosRequestConfig
): Promise<operations.BookmarkTopicResponse> {
const req = new operations.BookmarkTopicRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/{id}/bookmark.json", req);
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...config?.headers,
...properties.headers,
};
headers["Accept"] = "*/*";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "put",
headers: headers,
responseType: "arraybuffer",
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.BookmarkTopicResponse = new operations.BookmarkTopicResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
switch (true) {
case httpRes?.status == 200:
break;
}
return res;
}
/**
* Creates a new topic, a new post, or a private message
*/
async createTopicPostPM(
req: operations.CreateTopicPostPMRequestBody,
config?: AxiosRequestConfig
): Promise<operations.CreateTopicPostPMResponse> {
if (!(req instanceof utils.SpeakeasyBase)) {
req = new operations.CreateTopicPostPMRequestBody(req);
}
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = baseURL.replace(/\/$/, "") + "/posts.json";
let [reqBodyHeaders, reqBody]: [object, any] = [{}, null];
try {
[reqBodyHeaders, reqBody] = utils.serializeRequestBody(req, "request", "json");
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Error serializing request body, cause: ${e.message}`);
}
}
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...reqBodyHeaders,
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "post",
headers: headers,
responseType: "arraybuffer",
data: reqBody,
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.CreateTopicPostPMResponse = new operations.CreateTopicPostPMResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.CreateTopicPostPMResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Create topic timer
*/
async createTopicTimer(
apiKey: string,
apiUsername: string,
id: string,
requestBody?: operations.CreateTopicTimerRequestBody,
config?: AxiosRequestConfig
): Promise<operations.CreateTopicTimerResponse> {
const req = new operations.CreateTopicTimerRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
requestBody: requestBody,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/{id}/timer.json", req);
let [reqBodyHeaders, reqBody]: [object, any] = [{}, null];
try {
[reqBodyHeaders, reqBody] = utils.serializeRequestBody(req, "requestBody", "json");
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Error serializing request body, cause: ${e.message}`);
}
}
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...reqBodyHeaders,
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "post",
headers: headers,
responseType: "arraybuffer",
data: reqBody,
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.CreateTopicTimerResponse = new operations.CreateTopicTimerResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.CreateTopicTimerResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Get a single topic
*/
async getTopic(
apiKey: string,
apiUsername: string,
id: string,
config?: AxiosRequestConfig
): Promise<operations.GetTopicResponse> {
const req = new operations.GetTopicRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/{id}.json", req);
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "get",
headers: headers,
responseType: "arraybuffer",
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.GetTopicResponse = new operations.GetTopicResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.GetTopicResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Get topic by external_id
*/
async getTopicByExternalId(
externalId: string,
config?: AxiosRequestConfig
): Promise<operations.GetTopicByExternalIdResponse> {
const req = new operations.GetTopicByExternalIdRequest({
externalId: externalId,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(
baseURL,
"/t/external_id/{external_id}.json",
req
);
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = { ...config?.headers, ...properties.headers };
headers["Accept"] = "*/*";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "get",
headers: headers,
responseType: "arraybuffer",
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.GetTopicByExternalIdResponse =
new operations.GetTopicByExternalIdResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
switch (true) {
case httpRes?.status == 301:
break;
}
return res;
}
/**
* Invite to topic
*/
async inviteToTopic(
apiKey: string,
apiUsername: string,
id: string,
requestBody?: operations.InviteToTopicRequestBody,
config?: AxiosRequestConfig
): Promise<operations.InviteToTopicResponse> {
const req = new operations.InviteToTopicRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
requestBody: requestBody,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/{id}/invite.json", req);
let [reqBodyHeaders, reqBody]: [object, any] = [{}, null];
try {
[reqBodyHeaders, reqBody] = utils.serializeRequestBody(req, "requestBody", "json");
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Error serializing request body, cause: ${e.message}`);
}
}
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...reqBodyHeaders,
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "post",
headers: headers,
responseType: "arraybuffer",
data: reqBody,
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.InviteToTopicResponse = new operations.InviteToTopicResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.InviteToTopicResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Get the latest topics
*/
async listLatestTopics(
apiKey: string,
apiUsername: string,
ascending?: string,
order?: string,
config?: AxiosRequestConfig
): Promise<operations.ListLatestTopicsResponse> {
const req = new operations.ListLatestTopicsRequest({
apiKey: apiKey,
apiUsername: apiUsername,
ascending: ascending,
order: order,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = baseURL.replace(/\/$/, "") + "/latest.json";
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...config?.headers,
...properties.headers,
};
const queryParams: string = utils.serializeQueryParams(req);
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl + queryParams,
method: "get",
headers: headers,
responseType: "arraybuffer",
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.ListLatestTopicsResponse = new operations.ListLatestTopicsResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.ListLatestTopicsResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Get the top topics filtered by period
*/
async listTopTopics(
apiKey: string,
apiUsername: string,
period?: string,
config?: AxiosRequestConfig
): Promise<operations.ListTopTopicsResponse> {
const req = new operations.ListTopTopicsRequest({
apiKey: apiKey,
apiUsername: apiUsername,
period: period,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = baseURL.replace(/\/$/, "") + "/top.json";
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...config?.headers,
...properties.headers,
};
const queryParams: string = utils.serializeQueryParams(req);
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl + queryParams,
method: "get",
headers: headers,
responseType: "arraybuffer",
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.ListTopTopicsResponse = new operations.ListTopTopicsResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.ListTopTopicsResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Remove a topic
*/
async removeTopic(
apiKey: string,
apiUsername: string,
id: string,
config?: AxiosRequestConfig
): Promise<operations.RemoveTopicResponse> {
const req = new operations.RemoveTopicRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/{id}.json", req);
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...config?.headers,
...properties.headers,
};
headers["Accept"] = "*/*";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "delete",
headers: headers,
responseType: "arraybuffer",
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.RemoveTopicResponse = new operations.RemoveTopicResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
switch (true) {
case httpRes?.status == 200:
break;
}
return res;
}
/**
* Set notification level
*/
async setNotificationLevel(
apiKey: string,
apiUsername: string,
id: string,
requestBody?: operations.SetNotificationLevelRequestBody,
config?: AxiosRequestConfig
): Promise<operations.SetNotificationLevelResponse> {
const req = new operations.SetNotificationLevelRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
requestBody: requestBody,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/{id}/notifications.json", req);
let [reqBodyHeaders, reqBody]: [object, any] = [{}, null];
try {
[reqBodyHeaders, reqBody] = utils.serializeRequestBody(req, "requestBody", "json");
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Error serializing request body, cause: ${e.message}`);
}
}
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...reqBodyHeaders,
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "post",
headers: headers,
responseType: "arraybuffer",
data: reqBody,
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.SetNotificationLevelResponse =
new operations.SetNotificationLevelResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.SetNotificationLevelResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Update a topic
*/
async updateTopic(
apiKey: string,
apiUsername: string,
id: string,
requestBody?: operations.UpdateTopicRequestBody,
config?: AxiosRequestConfig
): Promise<operations.UpdateTopicResponse> {
const req = new operations.UpdateTopicRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
requestBody: requestBody,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/-/{id}.json", req);
let [reqBodyHeaders, reqBody]: [object, any] = [{}, null];
try {
[reqBodyHeaders, reqBody] = utils.serializeRequestBody(req, "requestBody", "json");
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Error serializing request body, cause: ${e.message}`);
}
}
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...reqBodyHeaders,
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "put",
headers: headers,
responseType: "arraybuffer",
data: reqBody,
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.UpdateTopicResponse = new operations.UpdateTopicResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.UpdateTopicResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Update the status of a topic
*/
async updateTopicStatus(
apiKey: string,
apiUsername: string,
id: string,
requestBody?: operations.UpdateTopicStatusRequestBody,
config?: AxiosRequestConfig
): Promise<operations.UpdateTopicStatusResponse> {
const req = new operations.UpdateTopicStatusRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
requestBody: requestBody,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(baseURL, "/t/{id}/status.json", req);
let [reqBodyHeaders, reqBody]: [object, any] = [{}, null];
try {
[reqBodyHeaders, reqBody] = utils.serializeRequestBody(req, "requestBody", "json");
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Error serializing request body, cause: ${e.message}`);
}
}
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...reqBodyHeaders,
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "put",
headers: headers,
responseType: "arraybuffer",
data: reqBody,
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.UpdateTopicStatusResponse = new operations.UpdateTopicStatusResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.UpdateTopicStatusResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
/**
* Update topic timestamp
*/
async updateTopicTimestamp(
apiKey: string,
apiUsername: string,
id: string,
requestBody?: operations.UpdateTopicTimestampRequestBody,
config?: AxiosRequestConfig
): Promise<operations.UpdateTopicTimestampResponse> {
const req = new operations.UpdateTopicTimestampRequest({
apiKey: apiKey,
apiUsername: apiUsername,
id: id,
requestBody: requestBody,
});
const baseURL: string = utils.templateUrl(
this.sdkConfiguration.serverURL,
this.sdkConfiguration.serverDefaults
);
const operationUrl: string = utils.generateURL(
baseURL,
"/t/{id}/change-timestamp.json",
req
);
let [reqBodyHeaders, reqBody]: [object, any] = [{}, null];
try {
[reqBodyHeaders, reqBody] = utils.serializeRequestBody(req, "requestBody", "json");
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Error serializing request body, cause: ${e.message}`);
}
}
const client: AxiosInstance = this.sdkConfiguration.defaultClient;
let globalSecurity = this.sdkConfiguration.security;
if (typeof globalSecurity === "function") {
globalSecurity = await globalSecurity();
}
if (!(globalSecurity instanceof utils.SpeakeasyBase)) {
globalSecurity = new shared.Security(globalSecurity);
}
const properties = utils.parseSecurityProperties(globalSecurity);
const headers: RawAxiosRequestHeaders = {
...utils.getHeadersFromRequest(req),
...reqBodyHeaders,
...config?.headers,
...properties.headers,
};
headers["Accept"] = "application/json";
headers["user-agent"] = this.sdkConfiguration.userAgent;
const httpRes: AxiosResponse = await client.request({
validateStatus: () => true,
url: operationUrl,
method: "put",
headers: headers,
responseType: "arraybuffer",
data: reqBody,
...config,
});
const responseContentType: string = httpRes?.headers?.["content-type"] ?? "";
if (httpRes?.status == null) {
throw new Error(`status code not found in response: ${httpRes}`);
}
const res: operations.UpdateTopicTimestampResponse =
new operations.UpdateTopicTimestampResponse({
statusCode: httpRes.status,
contentType: responseContentType,
rawResponse: httpRes,
});
const decodedRes = new TextDecoder().decode(httpRes?.data);
switch (true) {
case httpRes?.status == 200:
if (utils.matchContentType(responseContentType, `application/json`)) {
res.object = utils.objectToClass(
JSON.parse(decodedRes),
operations.UpdateTopicTimestampResponseBody
);
} else {
throw new errors.SDKError(
"unknown content-type received: " + responseContentType,
httpRes.status,
decodedRes,
httpRes
);
}
break;
}
return res;
}
}