EvaluationServiceApi.ts•11.4 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 { BatchEvaluationRequest } from '../models/BatchEvaluationRequest';
import { BatchEvaluationResponse } from '../models/BatchEvaluationResponse';
import { BooleanEvaluationResponse } from '../models/BooleanEvaluationResponse';
import { EvaluationRequest } from '../models/EvaluationRequest';
import { VariantEvaluationResponse } from '../models/VariantEvaluationResponse';
/**
* no description
*/
export class EvaluationServiceApiRequestFactory extends BaseAPIRequestFactory {
/**
* @param batchEvaluationRequest
*/
public async evaluateBatch(batchEvaluationRequest: BatchEvaluationRequest, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'batchEvaluationRequest' is not null or undefined
if (batchEvaluationRequest === null || batchEvaluationRequest === undefined) {
throw new RequiredError("EvaluationServiceApi", "evaluateBatch", "batchEvaluationRequest");
}
// Path Params
const localVarPath = '/evaluate/v1/batch';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(batchEvaluationRequest, "BatchEvaluationRequest", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* @param evaluationRequest
*/
public async evaluateBoolean(evaluationRequest: EvaluationRequest, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'evaluationRequest' is not null or undefined
if (evaluationRequest === null || evaluationRequest === undefined) {
throw new RequiredError("EvaluationServiceApi", "evaluateBoolean", "evaluationRequest");
}
// Path Params
const localVarPath = '/evaluate/v1/boolean';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(evaluationRequest, "EvaluationRequest", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* @param evaluationRequest
*/
public async evaluateVariant(evaluationRequest: EvaluationRequest, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'evaluationRequest' is not null or undefined
if (evaluationRequest === null || evaluationRequest === undefined) {
throw new RequiredError("EvaluationServiceApi", "evaluateVariant", "evaluationRequest");
}
// Path Params
const localVarPath = '/evaluate/v1/variant';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(evaluationRequest, "EvaluationRequest", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class EvaluationServiceApiResponseProcessor {
/**
* 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 evaluateBatch
* @throws ApiException if the response code was not in [200, 299]
*/
public async evaluateBatchWithHttpInfo(response: ResponseContext): Promise<HttpInfo<BatchEvaluationResponse >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: BatchEvaluationResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"BatchEvaluationResponse", ""
) as BatchEvaluationResponse;
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: BatchEvaluationResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"BatchEvaluationResponse", ""
) as BatchEvaluationResponse;
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 evaluateBoolean
* @throws ApiException if the response code was not in [200, 299]
*/
public async evaluateBooleanWithHttpInfo(response: ResponseContext): Promise<HttpInfo<BooleanEvaluationResponse >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: BooleanEvaluationResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"BooleanEvaluationResponse", ""
) as BooleanEvaluationResponse;
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: BooleanEvaluationResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"BooleanEvaluationResponse", ""
) as BooleanEvaluationResponse;
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 evaluateVariant
* @throws ApiException if the response code was not in [200, 299]
*/
public async evaluateVariantWithHttpInfo(response: ResponseContext): Promise<HttpInfo<VariantEvaluationResponse >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: VariantEvaluationResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"VariantEvaluationResponse", ""
) as VariantEvaluationResponse;
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: VariantEvaluationResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"VariantEvaluationResponse", ""
) as VariantEvaluationResponse;
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);
}
}