// 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 { SendBulkMailRequest } from '../models/SendBulkMailRequest'; import { SendBulkMailResponse } from '../models/SendBulkMailResponse'; import { SendMailRequest } from '../models/SendMailRequest'; import { SendMailResponse } from '../models/SendMailResponse'; /** * no description */ export class EmailApiRequestFactory extends BaseAPIRequestFactory { /** * Send a batch of multiple emails to individual recipients with the same content. Note that if cc or bcc address are provided, each email sent will also be sent to any addresses in these lists. Note that it is possible for only a subset of these to fail * @param sendBulkMailRequest Parameters of the messages to send */ public async sendBulk(sendBulkMailRequest: SendBulkMailRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'sendBulkMailRequest' is not null or undefined if (sendBulkMailRequest === null || sendBulkMailRequest === undefined) { throw new RequiredError("EmailApi", "sendBulk", "sendBulkMailRequest"); } // Path Params const localVarPath = '/email/sendBulk'; // 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(sendBulkMailRequest, "SendBulkMailRequest", ""), contentType ); requestContext.setBody(serializedBody); const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Send a single email. Note that if multiple to addresses are provided it will still only send a single email with multiple addresses in the to field. To send multiple emails to individual addresses, see the sendBulk endpoint. * @param sendMailRequest Parameters of the message to send */ public async sendEmail(sendMailRequest: SendMailRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'sendMailRequest' is not null or undefined if (sendMailRequest === null || sendMailRequest === undefined) { throw new RequiredError("EmailApi", "sendEmail", "sendMailRequest"); } // Path Params const localVarPath = '/email/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(sendMailRequest, "SendMailRequest", ""), 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 EmailApiResponseProcessor { /** * 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 sendBulk * @throws ApiException if the response code was not in [200, 299] */ public async sendBulkWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: SendBulkMailResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "SendBulkMailResponse", "" ) as SendBulkMailResponse; 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: SendBulkMailResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "SendBulkMailResponse", "" ) as SendBulkMailResponse; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(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 sendEmail * @throws ApiException if the response code was not in [200, 299] */ public async sendEmailWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: SendMailResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "SendMailResponse", "" ) as SendMailResponse; 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: SendMailResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "SendMailResponse", "" ) as SendMailResponse; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }