twilio
Version:
A Twilio helper library
176 lines (175 loc) • 6.27 kB
JavaScript
"use strict";
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio Knowledge API
* APIs for managing knowledge bases and knowledge content for AI-powered applications.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperationInstance = exports.OperationContextImpl = exports.OperationStatusError = exports.OperationResultResourceId = void 0;
exports.OperationListInstance = OperationListInstance;
const util_1 = require("util");
const deserialize = require("../../../base/deserialize");
const serialize = require("../../../base/serialize");
const utility_1 = require("../../../base/utility");
class OperationResultResourceId {
constructor(payload) {
this.type = payload["type"];
this.id = payload["id"];
}
}
exports.OperationResultResourceId = OperationResultResourceId;
class OperationStatusError {
constructor(payload) {
this.type = payload["type"];
this.title = payload["title"];
this.code = payload["code"];
this.detail = payload["detail"];
}
}
exports.OperationStatusError = OperationStatusError;
class OperationContextImpl {
constructor(_version, operationId) {
this._version = _version;
if (!(0, utility_1.isValidPathParam)(operationId)) {
throw new Error("Parameter 'operationId' is not valid.");
}
this._solution = { operationId };
this._uri = `/ControlPlane/Operations/${operationId}`;
}
fetch(callback) {
const headers = {};
headers["Accept"] = "application/json";
const instance = this;
let operationVersion = instance._version, operationPromise = operationVersion.fetch({
uri: instance._uri,
method: "get",
headers,
});
operationPromise = operationPromise.then((payload) => new OperationInstance(operationVersion, payload, instance._solution.operationId));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
fetchWithHttpInfo(callback) {
const headers = {};
headers["Accept"] = "application/json";
const instance = this;
let operationVersion = instance._version;
// CREATE, FETCH, UPDATE operations
let operationPromise = operationVersion
.fetchWithResponseInfo({
uri: instance._uri,
method: "get",
headers,
})
.then((response) => ({
...response,
body: new OperationInstance(operationVersion, response.body, instance._solution.operationId),
}));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
/**
* Provide a user-friendly representation
*
* @returns Object
*/
toJSON() {
return this._solution;
}
[util_1.inspect.custom](_depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.OperationContextImpl = OperationContextImpl;
class OperationInstance {
constructor(_version, _payload, operationId) {
this._version = _version;
const payload = _payload;
this.operationId = payload.operationId;
this.status = payload.status;
this.createdAt = deserialize.iso8601DateTime(payload.createdAt);
this.statusUrl = payload.statusUrl;
this.completedAt = deserialize.iso8601DateTime(payload.completedAt);
this.result =
payload.result !== null && payload.result !== undefined
? new OperationResultResourceId(payload.result)
: null;
this.error =
payload.error !== null && payload.error !== undefined
? new OperationStatusError(payload.error)
: null;
this.resultUrl = payload.resultUrl;
this._solution = { operationId: operationId };
}
get _proxy() {
this._context =
this._context ||
new OperationContextImpl(this._version, this._solution.operationId);
return this._context;
}
/**
* Fetch a OperationInstance
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed OperationInstance
*/
fetch(callback) {
return this._proxy.fetch(callback);
}
/**
* Fetch a OperationInstance and return HTTP info
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed OperationInstance with HTTP metadata
*/
fetchWithHttpInfo(callback) {
return this._proxy.fetchWithHttpInfo(callback);
}
/**
* Provide a user-friendly representation
*
* @returns Object
*/
toJSON() {
return {
operationId: this.operationId,
status: this.status,
createdAt: this.createdAt,
statusUrl: this.statusUrl,
completedAt: this.completedAt,
result: this.result,
error: this.error,
resultUrl: this.resultUrl,
};
}
[util_1.inspect.custom](_depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.OperationInstance = OperationInstance;
function OperationListInstance(version) {
const instance = ((operationId) => instance.get(operationId));
instance.get = function get(operationId) {
return new OperationContextImpl(version, operationId);
};
instance._version = version;
instance._solution = {};
instance._uri = ``;
instance.toJSON = function toJSON() {
return instance._solution;
};
instance[util_1.inspect.custom] = function inspectImpl(_depth, options) {
return (0, util_1.inspect)(instance.toJSON(), options);
};
return instance;
}