UNPKG

twilio

Version:
343 lines (342 loc) 13.3 kB
"use strict"; /* * This code was generated by * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ * * Sample/reference Twilio API. * This is the reference API for the rest-proxy server. * * NOTE: This class is auto generated by OpenAPI Generator. * https://openapi-generator.tech * Do not edit the class manually. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InboundPage = exports.InboundInstance = exports.InboundContextImpl = exports.ReportMetadata = exports.ReportFilter = exports.PhoneNumberReportFilter = exports.InsightsV2InboundPhoneNumberReportCallStatePercentage = exports.InsightsV2CreatePhoneNumbersReportRequestTimeRange = exports.InsightsV2CreatePhoneNumbersReportRequest = void 0; exports.InboundListInstance = InboundListInstance; const util_1 = require("util"); const Page_1 = __importDefault(require("../../../base/Page")); const deserialize = require("../../../base/deserialize"); const serialize = require("../../../base/serialize"); const utility_1 = require("../../../base/utility"); class InsightsV2CreatePhoneNumbersReportRequest { constructor(payload) { this.timeRange = payload["time_range"]; this.filters = payload["filters"]; this.size = payload["size"]; } } exports.InsightsV2CreatePhoneNumbersReportRequest = InsightsV2CreatePhoneNumbersReportRequest; class InsightsV2CreatePhoneNumbersReportRequestTimeRange { constructor(payload) { this.startDatetime = payload["start_datetime"]; this.endDatetime = payload["end_datetime"]; } } exports.InsightsV2CreatePhoneNumbersReportRequestTimeRange = InsightsV2CreatePhoneNumbersReportRequestTimeRange; /** * Percentage of calls made in each state. */ class InsightsV2InboundPhoneNumberReportCallStatePercentage { constructor(payload) { this.completed = payload["completed"]; this.fail = payload["fail"]; this.busy = payload["busy"]; this.noanswer = payload["noanswer"]; this.canceled = payload["canceled"]; } } exports.InsightsV2InboundPhoneNumberReportCallStatePercentage = InsightsV2InboundPhoneNumberReportCallStatePercentage; class PhoneNumberReportFilter { constructor(payload) { this.key = payload["key"]; this.values = payload["values"]; } } exports.PhoneNumberReportFilter = PhoneNumberReportFilter; class ReportFilter { constructor(payload) { this.key = payload["key"]; this.values = payload["values"]; } } exports.ReportFilter = ReportFilter; class ReportMetadata { constructor(payload) { this.startDatetime = payload["start_datetime"]; this.endDatetime = payload["end_datetime"]; this.filters = payload["filters"]; } } exports.ReportMetadata = ReportMetadata; class InboundContextImpl { constructor(_version, reportId) { this._version = _version; if (!(0, utility_1.isValidPathParam)(reportId)) { throw new Error("Parameter 'reportId' is not valid."); } this._solution = { reportId }; this._uri = `/Voice/Reports/PhoneNumbers/Inbound`; } create(params, headers, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.create({ uri: instance._uri, method: "post", data, headers, }); operationPromise = operationPromise.then((payload) => new InboundInstance(operationVersion, payload, instance._solution.reportId)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } createWithHttpInfo(params, headers, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version; // CREATE, FETCH, UPDATE operations let operationPromise = operationVersion .createWithResponseInfo({ uri: instance._uri, method: "post", data, headers, }) .then((response) => ({ ...response, body: new InboundInstance(operationVersion, response.body, instance._solution.reportId), })); 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.InboundContextImpl = InboundContextImpl; class InboundInstance { constructor(_version, payload, reportId) { this._version = _version; this.accountSid = payload.account_sid; this.reportId = payload.report_id; this.status = payload.status; this.requestMeta = payload.request_meta !== null && payload.request_meta !== undefined ? new ReportMetadata(payload.request_meta) : null; this.url = payload.url; this.handle = payload.handle; this.totalCalls = deserialize.integer(payload.total_calls); this.callAnswerScore = payload.call_answer_score; this.callStatePercentage = payload.call_state_percentage !== null && payload.call_state_percentage !== undefined ? new InsightsV2InboundPhoneNumberReportCallStatePercentage(payload.call_state_percentage) : null; this.silentCallsPercentage = payload.silent_calls_percentage; this._solution = { reportId: reportId || this.reportId }; } get _proxy() { this._context = this._context || new InboundContextImpl(this._version, this._solution.reportId); return this._context; } create(params, callback) { return this._proxy.create(params, callback); } createWithHttpInfo(params, callback) { return this._proxy.createWithHttpInfo(params, callback); } /** * Provide a user-friendly representation * * @returns Object */ toJSON() { return { accountSid: this.accountSid, reportId: this.reportId, status: this.status, requestMeta: this.requestMeta, url: this.url, handle: this.handle, totalCalls: this.totalCalls, callAnswerScore: this.callAnswerScore, callStatePercentage: this.callStatePercentage, silentCallsPercentage: this.silentCallsPercentage, }; } [util_1.inspect.custom](_depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.InboundInstance = InboundInstance; function InboundListInstance(version, reportId) { if (!(0, utility_1.isValidPathParam)(reportId)) { throw new Error("Parameter 'reportId' is not valid."); } const instance = ((reportId) => instance.get(reportId)); instance.get = function get(reportId) { return new InboundContextImpl(version, reportId); }; instance._version = version; instance._solution = { reportId }; instance._uri = `/Voice/Reports/PhoneNumbers/Inbound/${reportId}`; instance.page = function page(params, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; if (params["pageSize"] !== undefined) data["PageSize"] = params["pageSize"]; if (params.pageNumber !== undefined) data["Page"] = params.pageNumber; if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; const headers = {}; headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.page({ uri: instance._uri, method: "get", params: data, headers, }); operationPromise = operationPromise.then((payload) => new InboundPage(operationVersion, payload, instance._solution)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.each = instance._version.each; instance.list = instance._version.list; instance.getPage = function getPage(targetUrl, callback) { const operationPromise = instance._version._domain.twilio.request({ method: "get", uri: targetUrl, }); let pagePromise = operationPromise.then((payload) => new InboundPage(instance._version, payload, instance._solution)); pagePromise = instance._version.setPromiseCallback(pagePromise, callback); return pagePromise; }; instance.pageWithHttpInfo = function pageWithHttpInfo(params, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; if (params["pageSize"] !== undefined) data["PageSize"] = params["pageSize"]; if (params.pageNumber !== undefined) data["Page"] = params.pageNumber; if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; const headers = {}; headers["Accept"] = "application/json"; let operationVersion = version; // For page operations, use page() directly as it already returns { statusCode, body, headers } // IMPORTANT: Pass full response to Page constructor, not response.body let operationPromise = operationVersion .page({ uri: instance._uri, method: "get", params: data, headers }) .then((response) => ({ statusCode: response.statusCode, headers: response.headers, body: new InboundPage(operationVersion, response, instance._solution), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.each = instance._version.each; instance.eachWithHttpInfo = instance._version.eachWithHttpInfo; instance.list = instance._version.list; instance.listWithHttpInfo = instance._version.listWithHttpInfo; instance.getPageWithHttpInfo = function getPageWithHttpInfo(targetUrl, callback) { // Use request() directly as it already returns { statusCode, body, headers } const operationPromise = instance._version._domain.twilio.request({ method: "get", uri: targetUrl, }); let pagePromise = operationPromise.then((response) => ({ statusCode: response.statusCode, headers: response.headers, body: new InboundPage(instance._version, response, instance._solution), })); pagePromise = instance._version.setPromiseCallback(pagePromise, callback); return pagePromise; }; 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; } class InboundPage extends Page_1.default { /** * Initialize the InboundPage * * @param version - Version of the resource * @param response - Response from the API * @param solution - Path solution */ constructor(version, response, solution) { super(version, response, solution); } /** * Build an instance of InboundInstance * * @param payload - Payload response from the API */ getInstance(payload) { return new InboundInstance(this._version, payload, this._solution.reportId); } [util_1.inspect.custom](depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.InboundPage = InboundPage;