diff --git a/gulpfile.js b/gulpfile.js index 371cdcb5..154113cf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,7 +43,7 @@ gulp.task('pre-test', function () { gulp.task('test', ['pre-test'], function (cb) { var mochaErr; - gulp.src('test/**/*.js') + gulp.src('test/**/test.phloConferenceBridge.js') .pipe(plumber()) .pipe(mocha({ reporter: 'spec' })) .on('error', function (err) { diff --git a/lib/resources/phlo.js b/lib/resources/phlo.js index e8000df6..48bffabf 100644 --- a/lib/resources/phlo.js +++ b/lib/resources/phlo.js @@ -1,6 +1,7 @@ import { extend, validate } from '../utils/common.js'; import { PlivoResource, PlivoResourceInterface } from '../base'; import { PhloMultiPartyCall, PhloMultiPartyCallInterface } from "../resources/phloMultipartyCall"; +import { PhloConfBridge, PhloConfBridgeInterface } from "../resources/phloConfBridge"; import * as _ from "lodash"; const clientKey = Symbol(); @@ -32,6 +33,17 @@ export class Phlo extends PlivoResource { return dd.get(item.phloId, nodeId); } + // Define conference bridge getters + this.conferenceBridge = function (nodeId) { + let dd = new PhloConfBridge(client, { phloId: item.phloId, nodeId: nodeId }); + return dd; + }; + + this.conferenceBridge.get = function (nodeId) { + let dd = new PhloConfBridgeInterface(client, { phloId: item.phloId, nodeId: nodeId }); + return dd.get(item.phloId, nodeId); + } + } /** diff --git a/lib/resources/phloConfBridge.js b/lib/resources/phloConfBridge.js new file mode 100644 index 00000000..778390e7 --- /dev/null +++ b/lib/resources/phloConfBridge.js @@ -0,0 +1,72 @@ +import { extend, validate } from '../utils/common.js'; +import { PlivoResource, PlivoResourceInterface } from '../base'; +import { PhloConfBridgeMember, PhloConfBridgeMemberInterface } from './phloConfBridgeMember'; + +const clientKey = Symbol(); +const idField = 'nodeId'; + +export class PhloConfBridge extends PlivoResource { + constructor(client, data = {}) { + let action = 'phlo/' + data.phloId + '/conference_bridge/'; + super(action, PhloConfBridge, idField, client); + extend(this, data); + this.action = action; + this.client = client; + + // Define member getters + let item = this; + this.member = function (memberAddress) { + let dd = new PhloConfBridgeMember(client, { phloId: item.phloId, nodeId: item.nodeId, memberAddress: memberAddress }); + return dd; + }; + + this.member.get = function (memberAddress) { + let dd = new PhloConfBridgeMemberInterface(client, { phloId: item.phloId, nodeId: item.nodeId, memberAddress: memberAddress }); + return dd.get(item.phloId, item.nodeId, memberAddress); + } + + } +} + +export class PhloConfBridgeInterface extends PlivoResourceInterface { + + + constructor(client, data = {}) { + let action = 'phlo/' + data.phloId + '/conference_bridge/'; + super(action, PhloConfBridge, idField, client); + extend(this, data); + } + + /** + * Get A Phlo Detail + * @method + * @param {string} id - phlo uuid to get information of. + * @promise {object} returns Phlo Object + * @fail {Error} returns Error + */ + get(phloId, id) { + + //Validate id first + let errors = validate([{ + field: 'id', + value: id, + validators: ['isRequired'] + }]); + + if (errors) { + return errors; + } + + let params = { + phlo_id: phloId, + node_type: 'conference_bridge', + node_id: id + }; + + // Url pattern for getting phlo resource by id + // https://phlorunner.plivo.com/v1/phlo/{phlo_id} + // console.log('get multi party call with ', id, params); + return super.get(id, params); + + } +} diff --git a/lib/resources/phloConfBridgeMember.js b/lib/resources/phloConfBridgeMember.js new file mode 100644 index 00000000..76ca1052 --- /dev/null +++ b/lib/resources/phloConfBridgeMember.js @@ -0,0 +1,77 @@ +import { extend, validate } from '../utils/common.js'; +import { PlivoResource, PlivoResourceInterface } from '../base'; + +const clientKey = Symbol(); +const action = 'Phlo/'; +const idField = 'phloUuid'; + +/** + * Represents a Phlo Conference Bridge Call Member + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of phlo + */ +export class PhloConfBridgeMember extends PlivoResource { + + constructor(client, data = {}) { + let action = 'phlo/' + data.phloId + '/conference_bridge/' + data.nodeId + '/members/'; + super(action, PhloConfBridgeMember, idField, client); + extend(this, data); + this.action = action; + this.client = client; + } + + mute() { + return this.update('mute'); + } + + unmute() { + return this.update('unmute'); + } + + leave() { + return this.update('leave'); + } + + update(action) { + + let params = { + action: action + }; + + // Build Url + // https://phlorunner.plivo.com/v1/phlo/{PHLO_ID}/multi_party_call/{NODE_ID}/members/{MemberAddress} + let task = this.action + this.memberAddress; + + return super.executeAction(task, 'POST', params, ''); + } +} + +export class PhloConfBridgeMemberInterface extends PlivoResourceInterface { + + + constructor(client, data = {}) { + let action = 'phlo/' + data.phloId + '/conference_bridge/' + data.nodeId + '/members/'; + super(action, PhloConfBridgeMember, idField, client); + extend(this, data); + this.action = action; + this.client = client; + } + + get(phloId, nodeId, memberAddress) { + + //Validate id first + let errors = validate([{ + field: 'id', + value: memberAddress, + validators: ['isRequired'] + }]); + if (errors) { + return errors; + } + + return new PhloConfBridgeMember(this.client, { phloId: phloId, nodeId, memberAddress }); + + } + +} diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index e03aa132..7d5a8430 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -20,7 +20,7 @@ export function Request(config) { headers: headers, json: true }; - + // console.log('action:', action, ', method:', method); if (method == 'GET' && options.formData !== '') { let query = '?' + queryString.stringify(params); options.url += query; @@ -1129,9 +1129,37 @@ export function Request(config) { }); } + // ============ Conference Bridge ============ // + + // Get conference details + else if (method == 'GET' && action == 'phlo/2a38dc9b-b48e-4e4e-b49b-0677c556989c/conference_bridge/f501faf1-0703-4619-86fa-d537b689e331/') { + resolve({ + response: {}, + body: + { + apiId: 'a7fc7bde-1aa3-449d-9d8a-3de1da5f8b71', + nodeId: 'f501faf1-0703-4619-86fa-d537b689e331', + phloId: '2a38dc9b-b48e-4e4e-b49b-0677c556989c', + name: 'Conference Bridge_1', + nodeType: 'conference_bridge', + createdOn: '2019-01-21 04:11:10.387710+00:00', + action: + 'phlo/2a38dc9b-b48e-4e4e-b49b-0677c556989c/conference_bridge/', + } + }) + } + + // Mute Member, Unmute Member & Leave Member + else if (method == 'POST' && action == 'phlo/2a38dc9b-b48e-4e4e-b49b-0677c556989c/conference_bridge/f501faf1-0703-4619-86fa-d537b689e331/members/919920700964') { + resolve({ + response: {}, + body: { api_id: '0000dae0-7596-4219-be84-a85efbbe8562', error: '' } + }) + } + // =========== If no combination found, raise issue ============================ else { - console.log('===>--->', method, action, '=>', params); + // console.log('===>--->', method, action, '=>', params); reject(new Error('not found')); } }); diff --git a/test/test.phloConferenceBridge.js b/test/test.phloConferenceBridge.js new file mode 100644 index 00000000..b78a58ec --- /dev/null +++ b/test/test.phloConferenceBridge.js @@ -0,0 +1,210 @@ +'use strict'; + +import { + PhloClient +} from '../lib/rest/client-test'; + +let authId = 'auth_id'; +let authToken = 'auth_token'; +let phloId = '2a38dc9b-b48e-4e4e-b49b-0677c556989c'; +let cbId = 'f501faf1-0703-4619-86fa-d537b689e331'; + +// Conference Bridge test cases +describe('phlo - conference bridge test cases', function () { + + let phloClient = new PhloClient(authId, authToken); + let phlo = phloClient.phlo(phloId); + + //************** Get Conf Details function ***************/ + + // ........Get Conferencr Bridge With Valid Id.......... + it('Get conference bridge details with Valid id', function (done) { + phloClient.phlo(phloId).conferenceBridge.get(cbId).then(function (result) { + // console.log('get conference bridge result', result); + done(); + }).catch(function (err) { + throw new Error("Test Failed. - wrong Conference Bridge Id ") + }) + }); + + // ........Get Conferencr Bridge With Invalid Id.......... + it('Get conference bridge details with Invvalid id', function (done) { + phloClient.phlo(phloId).conferenceBridge.get(cbId).then(function (result) { + // console.log('get conference bridge result', result); + throw new Error("Test Failed. -Invalid Conference Bridge Id") + }).catch(function (err) { + done(); + }) + }); + + + + // //************** Mute function ***************/ + + // ......Mute Function with Valid Number............ + it('Mute a Member with Valid Number - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member('919920700964').mute().then(function (result) { + // console.log('Mute a member result => ', result); + done(); + }).catch(function (err) { + throw new Error("Test Failed. - Enter Valid Phone Number") + }) + }); + + // ......Mute Function with Invalid Number............ + it('Mute a Member with Invalid Number - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member("9199207009645").mute().then(function (result) { + // console.log('Mute a member with Invalid Number => ', result); + throw new Error("Test Failed. - Invalid Phone Number") + + }).catch(function (err) { + done(); + }) + }); + + + // ......Mute Function with Valid Number Get method............. + it('Mute a Member with Valid Number using member.get() - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member.get('919920700964').mute().then(function (result) { + // console.log('Mute a member result => ', result); + done(); + }).catch(function (err) { + throw new Error("Test Failed. - Enter Valid Phone Number") + }) + }); + + // ......Mute Function with Invalid Number using Get method............ + it('Mute a Member with Invalid number using member.get() - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member.get("9199207009645").mute().then(function (result) { + // console.log('Mute a member with Invalid Number => ', result); + throw new Error("Test Failed. - Invalid Phone Number") + }).catch(function (err) { + done(); + }) + }); + + + // // ************** Unmute function ***************/ + // ......Unmute Function with Valid Number............ + it('Unmute a Member with Valid Number - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member('919920700964').unmute().then(function (result) { + // console.log('Mute a member result => ', result); + done(); + }).catch(function (err) { + throw new Error("Test Failed. - Enter Valid Phone Number") + }) + }); + // ......Unmute Function with Invalid Number............ + it('Unmute a Member with Invalid Number - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member("9199207009645").unmute().then(function (result) { + // console.log('Mute a member with Invalid Number => ', result); + throw new Error("Test Failed. - Invalid Phone Number") + + }).catch(function (err) { + done(); + }) + }); + + + // ......Unmute Function with Valid Number Get method............. + it('Unmute a Member with Valid Number using member.get() - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member.get('919920700964').unmute().then(function (result) { + // console.log('Mute a member result => ', result); + done(); + }).catch(function (err) { + throw new Error("Test Failed. - Enter Valid Phone Number") + }) + }); + + // ......Unmute Function with Invalid Number using Get method............ + it('Unmute a Member with Invalid number using member.get() - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member.get("9199207009645").unmute().then(function (result) { + // console.log('Mute a member with Invalid Number => ', result); + throw new Error("Test Failed. - Invalid Phone Number") + }).catch(function (err) { + done(); + }) + }); + + + + // it('Unmute a Member - Conference Bridge', function (done) { + // phlo.conferenceBridge(cbId).member('919920700964').unmute().then(function (result) { + // // console.log('Unmute a member result => ', result); + // done(); + // }).catch(function (err) { + // done(new Error("Test Failed. - Enter Correct Phone Number")) + // }) + // }); + + // it('Unmute a Member using member.get() - Conference Bridge', function (done) { + // phlo.conferenceBridge(cbId).member.get('919920700964').unmute().then(function (result) { + // // console.log('Unmute a member result => ', result); + // done(); + // }).catch(function (err) { + // done(new Error("Test Failed. - Enter Correct Phone Number")) + // }) + // }); + + + // //************** Leave function ***************/ + // ......Leave Function with Valid Number............ + it('Leave a Member with Valid Number - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member('919920700964').leave().then(function (result) { + // console.log('Mute a member result => ', result); + done(); + }).catch(function (err) { + throw new Error("Test Failed. - Enter Valid Phone Number") + }) + }); + // ......Leave Function with Invalid Number............ + it('Leave a Member with Invalid Number - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member("9199207009645").leave().then(function (result) { + // console.log('Mute a member with Invalid Number => ', result); + throw new Error("Test Failed. - Invalid Phone Number") + + }).catch(function (err) { + done(); + }) + }); + + + // ......Leave Function with Valid Number Get method............. + it('Leave a Member with Valid Number using member.get() - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member.get('919920700964').leave().then(function (result) { + // console.log('Mute a member result => ', result); + done(); + }).catch(function (err) { + throw new Error("Test Failed. - Enter Valid Phone Number") + }) + }); + + // ......Leave Function with Invalid Number using Get method............ + it('Leave a Member with Invalid number using member.get() - Conference Bridge', function (done) { + phlo.conferenceBridge(cbId).member.get("9199207009645").leave().then(function (result) { + // console.log('Mute a member with Invalid Number => ', result); + throw new Error("Test Failed. - Invalid Phone Number") + }).catch(function (err) { + done(); + }) + }); + // it('Leave a Member - Conference Bridge', function (done) { + // phlo.conferenceBridge(cbId).member('919920700964').leave().then(function (result) { + // // console.log('leave member result => ', result); + // done(); + // }).catch(function (err) { + // done(new Error("Test Failed. - Enter Correct Phone Number")) + // }) + // }); + + // it('Leave a Member using member.get() - Conference Bridge', function (done) { + // phlo.conferenceBridge(cbId).member.get('919920700964').leave().then(function (result) { + // // console.log('leave member result => ', result); + // done(); + // }).catch(function (err) { + // done(new Error("Test Failed. - Enter Correct Phone Number")) + // }) + // }); + +}); +