UNPKG

@openweb3-io/dex-aggregator

Version:

dex-aggregator API client and webhook verification library

100 lines (79 loc) 4.42 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 { TokenGainersPage } from '../models/TokenGainersPage'; /** * no description */ export class TokenRankingsApiRequestFactory extends BaseAPIRequestFactory { /** * CONTROLLER.TOKEN_RANKING.GAINERS.DESCRIPTION * CONTROLLER.TOKEN_RANKING.GAINERS.SUMMARY * @param chain GLOBAL.CHAIN.DESCRIPTION * @param tokenAddress GLOBAL.TOKENADDRESS.DESCRIPTION */ public async getGainers(chain: 'sol' | 'base', tokenAddress: string, _options?: Configuration): Promise<RequestContext> { let _config = _options || this.configuration; // verify required parameter 'chain' is not null or undefined if (chain === null || chain === undefined) { throw new RequiredError("TokenRankingsApi", "getGainers", "chain"); } // verify required parameter 'tokenAddress' is not null or undefined if (tokenAddress === null || tokenAddress === undefined) { throw new RequiredError("TokenRankingsApi", "getGainers", "tokenAddress"); } // Path Params const localVarPath = '/ranking/{chain}/{tokenAddress}/gainers' .replace('{' + 'chain' + '}', encodeURIComponent(String(chain))) .replace('{' + 'tokenAddress' + '}', encodeURIComponent(String(tokenAddress))); // 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()) let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearer"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class TokenRankingsApiResponseProcessor { /** * 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 getGainers * @throws ApiException if the response code was not in [200, 299] */ public async getGainersWithHttpInfo(response: ResponseContext): Promise<HttpInfo<Array<TokenGainersPage> >> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: Array<TokenGainersPage> = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "Array<TokenGainersPage>", "" ) as Array<TokenGainersPage>; 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: Array<TokenGainersPage> = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "Array<TokenGainersPage>", "" ) as Array<TokenGainersPage>; 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); } }