@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
80 lines (79 loc) • 5.46 kB
JavaScript
// TODO: better import syntax?
import { BaseAPIRequestFactory } from './baseapi.js';
import { HttpMethod, HttpInfo } from '../http/http.js';
import { ObjectSerializer } from '../models/ObjectSerializer.js';
import { ApiException } from './exception.js';
import { isCodeInRange } from '../util.js';
/**
* no description
*/
export class CallsApiRequestFactory extends BaseAPIRequestFactory {
/**
* Paginate through all calls in Affinity. Returns basic information about the call interaction and its participants. Will only return calls that the current authenticated user has permission to see. You can filter calls using the `filter` query parameter. The filter parameter is a string that you can specify conditions based on the following properties. | **Property Name** | **Description** | **Type** | **Allowed Operators** | **Examples** | |-----------------------------|-----------------------------------------------------------------|------------|--------------------------------------|----------------------------------| | `id` | Unique identifier for Calls | `int64` | `=` | `id=1` | | `startTime` | Start time of when the Call was held | `datetime` | `>`, `<`, `>=`, `<=` | `sentAt>2025-01-01T01:00:00Z` | | `createdAt` | When the Call was created in Affinity | `datetime` | `>`, `<`, `>=`, `<=` | `createdAt<2025-01-01T01:00:00Z` | | `updatedAt` | When the Call was updated in Affinity | `datetime` | `>`, `<`, `>=`, `<=` | `updatedAt>=2025-01-01T01:00:00Z`|
* Get metadata on all Calls
* @param cursor Cursor for the next or previous page
* @param limit Number of items to include in the page
* @param filter Filter options
*/
async v2CallsGET(cursor, limit, filter, _options) {
let _config = _options || this.configuration;
// Path Params
const localVarPath = '/v2/calls';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
// Query Params
if (cursor !== undefined) {
requestContext.setQueryParam("cursor", ObjectSerializer.serialize(cursor, "string", ""));
}
// Query Params
if (limit !== undefined) {
requestContext.setQueryParam("limit", ObjectSerializer.serialize(limit, "number", "int32"));
}
// Query Params
if (filter !== undefined) {
requestContext.setQueryParam("filter", ObjectSerializer.serialize(filter, "string", ""));
}
let authMethod;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"];
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth = _config?.authMethods?.default;
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class CallsApiResponseProcessor {
/**
* 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 v2CallsGET
* @throws ApiException if the response code was not in [200, 299]
*/
async v2CallsGETWithHttpInfo(response) {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "InteractionsCallPaged", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("400", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Responses400", "");
throw new ApiException(response.httpStatusCode, "Bad Request", body, response.headers);
}
if (isCodeInRange("0", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Errors", "");
throw new ApiException(response.httpStatusCode, "Errors", body, response.headers);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "InteractionsCallPaged", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
}