From 47bacf2bc45c3d60ae839f83782c6881dec99e95 Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Fri, 3 Dec 2021 17:02:35 +0530 Subject: [PATCH 1/9] added support for hostedMessagingNumber and LOA --- lib/resources/hostedMessagingNumber.js | 222 +++++++++++++++++++ lib/resources/loa.js | 234 +++++++++++++++++++++ lib/rest/client.js | 7 +- types/resources/hostedMessagingNumber.d.ts | 123 +++++++++++ types/resources/loa.d.ts | 134 ++++++++++++ types/rest/client.d.ts | 6 +- 6 files changed, 724 insertions(+), 2 deletions(-) create mode 100644 lib/resources/hostedMessagingNumber.js create mode 100644 lib/resources/loa.js create mode 100644 types/resources/hostedMessagingNumber.d.ts create mode 100644 types/resources/loa.d.ts diff --git a/lib/resources/hostedMessagingNumber.js b/lib/resources/hostedMessagingNumber.js new file mode 100644 index 00000000..8f2ece93 --- /dev/null +++ b/lib/resources/hostedMessagingNumber.js @@ -0,0 +1,222 @@ +import { + PlivoResource, PlivoResourceInterface +} from '../base'; +import { + extend, validate +} from '../utils/common.js'; + +const clientKey = Symbol(); +const action = 'HostedMessagingNumber/'; +const idField = 'hosted_messaging_number_id'; + +export class HostedMessagingNumberResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.application = params.application + this.failureReason = params.failureReason + this.file = params.file; + this.hostedMessagingNumberId = params.hostedMessagingNumberId; + this.loaId = params.loaId; + this.number = params.number; + this.hostedStatus = params.hostedStatus; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class CreateHostedMessagingNumberResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.application = params.application + this.failureReason = params.failureReason + this.file = params.file; + this.hostedMessagingNumberId = params.hostedMessagingNumberId; + this.loaId = params.loaId; + this.number = params.number; + this.hostedStatus = params.hostedStatus; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class ListHostedMessagingNumberResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.meta = params.metaResponse; + this.objects = params.objects; + } +} + + +export class HostedMessagingNumber extends PlivoResource { + constructor(client, data = {}) { + super(action, HostedMessagingNumber, idField, client); + if (idField in data) { + this.id = data[idField]; + } + this[clientKey] = client; + extend(this, data); + } + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the HostedMessagingNumber + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + if (action !== '' && !id) { + reject(new Error(this[idKey] + ' must be set')); + } + client('GET', action + (id ? id + '/' : '')) + .then(response => { + let object = new HostedMessagingNumberResponse(response.body, client); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + * @fail {Error} return Error + */ + list(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + client('GET', action, params) + .then(response => { + resolve(new ListHostedMessagingNumberResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.applicationId] - Application ID + * @param {string} [params.number] - Phone Number + * @param {string} [params.applicationId] - LOA ID + * @fail {Error} return Error + */ + create(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + params.multipart = true; + client('POST', action, params) + .then(response => { + let object = new CreateHostedMessagingNumberResponse(response.body, idField); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }) + } +} + +/** + * Represents a HostedMessagingNumber interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class HostedMessagingNumberInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(action, HostedMessagingNumber, idField, client); + extend(this, data); + this[clientKey] = client; + } + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the HostedMessagingNumber + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id) { + let errors = validate([{field: 'id', value: id, validators: ['isRequired', 'isString']},]); + if (errors) { + return errors; + } + return new HostedMessagingNumber(this[clientKey], {id: idField}).get(id) + } + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + * @fail {Error} return Error + */ + list(params = {}) { + const validations = [] + if (params.hasOwnProperty("alias")) { + validations.push({field: 'alias', value: params.alias, validators: ['isString']}) + } + if (params.hasOwnProperty("hostedStatus")) { + validations.push({field: 'hostedStatus', value: params.hostedStatus, validators: ['isString']}) + } + if (params.hasOwnProperty("number")) { + validations.push({field: 'number', value: params.number, validators: ['isString']}) + } + if (params.hasOwnProperty("loaId")) { + validations.push({field: 'loaId', value: params.loaId, validators: ['isString']}) + } + let errors = validate(validations); + if (errors) { + return errors; + } + return new HostedMessagingNumber(this[clientKey], {id: idField}).list(params) + } + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.applicationId] - Application ID + * @param {string} [params.number] - Phone Number + * @param {string} [params.applicationId] - LOA ID + * @fail {Error} return Error + */ + create(params = {}) { + let errors = validate([ + {field: 'alias', value: params.alias, validators: ['isRequired', 'isString']}, + {field: 'applicationId', value: params.applicationId, validators: ['isRequired', 'isString']}, + {field: 'loaId', value: params.loaId, validators: ['isRequired', 'isString']}, + {field: 'number', value: params.number, validators: ['isRequired', 'isString']}, + ]); + if (errors) { + return errors; + } + return new HostedMessagingNumber(this[clientKey], {id: idField}).create(params) + } +} diff --git a/lib/resources/loa.js b/lib/resources/loa.js new file mode 100644 index 00000000..aec1d601 --- /dev/null +++ b/lib/resources/loa.js @@ -0,0 +1,234 @@ +import { + PlivoResource, PlivoResourceInterface +} from '../base'; +import { + extend, validate +} from '../utils/common.js'; + +const clientKey = Symbol(); +const action = 'HostedMessagingNumber/LOA/'; +const idField = 'loaID'; + +export class LOAResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.file = params.file; + this.loaId = params.loaId; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class CreateLOAResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.file = params.file; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class ListLOAResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.meta = params.metaResponse; + this.objects = params.objects; + } +} + + +export class LOA extends PlivoResource { + constructor(client, data = {}) { + super(action, LOA, idField, client); + if (idField in data) { + this.id = data[idField]; + } + this[clientKey] = client; + extend(this, data); + } + + /** + * get LOA by given id + * @method + * @param {string} id - id of the LOA + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + if (action !== '' && !id) { + reject(new Error(this[idKey] + ' must be set')); + } + client('GET', action + (id ? id + '/' : '')) + .then(response => { + let object = new LOAResponse(response.body, client); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list LOA by. + * @param {string} [params.alias] - Alias + */ + list(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + client('GET', action, params) + .then(response => { + resolve(new ListLOAResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + params.multipart = true; + client('POST', action, params) + .then(response => { + let object = new CreateLOAResponse(response.body, idField); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }) + } + + /** + * deletes an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(id) { + let client = this[clientKey]; + + return new Promise((resolve, reject) => { + if (action !== '' && !id) { + reject(new Error(this[idKey] + ' must be set')); + } + client('DELETE', action + id + '/') + .then(() => { + resolve(true); + }) + .catch(error => { + reject(error); + }); + }); + } +} + +/** + * Represents a LOA interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class LOAInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(action, LOA, idField, client); + extend(this, data); + this[clientKey] = client; + } + + /** + * get LOA by given id + * @method + * @param {string} id - id of the loa + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id) { + let errors = validate([{field: 'id', value: id, validators: ['isRequired', 'isString']},]); + if (errors) { + return errors; + } + return new LOA(this[clientKey], {id: idField}).get(id) + } + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list LOA by. + * @param {string} [params.alias] - Alias + * @fail {Error} return Error + */ + list(params = {}) { + const validations = [] + if (params.hasOwnProperty("alias")) { + validations.push({field: 'alias', value: params.alias, validators: ['isString']},) + } + let errors = validate(validations); + if (errors) { + return errors; + } + return new LOA(this[clientKey], {id: idField}).list(params) + } + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params = {}) { + let errors = validate([{ + field: 'alias', + value: params.alias, + validators: ['isRequired', 'isString'] + }, {field: 'file', value: params.alias, validators: ['isRequired']}]); + + if (errors) { + return errors; + } + + return new LOA(this[clientKey], {id: idField}).create(params) + } + + /** + * delete an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(id) { + let errors = validate([{ + field: 'id', value: id, validators: ['isRequired', "isString"] + }]); + + if (errors) { + return errors; + } + return new LOA(this[clientKey], {id: idField}).delete(id); + } +} diff --git a/lib/rest/client.js b/lib/rest/client.js index 3c797679..81a34a77 100644 --- a/lib/rest/client.js +++ b/lib/rest/client.js @@ -27,7 +27,10 @@ import { ComplianceDocumentTypeInterface } from "../resources/complianceDocument import { ComplianceDocumentInterface} from "../resources/complianceDocuments"; import { ComplianceRequirementInterface } from "../resources/complianceRequirements"; import { ComplianceApplicationInterface } from "../resources/complianceApplications"; -import {MultiPartyCallInterface} from "../resources/multiPartyCall"; +import { MultiPartyCallInterface } from "../resources/multiPartyCall"; +import { LOAInterface } from "../resources/loa"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; + exports.Response = function() { return new Response(); @@ -102,6 +105,8 @@ export class Client { this.complianceRequirements = new ComplianceRequirementInterface(client); this.complianceApplications = new ComplianceApplicationInterface(client); this.multiPartyCalls = new MultiPartyCallInterface(client); + this.loa = new LOAInterface(client); + this.hostedMessagingNumber = new HostedMessagingNumberInterface(client); } toJSON() { diff --git a/types/resources/hostedMessagingNumber.d.ts b/types/resources/hostedMessagingNumber.d.ts new file mode 100644 index 00000000..1cd0d5bd --- /dev/null +++ b/types/resources/hostedMessagingNumber.d.ts @@ -0,0 +1,123 @@ +export class HostedMessagingNumberResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: Array; +} + +export class CreateHostedMessagingNumberResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: string[]; +} + +export class ListHostedMessagingNumberResponse { + constructor(params: object); + + apiId: string; + meta: Object; + objects: Array; +} + +/** + * Represents a HostedMessagingNumber + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class HostedMessagingNumber extends PlivoResource { + constructor(client: Function, data?: {}); + + id: string; + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the document + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + */ + list(params: object): Promise; + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + [clientKey]: symbol; +} + +/** + * Represents a HostedMessagingNumber Interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class HostedMessagingNumberInterface extends PlivoResourceInterface { + constructor(client: Function, data?: {}); + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the document + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + */ + list(params: object): Promise; + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + [clientKey]: symbol; +} + +import {PlivoResource} from "../base"; + +declare const clientKey: unique symbol; +import {PlivoResourceInterface} from "../base"; + +export {}; diff --git a/types/resources/loa.d.ts b/types/resources/loa.d.ts new file mode 100644 index 00000000..d87918a6 --- /dev/null +++ b/types/resources/loa.d.ts @@ -0,0 +1,134 @@ +export class LOAResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: Array; +} + +export class CreateLOAResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: string[]; +} + +export class ListLOAResponse { + constructor(params: object); + + apiId: string; + meta: Object; + objects: Array; +} + +/** + * Represents an LOA + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class LOA extends PlivoResource { + constructor(client: Function, data?: {}); + + id: string; + + /** + * get LOA by given id + * @method + * @param {string} id - id of the LOA + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list loa by. + */ + list(params: object): Promise; + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File array of the files to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + /** + * delete an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(): Promise; + + [clientKey]: symbol; +} + +/** + * Represents an LOA Interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class LOAInterface extends PlivoResourceInterface { + constructor(client: Function, data?: {}); + + /** + * get LOA by given id + * @method + * @param {string} id - id of the LOA + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list loa by. + */ + list(params: object): Promise; + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File array of the files to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + /** + * delete an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(id: string): any; + + [clientKey]: symbol; +} + +import {PlivoResource} from "../base"; + +declare const clientKey: unique symbol; +import {PlivoResourceInterface} from "../base"; + +export {}; diff --git a/types/rest/client.d.ts b/types/rest/client.d.ts index 86eaded2..499c046c 100644 --- a/types/rest/client.d.ts +++ b/types/rest/client.d.ts @@ -28,6 +28,8 @@ export class Client { complianceDocuments: ComplianceDocumentInterface; complianceRequirements: ComplianceRequirementInterface; complianceApplications: ComplianceApplicationInterface; + loa: LOAInterface; + hostedMessagingNumber: HostedMessagingNumberInterface; toJSON(...args: any[]): any; } /** @@ -58,4 +60,6 @@ import { EndUserInterface } from "../resources/endUsers"; import { ComplianceDocumentTypeInterface } from "../resources/complianceDocumentTypes"; import { ComplianceDocumentInterface} from "../resources/complianceDocuments"; import { ComplianceRequirementInterface } from "../resources/complianceRequirements"; -import { ComplianceApplicationInterface } from "../resources/complianceApplications"; \ No newline at end of file +import { ComplianceApplicationInterface } from "../resources/complianceApplications"; +import { LOAInterface } from "../resources/loa"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; From 2dca4a96db88962d78635bac8c9759a99213745e Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Fri, 3 Dec 2021 17:48:36 +0530 Subject: [PATCH 2/9] added examples for hostedMessagingNumber and loa --- examples/hostedMessagingNumber.js | 35 ++++++++++++++++++++++++++++++ examples/loa.js | 36 +++++++++++++++++++++++++++++++ lib/rest/client-test.js | 4 ++++ types/rest/client-test.d.ts | 4 ++++ 4 files changed, 79 insertions(+) create mode 100644 examples/hostedMessagingNumber.js create mode 100644 examples/loa.js diff --git a/examples/hostedMessagingNumber.js b/examples/hostedMessagingNumber.js new file mode 100644 index 00000000..332f789c --- /dev/null +++ b/examples/hostedMessagingNumber.js @@ -0,0 +1,35 @@ +var Plivo = require('../dist/rest/client.js'); +var client = new Plivo.Client(); + +var createParams = { + alias:"alias", + applicationId: "applicationId", + loaId:"loaID", + number:"number" +}; + +var listParams = { + alias:"alias", + applicationId: "applicationId", + loaId:"loaID", + number:"number", + hostedStatus: "completed", +}; + + +client.hostedMessagingNumber.create(createParams) + .then(function (hmn) { + console.log("\n============ created ===========\n", hmn) + return client.hostedMessagingNumber.get(hmn.id); + }) + .then(function (hmn) { + console.log("\n============ get ===========\n", hmn) + return client.hostedMessagingNumber.list(listParams) + }) + .then(function (hmns) { + console.log("\n============ list with params ===========\n", hmns) + }) + .catch(function (err) { + console.log("\n============ Error :: ===========\n", err); + }); + diff --git a/examples/loa.js b/examples/loa.js new file mode 100644 index 00000000..3216fe6b --- /dev/null +++ b/examples/loa.js @@ -0,0 +1,36 @@ +var Plivo = require('../dist/rest/client.js'); +var client = new Plivo.Client(); + +var createParams = { + "alias": "Test loa", + "file": "path to file" + +}; + +var listParams = { + alias: "Test loa", + limit: 10, + offset: 5 +}; + + +client.loa.create(createParams) + .then(function (loa) { + console.log("\n============ created ===========\n", loa) + return client.loa.get(loa.id); + }) + .then(function (loa) { + console.log("\n============ get ===========\n", loa) + return client.loa.delete(loa.id); + }) + .then(function (result) { + console.log("\n============ deleted ===========\n", result) + return client.loa.list(listParams) + }) + .then(function (loas) { + console.log("\n============ list with params ===========\n", loas) + }) + .catch(function (err) { + console.log("\n============ Error :: ===========\n", err); + }); + diff --git a/lib/rest/client-test.js b/lib/rest/client-test.js index 0a88610c..7dbed8e6 100644 --- a/lib/rest/client-test.js +++ b/lib/rest/client-test.js @@ -61,6 +61,8 @@ import { ComplianceDocumentTypeInterface } from "../resources/complianceDocument import { ComplianceDocumentInterface} from "../resources/complianceDocuments"; import { ComplianceRequirementInterface } from "../resources/complianceRequirements"; import { ComplianceApplicationInterface } from "../resources/complianceApplications"; +import { LOAInterface } from "../resources/loa"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; export class Client { constructor(authId, authToken, proxy) { @@ -111,6 +113,8 @@ export class Client { this.complianceRequirements = new ComplianceRequirementInterface(client); this.complianceApplications = new ComplianceApplicationInterface(client); this.multiPartyCalls = new MultiPartyCallInterface(client); + this.loa = new LOAInterface(client); + this.hostedMessagingNumber = new HostedMessagingNumberInterface(client); } } diff --git a/types/rest/client-test.d.ts b/types/rest/client-test.d.ts index 6e73f732..cd82e78d 100644 --- a/types/rest/client-test.d.ts +++ b/types/rest/client-test.d.ts @@ -13,6 +13,8 @@ export class Client { pricings: PricingInterface; recordings: RecordingInterface; media: MediaInterface; + loa: LOAInterface; + hostedMessagingNumber: HostedMessagingNumberInterface; } /** * Plivo API client which can be used to access the Plivo APIs. @@ -37,3 +39,5 @@ import { PricingInterface } from "../resources/pricings.js"; import { RecordingInterface } from "../resources/recordings.js"; import { MediaInterface } from "../resources/media.js"; import { Phlo } from "../resources/phlo.js"; +import { LOAInterface } from "../resources/loa.js"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber.js"; From 787dd7446357f55fd28af75c89c8d79409f92882 Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Wed, 16 Feb 2022 18:30:34 +0530 Subject: [PATCH 3/9] added missing fields --- examples/hostedMessagingNumber.js | 2 +- examples/loa.js | 4 ++-- lib/resources/hostedMessagingNumber.js | 3 +++ lib/resources/loa.js | 3 +++ types/resources/hostedMessagingNumber.d.ts | 3 +++ types/resources/loa.d.ts | 3 +++ 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/hostedMessagingNumber.js b/examples/hostedMessagingNumber.js index 332f789c..534982fd 100644 --- a/examples/hostedMessagingNumber.js +++ b/examples/hostedMessagingNumber.js @@ -20,7 +20,7 @@ var listParams = { client.hostedMessagingNumber.create(createParams) .then(function (hmn) { console.log("\n============ created ===========\n", hmn) - return client.hostedMessagingNumber.get(hmn.id); + return client.hostedMessagingNumber.get(hmn.hostedMessagingNumberId); }) .then(function (hmn) { console.log("\n============ get ===========\n", hmn) diff --git a/examples/loa.js b/examples/loa.js index 3216fe6b..e074f71b 100644 --- a/examples/loa.js +++ b/examples/loa.js @@ -17,11 +17,11 @@ var listParams = { client.loa.create(createParams) .then(function (loa) { console.log("\n============ created ===========\n", loa) - return client.loa.get(loa.id); + return client.loa.get(loa.loaId); }) .then(function (loa) { console.log("\n============ get ===========\n", loa) - return client.loa.delete(loa.id); + return client.loa.delete(loa.loaId); }) .then(function (result) { console.log("\n============ deleted ===========\n", result) diff --git a/lib/resources/hostedMessagingNumber.js b/lib/resources/hostedMessagingNumber.js index 8f2ece93..086e5865 100644 --- a/lib/resources/hostedMessagingNumber.js +++ b/lib/resources/hostedMessagingNumber.js @@ -22,6 +22,7 @@ export class HostedMessagingNumberResponse { this.number = params.number; this.hostedStatus = params.hostedStatus; this.linkedNumbers = params.linkedNumbers; + this.resourceUri = params.resourceUri; this.createdAt = params.createdAt; } } @@ -39,6 +40,8 @@ export class CreateHostedMessagingNumberResponse { this.number = params.number; this.hostedStatus = params.hostedStatus; this.linkedNumbers = params.linkedNumbers; + this.resourceUri = params.resourceUri; + this.message = params.message; this.createdAt = params.createdAt; } } diff --git a/lib/resources/loa.js b/lib/resources/loa.js index aec1d601..3236904f 100644 --- a/lib/resources/loa.js +++ b/lib/resources/loa.js @@ -18,6 +18,7 @@ export class LOAResponse { this.loaId = params.loaId; this.linkedNumbers = params.linkedNumbers; this.createdAt = params.createdAt; + this.resourceUri = params.resourceUri; } } @@ -29,6 +30,8 @@ export class CreateLOAResponse { this.file = params.file; this.linkedNumbers = params.linkedNumbers; this.createdAt = params.createdAt; + this.resourceUri = params.resourceUri; + this.message = params.message; } } diff --git a/types/resources/hostedMessagingNumber.d.ts b/types/resources/hostedMessagingNumber.d.ts index 1cd0d5bd..3b5c2d18 100644 --- a/types/resources/hostedMessagingNumber.d.ts +++ b/types/resources/hostedMessagingNumber.d.ts @@ -7,6 +7,7 @@ export class HostedMessagingNumberResponse { file: string; createdAt: string; linkedNumbers: Array; + resourceUri:string; } export class CreateHostedMessagingNumberResponse { @@ -18,6 +19,8 @@ export class CreateHostedMessagingNumberResponse { file: string; createdAt: string; linkedNumbers: string[]; + resourceUri:string; + message:string; } export class ListHostedMessagingNumberResponse { diff --git a/types/resources/loa.d.ts b/types/resources/loa.d.ts index d87918a6..f64392d1 100644 --- a/types/resources/loa.d.ts +++ b/types/resources/loa.d.ts @@ -7,6 +7,7 @@ export class LOAResponse { file: string; createdAt: string; linkedNumbers: Array; + resourceUri: string; } export class CreateLOAResponse { @@ -18,6 +19,8 @@ export class CreateLOAResponse { file: string; createdAt: string; linkedNumbers: string[]; + resourceUri: string; + message: string; } export class ListLOAResponse { From 02e8ace78f8d07f8b88107fd0b3204d3d464f1d1 Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Thu, 17 Feb 2022 15:45:48 +0530 Subject: [PATCH 4/9] added loaId in createLoa --- lib/resources/loa.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/resources/loa.js b/lib/resources/loa.js index 3236904f..206853f2 100644 --- a/lib/resources/loa.js +++ b/lib/resources/loa.js @@ -25,6 +25,7 @@ export class LOAResponse { export class CreateLOAResponse { constructor(params) { params = params || {}; + this.loaId = params.loaId; this.apiId = params.apiId; this.alias = params.alias; this.file = params.file; From 46dbba603af7efa05d323738eb6826e2c527f207 Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Fri, 3 Dec 2021 17:02:35 +0530 Subject: [PATCH 5/9] added support for hostedMessagingNumber and LOA --- lib/resources/hostedMessagingNumber.js | 222 +++++++++++++++++++ lib/resources/loa.js | 234 +++++++++++++++++++++ lib/rest/client.js | 7 +- types/resources/hostedMessagingNumber.d.ts | 123 +++++++++++ types/resources/loa.d.ts | 134 ++++++++++++ types/rest/client.d.ts | 6 +- 6 files changed, 724 insertions(+), 2 deletions(-) create mode 100644 lib/resources/hostedMessagingNumber.js create mode 100644 lib/resources/loa.js create mode 100644 types/resources/hostedMessagingNumber.d.ts create mode 100644 types/resources/loa.d.ts diff --git a/lib/resources/hostedMessagingNumber.js b/lib/resources/hostedMessagingNumber.js new file mode 100644 index 00000000..8f2ece93 --- /dev/null +++ b/lib/resources/hostedMessagingNumber.js @@ -0,0 +1,222 @@ +import { + PlivoResource, PlivoResourceInterface +} from '../base'; +import { + extend, validate +} from '../utils/common.js'; + +const clientKey = Symbol(); +const action = 'HostedMessagingNumber/'; +const idField = 'hosted_messaging_number_id'; + +export class HostedMessagingNumberResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.application = params.application + this.failureReason = params.failureReason + this.file = params.file; + this.hostedMessagingNumberId = params.hostedMessagingNumberId; + this.loaId = params.loaId; + this.number = params.number; + this.hostedStatus = params.hostedStatus; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class CreateHostedMessagingNumberResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.application = params.application + this.failureReason = params.failureReason + this.file = params.file; + this.hostedMessagingNumberId = params.hostedMessagingNumberId; + this.loaId = params.loaId; + this.number = params.number; + this.hostedStatus = params.hostedStatus; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class ListHostedMessagingNumberResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.meta = params.metaResponse; + this.objects = params.objects; + } +} + + +export class HostedMessagingNumber extends PlivoResource { + constructor(client, data = {}) { + super(action, HostedMessagingNumber, idField, client); + if (idField in data) { + this.id = data[idField]; + } + this[clientKey] = client; + extend(this, data); + } + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the HostedMessagingNumber + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + if (action !== '' && !id) { + reject(new Error(this[idKey] + ' must be set')); + } + client('GET', action + (id ? id + '/' : '')) + .then(response => { + let object = new HostedMessagingNumberResponse(response.body, client); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + * @fail {Error} return Error + */ + list(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + client('GET', action, params) + .then(response => { + resolve(new ListHostedMessagingNumberResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.applicationId] - Application ID + * @param {string} [params.number] - Phone Number + * @param {string} [params.applicationId] - LOA ID + * @fail {Error} return Error + */ + create(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + params.multipart = true; + client('POST', action, params) + .then(response => { + let object = new CreateHostedMessagingNumberResponse(response.body, idField); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }) + } +} + +/** + * Represents a HostedMessagingNumber interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class HostedMessagingNumberInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(action, HostedMessagingNumber, idField, client); + extend(this, data); + this[clientKey] = client; + } + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the HostedMessagingNumber + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id) { + let errors = validate([{field: 'id', value: id, validators: ['isRequired', 'isString']},]); + if (errors) { + return errors; + } + return new HostedMessagingNumber(this[clientKey], {id: idField}).get(id) + } + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + * @fail {Error} return Error + */ + list(params = {}) { + const validations = [] + if (params.hasOwnProperty("alias")) { + validations.push({field: 'alias', value: params.alias, validators: ['isString']}) + } + if (params.hasOwnProperty("hostedStatus")) { + validations.push({field: 'hostedStatus', value: params.hostedStatus, validators: ['isString']}) + } + if (params.hasOwnProperty("number")) { + validations.push({field: 'number', value: params.number, validators: ['isString']}) + } + if (params.hasOwnProperty("loaId")) { + validations.push({field: 'loaId', value: params.loaId, validators: ['isString']}) + } + let errors = validate(validations); + if (errors) { + return errors; + } + return new HostedMessagingNumber(this[clientKey], {id: idField}).list(params) + } + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.applicationId] - Application ID + * @param {string} [params.number] - Phone Number + * @param {string} [params.applicationId] - LOA ID + * @fail {Error} return Error + */ + create(params = {}) { + let errors = validate([ + {field: 'alias', value: params.alias, validators: ['isRequired', 'isString']}, + {field: 'applicationId', value: params.applicationId, validators: ['isRequired', 'isString']}, + {field: 'loaId', value: params.loaId, validators: ['isRequired', 'isString']}, + {field: 'number', value: params.number, validators: ['isRequired', 'isString']}, + ]); + if (errors) { + return errors; + } + return new HostedMessagingNumber(this[clientKey], {id: idField}).create(params) + } +} diff --git a/lib/resources/loa.js b/lib/resources/loa.js new file mode 100644 index 00000000..aec1d601 --- /dev/null +++ b/lib/resources/loa.js @@ -0,0 +1,234 @@ +import { + PlivoResource, PlivoResourceInterface +} from '../base'; +import { + extend, validate +} from '../utils/common.js'; + +const clientKey = Symbol(); +const action = 'HostedMessagingNumber/LOA/'; +const idField = 'loaID'; + +export class LOAResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.file = params.file; + this.loaId = params.loaId; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class CreateLOAResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.alias = params.alias; + this.file = params.file; + this.linkedNumbers = params.linkedNumbers; + this.createdAt = params.createdAt; + } +} + +export class ListLOAResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.meta = params.metaResponse; + this.objects = params.objects; + } +} + + +export class LOA extends PlivoResource { + constructor(client, data = {}) { + super(action, LOA, idField, client); + if (idField in data) { + this.id = data[idField]; + } + this[clientKey] = client; + extend(this, data); + } + + /** + * get LOA by given id + * @method + * @param {string} id - id of the LOA + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + if (action !== '' && !id) { + reject(new Error(this[idKey] + ' must be set')); + } + client('GET', action + (id ? id + '/' : '')) + .then(response => { + let object = new LOAResponse(response.body, client); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list LOA by. + * @param {string} [params.alias] - Alias + */ + list(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + client('GET', action, params) + .then(response => { + resolve(new ListLOAResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }); + } + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params = {}) { + let client = this[clientKey]; + return new Promise((resolve, reject) => { + params.multipart = true; + client('POST', action, params) + .then(response => { + let object = new CreateLOAResponse(response.body, idField); + Object.keys(object).forEach(key => object[key] === undefined && delete object[key]); + resolve(object); + }) + .catch(error => { + reject(error); + }); + }) + } + + /** + * deletes an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(id) { + let client = this[clientKey]; + + return new Promise((resolve, reject) => { + if (action !== '' && !id) { + reject(new Error(this[idKey] + ' must be set')); + } + client('DELETE', action + id + '/') + .then(() => { + resolve(true); + }) + .catch(error => { + reject(error); + }); + }); + } +} + +/** + * Represents a LOA interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class LOAInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(action, LOA, idField, client); + extend(this, data); + this[clientKey] = client; + } + + /** + * get LOA by given id + * @method + * @param {string} id - id of the loa + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id) { + let errors = validate([{field: 'id', value: id, validators: ['isRequired', 'isString']},]); + if (errors) { + return errors; + } + return new LOA(this[clientKey], {id: idField}).get(id) + } + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list LOA by. + * @param {string} [params.alias] - Alias + * @fail {Error} return Error + */ + list(params = {}) { + const validations = [] + if (params.hasOwnProperty("alias")) { + validations.push({field: 'alias', value: params.alias, validators: ['isString']},) + } + let errors = validate(validations); + if (errors) { + return errors; + } + return new LOA(this[clientKey], {id: idField}).list(params) + } + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params = {}) { + let errors = validate([{ + field: 'alias', + value: params.alias, + validators: ['isRequired', 'isString'] + }, {field: 'file', value: params.alias, validators: ['isRequired']}]); + + if (errors) { + return errors; + } + + return new LOA(this[clientKey], {id: idField}).create(params) + } + + /** + * delete an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(id) { + let errors = validate([{ + field: 'id', value: id, validators: ['isRequired', "isString"] + }]); + + if (errors) { + return errors; + } + return new LOA(this[clientKey], {id: idField}).delete(id); + } +} diff --git a/lib/rest/client.js b/lib/rest/client.js index 3c797679..81a34a77 100644 --- a/lib/rest/client.js +++ b/lib/rest/client.js @@ -27,7 +27,10 @@ import { ComplianceDocumentTypeInterface } from "../resources/complianceDocument import { ComplianceDocumentInterface} from "../resources/complianceDocuments"; import { ComplianceRequirementInterface } from "../resources/complianceRequirements"; import { ComplianceApplicationInterface } from "../resources/complianceApplications"; -import {MultiPartyCallInterface} from "../resources/multiPartyCall"; +import { MultiPartyCallInterface } from "../resources/multiPartyCall"; +import { LOAInterface } from "../resources/loa"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; + exports.Response = function() { return new Response(); @@ -102,6 +105,8 @@ export class Client { this.complianceRequirements = new ComplianceRequirementInterface(client); this.complianceApplications = new ComplianceApplicationInterface(client); this.multiPartyCalls = new MultiPartyCallInterface(client); + this.loa = new LOAInterface(client); + this.hostedMessagingNumber = new HostedMessagingNumberInterface(client); } toJSON() { diff --git a/types/resources/hostedMessagingNumber.d.ts b/types/resources/hostedMessagingNumber.d.ts new file mode 100644 index 00000000..1cd0d5bd --- /dev/null +++ b/types/resources/hostedMessagingNumber.d.ts @@ -0,0 +1,123 @@ +export class HostedMessagingNumberResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: Array; +} + +export class CreateHostedMessagingNumberResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: string[]; +} + +export class ListHostedMessagingNumberResponse { + constructor(params: object); + + apiId: string; + meta: Object; + objects: Array; +} + +/** + * Represents a HostedMessagingNumber + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class HostedMessagingNumber extends PlivoResource { + constructor(client: Function, data?: {}); + + id: string; + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the document + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + */ + list(params: object): Promise; + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + [clientKey]: symbol; +} + +/** + * Represents a HostedMessagingNumber Interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class HostedMessagingNumberInterface extends PlivoResourceInterface { + constructor(client: Function, data?: {}); + + /** + * get HostedMessagingNumber by given id + * @method + * @param {string} id - id of the document + * @promise {object} return {@link HostedMessagingNumber} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + + /** + * list all HostedMessagingNumber + * @method + * @param {object} params - params containing options to list HostedMessagingNumber by. + * @param {string} [params.alias] - Alias + * @param {string} [params.hostedStatus] - Hosted Status + * @param {string} [params.number] - Phone Number + * @param {string} [params.loaId] - LOA ID + */ + list(params: object): Promise; + + /** + * Create a HostedMessagingNumber + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + [clientKey]: symbol; +} + +import {PlivoResource} from "../base"; + +declare const clientKey: unique symbol; +import {PlivoResourceInterface} from "../base"; + +export {}; diff --git a/types/resources/loa.d.ts b/types/resources/loa.d.ts new file mode 100644 index 00000000..d87918a6 --- /dev/null +++ b/types/resources/loa.d.ts @@ -0,0 +1,134 @@ +export class LOAResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: Array; +} + +export class CreateLOAResponse { + constructor(params: object); + + apiId: string; + loaId: string; + alias: string; + file: string; + createdAt: string; + linkedNumbers: string[]; +} + +export class ListLOAResponse { + constructor(params: object); + + apiId: string; + meta: Object; + objects: Array; +} + +/** + * Represents an LOA + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class LOA extends PlivoResource { + constructor(client: Function, data?: {}); + + id: string; + + /** + * get LOA by given id + * @method + * @param {string} id - id of the LOA + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list loa by. + */ + list(params: object): Promise; + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File array of the files to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + /** + * delete an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(): Promise; + + [clientKey]: symbol; +} + +/** + * Represents an LOA Interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class LOAInterface extends PlivoResourceInterface { + constructor(client: Function, data?: {}); + + /** + * get LOA by given id + * @method + * @param {string} id - id of the LOA + * @promise {object} return {@link LOA} object + * @fail {Error} return Error + */ + get(id: string): Promise; + + + /** + * list all LOA + * @method + * @param {object} params - params containing options to list loa by. + */ + list(params: object): Promise; + + /** + * Create an LOA + * @method + * @param {object} params + * @param {string} [params.alias] - Alias + * @param {string} [params.file] - File array of the files to be uploaded + * @fail {Error} return Error + */ + create(params: object): Promise; + + /** + * delete an LOA + * @method + * @param {string} id - id to delete + * @promise {boolean} return true if success + * @fail {Error} return Error + */ + delete(id: string): any; + + [clientKey]: symbol; +} + +import {PlivoResource} from "../base"; + +declare const clientKey: unique symbol; +import {PlivoResourceInterface} from "../base"; + +export {}; diff --git a/types/rest/client.d.ts b/types/rest/client.d.ts index 86eaded2..499c046c 100644 --- a/types/rest/client.d.ts +++ b/types/rest/client.d.ts @@ -28,6 +28,8 @@ export class Client { complianceDocuments: ComplianceDocumentInterface; complianceRequirements: ComplianceRequirementInterface; complianceApplications: ComplianceApplicationInterface; + loa: LOAInterface; + hostedMessagingNumber: HostedMessagingNumberInterface; toJSON(...args: any[]): any; } /** @@ -58,4 +60,6 @@ import { EndUserInterface } from "../resources/endUsers"; import { ComplianceDocumentTypeInterface } from "../resources/complianceDocumentTypes"; import { ComplianceDocumentInterface} from "../resources/complianceDocuments"; import { ComplianceRequirementInterface } from "../resources/complianceRequirements"; -import { ComplianceApplicationInterface } from "../resources/complianceApplications"; \ No newline at end of file +import { ComplianceApplicationInterface } from "../resources/complianceApplications"; +import { LOAInterface } from "../resources/loa"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; From 43255bebd48f240925c30aee045f17e46ca72aaf Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Fri, 3 Dec 2021 17:48:36 +0530 Subject: [PATCH 6/9] added examples for hostedMessagingNumber and loa --- examples/hostedMessagingNumber.js | 35 ++++++++++++++++++++++++++++++ examples/loa.js | 36 +++++++++++++++++++++++++++++++ lib/rest/client-test.js | 4 ++++ types/rest/client-test.d.ts | 4 ++++ 4 files changed, 79 insertions(+) create mode 100644 examples/hostedMessagingNumber.js create mode 100644 examples/loa.js diff --git a/examples/hostedMessagingNumber.js b/examples/hostedMessagingNumber.js new file mode 100644 index 00000000..332f789c --- /dev/null +++ b/examples/hostedMessagingNumber.js @@ -0,0 +1,35 @@ +var Plivo = require('../dist/rest/client.js'); +var client = new Plivo.Client(); + +var createParams = { + alias:"alias", + applicationId: "applicationId", + loaId:"loaID", + number:"number" +}; + +var listParams = { + alias:"alias", + applicationId: "applicationId", + loaId:"loaID", + number:"number", + hostedStatus: "completed", +}; + + +client.hostedMessagingNumber.create(createParams) + .then(function (hmn) { + console.log("\n============ created ===========\n", hmn) + return client.hostedMessagingNumber.get(hmn.id); + }) + .then(function (hmn) { + console.log("\n============ get ===========\n", hmn) + return client.hostedMessagingNumber.list(listParams) + }) + .then(function (hmns) { + console.log("\n============ list with params ===========\n", hmns) + }) + .catch(function (err) { + console.log("\n============ Error :: ===========\n", err); + }); + diff --git a/examples/loa.js b/examples/loa.js new file mode 100644 index 00000000..3216fe6b --- /dev/null +++ b/examples/loa.js @@ -0,0 +1,36 @@ +var Plivo = require('../dist/rest/client.js'); +var client = new Plivo.Client(); + +var createParams = { + "alias": "Test loa", + "file": "path to file" + +}; + +var listParams = { + alias: "Test loa", + limit: 10, + offset: 5 +}; + + +client.loa.create(createParams) + .then(function (loa) { + console.log("\n============ created ===========\n", loa) + return client.loa.get(loa.id); + }) + .then(function (loa) { + console.log("\n============ get ===========\n", loa) + return client.loa.delete(loa.id); + }) + .then(function (result) { + console.log("\n============ deleted ===========\n", result) + return client.loa.list(listParams) + }) + .then(function (loas) { + console.log("\n============ list with params ===========\n", loas) + }) + .catch(function (err) { + console.log("\n============ Error :: ===========\n", err); + }); + diff --git a/lib/rest/client-test.js b/lib/rest/client-test.js index 0a88610c..7dbed8e6 100644 --- a/lib/rest/client-test.js +++ b/lib/rest/client-test.js @@ -61,6 +61,8 @@ import { ComplianceDocumentTypeInterface } from "../resources/complianceDocument import { ComplianceDocumentInterface} from "../resources/complianceDocuments"; import { ComplianceRequirementInterface } from "../resources/complianceRequirements"; import { ComplianceApplicationInterface } from "../resources/complianceApplications"; +import { LOAInterface } from "../resources/loa"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; export class Client { constructor(authId, authToken, proxy) { @@ -111,6 +113,8 @@ export class Client { this.complianceRequirements = new ComplianceRequirementInterface(client); this.complianceApplications = new ComplianceApplicationInterface(client); this.multiPartyCalls = new MultiPartyCallInterface(client); + this.loa = new LOAInterface(client); + this.hostedMessagingNumber = new HostedMessagingNumberInterface(client); } } diff --git a/types/rest/client-test.d.ts b/types/rest/client-test.d.ts index 6e73f732..cd82e78d 100644 --- a/types/rest/client-test.d.ts +++ b/types/rest/client-test.d.ts @@ -13,6 +13,8 @@ export class Client { pricings: PricingInterface; recordings: RecordingInterface; media: MediaInterface; + loa: LOAInterface; + hostedMessagingNumber: HostedMessagingNumberInterface; } /** * Plivo API client which can be used to access the Plivo APIs. @@ -37,3 +39,5 @@ import { PricingInterface } from "../resources/pricings.js"; import { RecordingInterface } from "../resources/recordings.js"; import { MediaInterface } from "../resources/media.js"; import { Phlo } from "../resources/phlo.js"; +import { LOAInterface } from "../resources/loa.js"; +import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber.js"; From 7a7778ff5788ebf676c32153d27c55800b67ecd0 Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Wed, 16 Feb 2022 18:30:34 +0530 Subject: [PATCH 7/9] added missing fields --- examples/hostedMessagingNumber.js | 2 +- examples/loa.js | 4 ++-- lib/resources/hostedMessagingNumber.js | 3 +++ lib/resources/loa.js | 3 +++ types/resources/hostedMessagingNumber.d.ts | 3 +++ types/resources/loa.d.ts | 3 +++ 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/hostedMessagingNumber.js b/examples/hostedMessagingNumber.js index 332f789c..534982fd 100644 --- a/examples/hostedMessagingNumber.js +++ b/examples/hostedMessagingNumber.js @@ -20,7 +20,7 @@ var listParams = { client.hostedMessagingNumber.create(createParams) .then(function (hmn) { console.log("\n============ created ===========\n", hmn) - return client.hostedMessagingNumber.get(hmn.id); + return client.hostedMessagingNumber.get(hmn.hostedMessagingNumberId); }) .then(function (hmn) { console.log("\n============ get ===========\n", hmn) diff --git a/examples/loa.js b/examples/loa.js index 3216fe6b..e074f71b 100644 --- a/examples/loa.js +++ b/examples/loa.js @@ -17,11 +17,11 @@ var listParams = { client.loa.create(createParams) .then(function (loa) { console.log("\n============ created ===========\n", loa) - return client.loa.get(loa.id); + return client.loa.get(loa.loaId); }) .then(function (loa) { console.log("\n============ get ===========\n", loa) - return client.loa.delete(loa.id); + return client.loa.delete(loa.loaId); }) .then(function (result) { console.log("\n============ deleted ===========\n", result) diff --git a/lib/resources/hostedMessagingNumber.js b/lib/resources/hostedMessagingNumber.js index 8f2ece93..086e5865 100644 --- a/lib/resources/hostedMessagingNumber.js +++ b/lib/resources/hostedMessagingNumber.js @@ -22,6 +22,7 @@ export class HostedMessagingNumberResponse { this.number = params.number; this.hostedStatus = params.hostedStatus; this.linkedNumbers = params.linkedNumbers; + this.resourceUri = params.resourceUri; this.createdAt = params.createdAt; } } @@ -39,6 +40,8 @@ export class CreateHostedMessagingNumberResponse { this.number = params.number; this.hostedStatus = params.hostedStatus; this.linkedNumbers = params.linkedNumbers; + this.resourceUri = params.resourceUri; + this.message = params.message; this.createdAt = params.createdAt; } } diff --git a/lib/resources/loa.js b/lib/resources/loa.js index aec1d601..3236904f 100644 --- a/lib/resources/loa.js +++ b/lib/resources/loa.js @@ -18,6 +18,7 @@ export class LOAResponse { this.loaId = params.loaId; this.linkedNumbers = params.linkedNumbers; this.createdAt = params.createdAt; + this.resourceUri = params.resourceUri; } } @@ -29,6 +30,8 @@ export class CreateLOAResponse { this.file = params.file; this.linkedNumbers = params.linkedNumbers; this.createdAt = params.createdAt; + this.resourceUri = params.resourceUri; + this.message = params.message; } } diff --git a/types/resources/hostedMessagingNumber.d.ts b/types/resources/hostedMessagingNumber.d.ts index 1cd0d5bd..3b5c2d18 100644 --- a/types/resources/hostedMessagingNumber.d.ts +++ b/types/resources/hostedMessagingNumber.d.ts @@ -7,6 +7,7 @@ export class HostedMessagingNumberResponse { file: string; createdAt: string; linkedNumbers: Array; + resourceUri:string; } export class CreateHostedMessagingNumberResponse { @@ -18,6 +19,8 @@ export class CreateHostedMessagingNumberResponse { file: string; createdAt: string; linkedNumbers: string[]; + resourceUri:string; + message:string; } export class ListHostedMessagingNumberResponse { diff --git a/types/resources/loa.d.ts b/types/resources/loa.d.ts index d87918a6..f64392d1 100644 --- a/types/resources/loa.d.ts +++ b/types/resources/loa.d.ts @@ -7,6 +7,7 @@ export class LOAResponse { file: string; createdAt: string; linkedNumbers: Array; + resourceUri: string; } export class CreateLOAResponse { @@ -18,6 +19,8 @@ export class CreateLOAResponse { file: string; createdAt: string; linkedNumbers: string[]; + resourceUri: string; + message: string; } export class ListLOAResponse { From ef030074fbe300d44ff3919da1365b6753d9d451 Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Thu, 17 Feb 2022 15:45:48 +0530 Subject: [PATCH 8/9] added loaId in createLoa --- lib/resources/loa.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/resources/loa.js b/lib/resources/loa.js index 3236904f..206853f2 100644 --- a/lib/resources/loa.js +++ b/lib/resources/loa.js @@ -25,6 +25,7 @@ export class LOAResponse { export class CreateLOAResponse { constructor(params) { params = params || {}; + this.loaId = params.loaId; this.apiId = params.apiId; this.alias = params.alias; this.file = params.file; From 386593501ff54ba5d9e59c85886db078840a5636 Mon Sep 17 00:00:00 2001 From: kalyan-plivo Date: Wed, 23 Feb 2022 13:14:16 +0530 Subject: [PATCH 9/9] version changes --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80be95e8..136063b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [v4.28.0](https://github.com/plivo/plivo-node/tree/v4.28.0) (2022-02-23) +**Features - Numbers: Hosted Messaging API** +- Add support for Hosted Messaging APIs. + ## [v4.27.0](https://github.com/plivo/plivo-node/tree/v4.27.0) (2022-02-02) **Features - MPCStartCallRecording** - Parameter change from statusCallback to recordingCallback diff --git a/package.json b/package.json index 55b4bbaa..965b8150 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.27.0", + "version": "4.28.0", "description": "A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML", "homepage": "https://github.com/plivo/plivo-node", "files": [