UNPKG

sleeper-api-tsclient

Version:

Typescript client for the sleeper api

181 lines (145 loc) 7.44 kB
// TODO: better import syntax? import { BaseAPIRequestFactory, RequiredError } from './baseapi'; import {Configuration} from '../configuration'; import { RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http'; import {ObjectSerializer} from '../models/ObjectSerializer'; import {ApiException} from './exception'; import {isCodeInRange} from '../util'; import { User } from '../models/User'; /** * no description */ export class UserApiRequestFactory extends BaseAPIRequestFactory { /** * Update an existing pet * @param userId The id of the user to get */ public async userUserIdGet(userId: string, options?: Configuration): Promise<RequestContext> { let config = options || this.configuration; // verify required parameter 'userId' is not null or undefined if (userId === null || userId === undefined) { throw new RequiredError('Required parameter userId was null or undefined when calling userUserIdGet.'); } // Path Params const localVarPath = '/user/{user_id}' .replace('{' + 'user_id' + '}', encodeURIComponent(String(userId))); // Make Request Context const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") // Query Params // Header Params // Form Params // Body Params // Apply auth methods return requestContext; } /** * Get user information * @param username The username to get */ public async userUsernameGet(username: string, options?: Configuration): Promise<RequestContext> { let config = options || this.configuration; // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { throw new RequiredError('Required parameter username was null or undefined when calling userUsernameGet.'); } // Path Params const localVarPath = '/user/{username}' .replace('{' + 'username' + '}', encodeURIComponent(String(username))); // Make Request Context const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") // Query Params // Header Params // Form Params // Body Params // Apply auth methods return requestContext; } } export class UserApiResponseProcessor { /** * 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 userUserIdGet * @throws ApiException if the response code was not in [200, 299] */ public async userUserIdGet(response: ResponseContext): Promise<User > { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: User = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "User", "" ) as User; return body; } if (isCodeInRange("400", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Bad Request -- Your request is invalid."); } if (isCodeInRange("404", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Not Found -- The specified kitten could not be found."); } if (isCodeInRange("429", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Too Many Requests -- You&#39;re requesting too many kittens! Slow down!"); } if (isCodeInRange("500", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Internal Server Error -- We had a problem with our server. Try again later."); } if (isCodeInRange("503", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Service Unavailable -- We&#39;re temporarily offline for maintenance. Please try again later."); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: User = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "User", "" ) as User; return body; } let body = response.body || ""; throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); } /** * 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 userUsernameGet * @throws ApiException if the response code was not in [200, 299] */ public async userUsernameGet(response: ResponseContext): Promise<User > { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: User = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "User", "" ) as User; return body; } if (isCodeInRange("400", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Bad Request -- Your request is invalid."); } if (isCodeInRange("404", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Not Found -- The specified kitten could not be found."); } if (isCodeInRange("429", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Too Many Requests -- You&#39;re requesting too many kittens! Slow down!"); } if (isCodeInRange("500", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Internal Server Error -- We had a problem with our server. Try again later."); } if (isCodeInRange("503", response.httpStatusCode)) { throw new ApiException<string>(response.httpStatusCode, "Service Unavailable -- We&#39;re temporarily offline for maintenance. Please try again later."); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: User = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "User", "" ) as User; return body; } let body = response.body || ""; throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); } }