UNPKG

@openweb3-io/dex-aggregator

Version:

dex-aggregator API client and webhook verification library

170 lines (133 loc) 7.21 kB
// TODO: better import syntax? import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi'; import {Configuration} from '../configuration'; import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http'; import {ObjectSerializer} from '../models/ObjectSerializer'; import {ApiException} from './exception'; import {canConsumeForm, isCodeInRange} from '../util'; import {SecurityAuthentication} from '../auth/auth'; import { BlockchainDTO } from '../models/BlockchainDTO'; import { BlockchainPage } from '../models/BlockchainPage'; /** * no description */ export class BlockchainApiRequestFactory extends BaseAPIRequestFactory { /** * Retrieve information about a specific blockchain. * Blockchain - Detail * @param symbol A chain name listed in supported networks */ public async blockchainGet(symbol: string, _options?: Configuration): Promise<RequestContext> { let _config = _options || this.configuration; // verify required parameter 'symbol' is not null or undefined if (symbol === null || symbol === undefined) { throw new RequiredError("BlockchainApi", "blockchainGet", "symbol"); } // Path Params const localVarPath = '/blockchain/{symbol}' .replace('{' + 'symbol' + '}', encodeURIComponent(String(symbol))); // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") const randomId = Math.floor(Math.random() * Math.pow(2, 32)) requestContext.setHeaderParam("x-req-id", randomId.toString()) const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Fetch information about all supported blockchains. * Blockchain - List * @param orderBy Sort field * @param sort Sort type * @param cursor Pagination cursor * @param limit Number of results per page */ public async blockchainList(orderBy?: 'name' | 'symbol', sort?: 'asc' | 'desc', cursor?: string, limit?: number, _options?: Configuration): Promise<RequestContext> { let _config = _options || this.configuration; // Path Params const localVarPath = '/blockchain'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") const randomId = Math.floor(Math.random() * Math.pow(2, 32)) requestContext.setHeaderParam("x-req-id", randomId.toString()) // Query Params if (orderBy !== undefined) { requestContext.setQueryParam("orderBy", ObjectSerializer.serialize(orderBy, "'name' | 'symbol'", "")); } // Query Params if (sort !== undefined) { requestContext.setQueryParam("sort", ObjectSerializer.serialize(sort, "'asc' | 'desc'", "")); } // Query Params if (cursor !== undefined) { requestContext.setQueryParam("cursor", ObjectSerializer.serialize(cursor, "string", "")); } // Query Params if (limit !== undefined) { requestContext.setQueryParam("limit", ObjectSerializer.serialize(limit, "number", "")); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class BlockchainApiResponseProcessor { /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to blockchainGet * @throws ApiException if the response code was not in [200, 299] */ public async blockchainGetWithHttpInfo(response: ResponseContext): Promise<HttpInfo<BlockchainDTO >> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: BlockchainDTO = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "BlockchainDTO", "" ) as BlockchainDTO; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: BlockchainDTO = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "BlockchainDTO", "" ) as BlockchainDTO; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to blockchainList * @throws ApiException if the response code was not in [200, 299] */ public async blockchainListWithHttpInfo(response: ResponseContext): Promise<HttpInfo<BlockchainPage >> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: BlockchainPage = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "BlockchainPage", "" ) as BlockchainPage; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: BlockchainPage = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "BlockchainPage", "" ) as BlockchainPage; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }