UNPKG

@kloutit/kloutit-sdk

Version:
127 lines (116 loc) 4.28 kB
/* tslint:disable */ /* eslint-disable */ /** * API Reference * The Kloutit API is organized around [REST](https://en.wikipedia.org/wiki/REST), it accepts and returns [JSON-encoded](https://www.json.org) bodies, returning standard [HTTP response codes](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes). You can interact with the API directly using your preferred HTTP/REST library. * * The version of the OpenAPI document: 2.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ import type { Configuration } from "./configuration"; import type { RequestArgs } from "./base"; import type { AxiosInstance, AxiosResponse } from 'axios'; import { RequiredError } from "./base"; /** * * @export */ export const DUMMY_BASE_URL = 'https://example.com' /** * * @throws {RequiredError} * @export */ export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) { if (paramValue === null || paramValue === undefined) { throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); } } /** * * @export */ export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) { if (configuration && configuration.apiKey) { const localVarApiKeyValue = await configuration.apiKey; object[keyParamName] = localVarApiKeyValue; } } function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { if (parameter == null) return; if (typeof parameter === "object") { if (Array.isArray(parameter)) { (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); } else { Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`) ); } } else { if (urlSearchParams.has(key)) { urlSearchParams.append(key, parameter); } else { urlSearchParams.set(key, parameter); } } } /** * * @export */ export const setSearchParams = function (url: URL, ...objects: any[]) { const searchParams = new URLSearchParams(url.search); setFlattenedQueryParams(searchParams, objects); url.search = searchParams.toString(); } /** * * @export */ export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) { const nonString = typeof value !== 'string'; const needsSerialization = nonString && configuration && isJsonMime ? isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization ? JSON.stringify(value !== undefined ? value : {}) : (value || ""); } /** * * @export */ export const toPathString = function (url: URL) { return url.pathname + url.search + url.hash } /** * * @export */ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url}; return axios.request<T, R>(axiosRequestArgs); }; } /** * Check if the given MIME is a JSON MIME. * JSON MIME examples: * application/json * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json * @param mime - MIME (Multipurpose Internet Mail Extensions) * @return True if the given MIME is JSON, false otherwise. */ export const isJsonMime = function (mime: string): boolean { const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); }