// 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 * as FormData from "form-data"; import { URLSearchParams } from 'url'; import {ObjectSerializer} from '../models/ObjectSerializer'; import {ApiException} from './exception'; import {canConsumeForm, isCodeInRange} from '../util'; import {SecurityAuthentication} from '../auth/auth'; import { SendSlackMessageRequest } from '../models/SendSlackMessageRequest'; import { SendSlackMessageResponse } from '../models/SendSlackMessageResponse'; /** * no description */ export class NotificationApiRequestFactory extends BaseAPIRequestFactory { /** * Send a Slack message * @param sendSlackMessageRequest Parameters of the message to send */ public async sendSlackNotification(sendSlackMessageRequest: SendSlackMessageRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'sendSlackMessageRequest' is not null or undefined if (sendSlackMessageRequest === null || sendSlackMessageRequest === undefined) { throw new RequiredError("NotificationApi", "sendSlackNotification", "sendSlackMessageRequest"); } // Path Params const localVarPath = '/notification/slack/send'; // 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(sendSlackMessageRequest, "SendSlackMessageRequest", ""), contentType ); requestContext.setBody(serializedBody); const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class NotificationApiResponseProcessor { /** * 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 sendSlackNotification * @throws ApiException if the response code was not in [200, 299] */ public async sendSlackNotificationWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: SendSlackMessageResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "SendSlackMessageResponse", "" ) as SendSlackMessageResponse; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } if (isCodeInRange("0", response.httpStatusCode)) { const body: Error = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "Error", "" ) as Error; throw new ApiException(response.httpStatusCode, "unexpected error", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: SendSlackMessageResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "SendSlackMessageResponse", "" ) as SendSlackMessageResponse; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }