mirror of
https://github.com/donl/plivo-node.git
synced 2026-05-25 22:07:10 -06:00
Merge branch 'master' of github.com:plivo/plivo-node into post-feedback
This commit is contained in:
commit
8f05a6fbf6
11 changed files with 702 additions and 26 deletions
|
|
@ -1,5 +1,11 @@
|
|||
# Change Log
|
||||
|
||||
## [4.1.8](https://github.com/plivo/plivo-node/releases/tag/v4.1.8)(2019-12-20)
|
||||
- Add Powerpack support.
|
||||
|
||||
## [4.1.7](https://github.com/plivo/plivo-node/releases/tag/v4.1.7)(2019-12-04)
|
||||
- Add MMS support.
|
||||
|
||||
## [4.1.6](https://github.com/plivo/plivo-node/releases/tag/v4.1.6)(2019-11-14)
|
||||
- Fix list APIs to return meta in response.
|
||||
|
||||
|
|
|
|||
32
examples/messages.js
Normal file
32
examples/messages.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
let plivo = require('plivo');
|
||||
let client = new plivo.Client('', '');
|
||||
|
||||
let optionalParams = {};
|
||||
client.messages.create(
|
||||
"", //from
|
||||
"", // to
|
||||
"", // text
|
||||
{
|
||||
type: "", // sms or mms
|
||||
method: "", // GET or POST callback method
|
||||
url: "", // callback url
|
||||
media_urls: [".gif", ".jpg"] // to send MMS, mention the media urls
|
||||
}
|
||||
|
||||
).then(function (message_created) {
|
||||
console.log(message_created)
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
|
||||
// get MMS Media detail
|
||||
client.messages.get("your message uuid").then(function (message) {
|
||||
return client.messages.listMedia(message.messageUuid)
|
||||
})
|
||||
.then(function (result) {
|
||||
console.log("\n============ list Media ===========\n", result)
|
||||
})
|
||||
.catch(function (response) {
|
||||
console.log("\n============ Error :: ===========\n", response);
|
||||
});
|
||||
39
examples/powerpacks.js
Normal file
39
examples/powerpacks.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
var Plivo = require('../dist/rest/client.js');
|
||||
var client = new Plivo.Client();
|
||||
|
||||
var params = {
|
||||
sticky_sender: true,
|
||||
local_connect: true
|
||||
};
|
||||
// create powerpack
|
||||
client.powerpacks.create("node sdk test", params).then(function (result) {
|
||||
console.log(result)
|
||||
});
|
||||
|
||||
// get powerpack
|
||||
client.powerpacks.get("0166c910-1268-47c7-bf30-f5809ee843b9").then(
|
||||
function (result) {
|
||||
console.log(result)
|
||||
});
|
||||
|
||||
// list powerpack
|
||||
client.powerpacks.list().then(
|
||||
function (result) {
|
||||
console.log(result)
|
||||
});
|
||||
// list numbers
|
||||
client.powerpacks.get("0166c910-1268-47c7-bf30-f5809ee843b9").then(
|
||||
function (powerpack) {
|
||||
return powerpack.list_numbers()
|
||||
})
|
||||
.then(function (result) {
|
||||
console.log("\n============ list numbers ===========\n", result)
|
||||
})
|
||||
// find number
|
||||
client.powerpacks.get("0166c910-1268-47c7-bf30-f5809ee843b9").then(
|
||||
function (powerpack) {
|
||||
return powerpack.find_number('1234')
|
||||
})
|
||||
.then(function (result) {
|
||||
console.log("\n============ list numbers ===========\n", result)
|
||||
})
|
||||
41
lib/base.js
41
lib/base.js
|
|
@ -75,6 +75,47 @@ export class PlivoResource {
|
|||
});
|
||||
});
|
||||
}
|
||||
customexecuteAction(url, method = 'GET', params = {}) {
|
||||
let client = this[clientKey];
|
||||
let idField = this[idKey];
|
||||
return new Promise((resolve, reject) => {
|
||||
client(method, url, params)
|
||||
.then(response => {
|
||||
resolve(new PlivoGenericResponse(response.body, idField));
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
customexecuteGetNumberAction(url, method = 'GET', params = {}) {
|
||||
let client = this[clientKey];
|
||||
let idField = this[idKey];
|
||||
let number = "";
|
||||
let promise = client(method, url, params).then(response => {
|
||||
number = response.body.objects[0].number;
|
||||
return number;
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
return error;
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
getMetaResponse(url, method = 'GET', params = {}) {
|
||||
let client = this[clientKey];
|
||||
let idField = this[idKey];
|
||||
let count = 0;
|
||||
return new Promise((resolve, reject) => {
|
||||
client(method, url, params)
|
||||
.then(response => {
|
||||
count = response.body.meta.totalCount;
|
||||
resolve(count);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class PlivoResourceInterface {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
|
||||
import { extend, validate } from '../utils/common.js';
|
||||
import { PlivoResource, PlivoResourceInterface } from '../base';
|
||||
import {
|
||||
extend,
|
||||
validate
|
||||
} from '../utils/common.js';
|
||||
import {
|
||||
PlivoResource,
|
||||
PlivoResourceInterface
|
||||
} from '../base';
|
||||
import * as _ from "lodash";
|
||||
|
||||
const clientKey = Symbol();
|
||||
const action = 'Message/';
|
||||
const idField = 'messageUuid';
|
||||
|
||||
|
|
@ -18,10 +24,18 @@ export class Message extends PlivoResource {
|
|||
|
||||
if (idField in data) {
|
||||
this.id = data[idField];
|
||||
}
|
||||
};
|
||||
|
||||
extend(this, data);
|
||||
}
|
||||
|
||||
listMedia() {
|
||||
return super.executeAction(this.id + '/Media/', 'Get', {});
|
||||
}
|
||||
deleteMedia() {
|
||||
return super.executeAction(this.id + '/Media/', 'Delete', {});
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Represents a Message Interface
|
||||
|
|
@ -35,6 +49,7 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
constructor(client, data = {}) {
|
||||
super(action, Message, idField, client);
|
||||
extend(this, data);
|
||||
this[clientKey] = client;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,9 +59,10 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
* @param {string} dst - destination number
|
||||
* @param {string} text - text to send
|
||||
* @param {object} optionalParams - Optional Params to send message
|
||||
* @param {string} [optionalParams.type] - The type of message. Should be `sms` for a text message. Defaults to `sms`.
|
||||
* @param {string} [optionalParams.type] - The type of message. Should be `sms` or `mms`. Defaults to `sms`.
|
||||
* @param {string} [optionalParams.url] The URL to which with the status of the message is sent.
|
||||
* @param {string} [optionalParams.method] The method used to call the url. Defaults to POST.
|
||||
* @param {list} [optionalParams.media_urls] For sending mms, specify the media urls in list of string
|
||||
* @param {boolean} [optionalParams.log] If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
|
||||
* @promise {object} return {@link PlivoGenericMessage} object if success
|
||||
* @fail {Error} return Error
|
||||
|
|
@ -62,18 +78,20 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
* @param {string} dst - destination number
|
||||
* @param {string} text - text to send
|
||||
* @param {object} optionalParams - Optional Params to send message
|
||||
* @param {string} [optionalParams.type] - The type of message. Should be `sms` for a text message. Defaults to `sms`.
|
||||
* @param {string} [optionalParams.type] - The type of message. Should be `sms` or `mms`. Defaults to `sms`.
|
||||
* @param {string} [optionalParams.url] The URL to which with the status of the message is sent.
|
||||
* @param {string} [optionalParams.method] The method used to call the url. Defaults to POST.
|
||||
* @param {boolean} [optionalParams.log] If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
|
||||
* @param {Array} [optionalParams.media_urls] For sending mms, specify the media urls in list of string
|
||||
* @promise {object} return {@link PlivoGenericMessage} object if success
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
create(src, dst, text, optionalParams, powerpackUUID) {
|
||||
let errors = validate([
|
||||
{ field: 'dst', value: dst, validators: ['isRequired'] },
|
||||
{ field: 'text', value: text, validators: ['isRequired'] },
|
||||
]);
|
||||
let errors = validate([{
|
||||
field: 'dst',
|
||||
value: dst,
|
||||
validators: ['isRequired']
|
||||
}]);
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
|
|
@ -113,9 +131,11 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
get(id) {
|
||||
let errors = validate([
|
||||
{ field: 'id', value: id, validators: ['isRequired'] }
|
||||
]);
|
||||
let errors = validate([{
|
||||
field: 'id',
|
||||
value: id,
|
||||
validators: ['isRequired']
|
||||
}]);
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
|
|
@ -123,4 +143,16 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
|
||||
return super.get(id);
|
||||
}
|
||||
|
||||
listMedia(messageUUID) {
|
||||
return new Message(this[clientKey], {
|
||||
id: messageUUID
|
||||
}).listMedia();
|
||||
}
|
||||
|
||||
deleteMedia(messageUUID) {
|
||||
return new Message(this[clientKey], {
|
||||
id: messageUUID
|
||||
}).deleteMedia();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
409
lib/resources/powerpacks.js
Normal file
409
lib/resources/powerpacks.js
Normal file
|
|
@ -0,0 +1,409 @@
|
|||
import { extend, validate } from '../utils/common.js';
|
||||
import { PlivoResource, PlivoResourceInterface } from '../base';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
const action = 'Powerpack/';
|
||||
const idField = 'uuid';
|
||||
const numberpoolIdField = 'numberPool';
|
||||
const clientKey = Symbol();
|
||||
|
||||
/**
|
||||
* Represents a Powerpack
|
||||
* @constructor
|
||||
* @param {function} client - make api call
|
||||
* @param {object} [data] - data of call
|
||||
*/
|
||||
export class Powerpack extends PlivoResource {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Powerpack, idField, client);
|
||||
|
||||
if (idField in data) {
|
||||
this.uuid = data[idField];
|
||||
}
|
||||
if (numberpoolIdField in data) {
|
||||
this.number_pool_id = data[numberpoolIdField].split('/')[5];
|
||||
}
|
||||
this.number_pool = new NumberPool(client, {
|
||||
number_pool_id: this.number_pool_id
|
||||
});
|
||||
extend(this, data);
|
||||
}
|
||||
|
||||
list_numbers(params) {
|
||||
let query = this.search_query(params);
|
||||
var queryparams = {};
|
||||
queryparams['search'] = 'hack';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/?' + query;
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', queryparams);
|
||||
}
|
||||
|
||||
search_query(params) {
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
var query = '';
|
||||
if (params.type != undefined) {
|
||||
query = 'type=' + params.type;
|
||||
}
|
||||
if (params.starts_with != undefined) {
|
||||
if (query == '') {
|
||||
query = 'starts_with=' + params.starts_with;
|
||||
} else {
|
||||
query += '&starts_with=' + params.starts_with;
|
||||
}
|
||||
}
|
||||
// return params;
|
||||
if (params.country_iso2 != undefined) {
|
||||
if (query == '') {
|
||||
query = 'country_iso2=' + params.country_iso2;
|
||||
} else {
|
||||
query += '&country_iso2=' + params.country_iso2;
|
||||
}
|
||||
}
|
||||
if (params.limit != undefined) {
|
||||
if (query == '') {
|
||||
query = 'limit=' + params.limit;
|
||||
} else {
|
||||
query += '&limit=' + params.limit;
|
||||
}
|
||||
}
|
||||
if (params.offset != undefined) {
|
||||
if (query == '') {
|
||||
query = 'offset=' + params.offset;
|
||||
} else {
|
||||
query += '&offset=' + params.offset;
|
||||
}
|
||||
}
|
||||
|
||||
query = query + '&';
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
count_numbers(params) {
|
||||
let query = this.search_query(params);
|
||||
var queryparams = {};
|
||||
queryparams['search'] = 'hack';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/?' + query;
|
||||
return super.getMetaResponse(path.toString().trim(), 'GET', queryparams);
|
||||
}
|
||||
|
||||
find_number(number) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
add_number(number) {
|
||||
var params = {};
|
||||
params['rent'] = 'false';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
remove_number(number, unrent = false) {
|
||||
var params = {};
|
||||
if (typeof unrent === 'boolean') {
|
||||
params['unrent'] = unrent.toString();
|
||||
} else {
|
||||
params['unrent'] = unrent;
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE', params);
|
||||
}
|
||||
list_shortcodes(params) {
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', params);
|
||||
}
|
||||
find_shortcode(shortcode) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/' + shortcode + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
buy_add_number(params) {
|
||||
var number = params.number;
|
||||
var rentparam = {};
|
||||
rentparam['rent'] = 'true';
|
||||
if (params.number == undefined) {
|
||||
try {
|
||||
if (params.country_iso2 != undefined) {
|
||||
params['country_iso'] = params.country_iso2;
|
||||
}
|
||||
var test = super.customexecuteGetNumberAction('PhoneNumber/', 'GET', params);
|
||||
return test.then((val) => {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + val + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', rentparam);
|
||||
});
|
||||
} catch (err) {
|
||||
return err.message;
|
||||
}
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', rentparam);
|
||||
}
|
||||
|
||||
/**
|
||||
* update powerpack
|
||||
* @method
|
||||
* @param {object} params - to update Powerpack
|
||||
* @param {string} [params.name]
|
||||
* @param {string} [params.application_type]
|
||||
* @param {string} [params.application_id]
|
||||
* @param {string} [params.sticky_sender]
|
||||
* @param {string} [params.local_connect]
|
||||
|
||||
* @promise {object} return {@link Powerpack} object
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
update(params) {
|
||||
let path = 'Powerpack/' + this.uuid + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete Powerpack
|
||||
* @method
|
||||
* @promise {object} return true on success
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
delete(unrent_numbers = false) {
|
||||
let params = {};
|
||||
if (typeof unrent_numbers === 'boolean') {
|
||||
params.unrent_numbers = unrent_numbers.toString();
|
||||
}
|
||||
let path = 'Powerpack/' + this.uuid + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE', params);
|
||||
}
|
||||
}
|
||||
const numberPoolField = 'number_pool_id';
|
||||
export class NumberPool extends PlivoResource {
|
||||
constructor(client, data = {}) {
|
||||
super(action, NumberPool, numberPoolField, client);
|
||||
this.numbers = new Numbers(client, {
|
||||
number_pool_id: data.number_pool_id
|
||||
});
|
||||
this.shortcodes = new Shortcode(client, {
|
||||
number_pool_id: data.number_pool_id
|
||||
});
|
||||
|
||||
extend(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
export class Numbers extends PlivoResource {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Numbers, numberPoolField, client);
|
||||
extend(this, data);
|
||||
}
|
||||
buy_add_number(params) {
|
||||
var number = params.number;
|
||||
var rentparam = {};
|
||||
rentparam['rent'] = 'true';
|
||||
if (params.number == undefined) {
|
||||
try {
|
||||
if (params.country_iso2 != undefined) {
|
||||
params['country_iso'] = params.country_iso2;
|
||||
}
|
||||
var test = super.customexecuteGetNumberAction('PhoneNumber/', 'GET', params);
|
||||
return test.then((val) => {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + val + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', rentparam);
|
||||
});
|
||||
} catch (err) {
|
||||
return err.message;
|
||||
}
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', rentparam);
|
||||
}
|
||||
|
||||
list(params) {
|
||||
let query = this.search_query(params);
|
||||
var queryparams = {};
|
||||
queryparams['search'] = 'hack';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number//?' + query;
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', queryparams);
|
||||
}
|
||||
count(params) {
|
||||
let query = this.search_query(params);
|
||||
var queryparams = {};
|
||||
queryparams['search'] = 'hack';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number//?' + query;
|
||||
return super.getMetaResponse(path.toString().trim(), 'GET', queryparams);
|
||||
}
|
||||
|
||||
search_query(params) {
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
var query = '';
|
||||
if (params.type != undefined) {
|
||||
query = 'type=' + params.type;
|
||||
}
|
||||
if (params.starts_with != undefined) {
|
||||
if (query == '') {
|
||||
query = 'starts_with=' + params.starts_with;
|
||||
} else {
|
||||
query += '&starts_with=' + params.starts_with;
|
||||
}
|
||||
}
|
||||
// return params;
|
||||
if (params.country_iso2 != undefined) {
|
||||
if (query == '') {
|
||||
query = 'country_iso2=' + params.country_iso2;
|
||||
} else {
|
||||
query += '&country_iso2=' + params.country_iso2;
|
||||
}
|
||||
}
|
||||
if (params.limit != undefined) {
|
||||
if (query == '') {
|
||||
query = 'limit=' + params.limit;
|
||||
} else {
|
||||
query += '&limit=' + params.limit;
|
||||
}
|
||||
}
|
||||
if (params.offset != undefined) {
|
||||
if (query == '') {
|
||||
query = 'offset=' + params.offset;
|
||||
} else {
|
||||
query += '&offset=' + params.offset;
|
||||
}
|
||||
}
|
||||
|
||||
query = query + '&';
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
find(number) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
add(number) {
|
||||
var params = {};
|
||||
params['rent'] = 'false';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
remove(number, unrent = false) {
|
||||
var params = {};
|
||||
if (typeof unrent === 'boolean') {
|
||||
params['unrent'] = unrent.toString();
|
||||
} else {
|
||||
params['unrent'] = unrent;
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE', params);
|
||||
}
|
||||
}
|
||||
export class Shortcode extends PlivoResource {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Shortcode, numberPoolField, client);
|
||||
extend(this, data);
|
||||
this.number_pool_id = data.number_pool_id;
|
||||
}
|
||||
list(params) {
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', params);
|
||||
}
|
||||
find(shortcode) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/' + shortcode + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Represents a Powerpack interface
|
||||
* @constructor
|
||||
* @param {function} client - make api call
|
||||
* @param {object} [data] - data of call
|
||||
*/
|
||||
export class PowerpackInterface extends PlivoResourceInterface {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Powerpack, idField, client);
|
||||
extend(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Powerpack by given id
|
||||
* @method
|
||||
* @param {string} uuid - id of Powerpack
|
||||
* @promise {object} return {@link Powerpack} object
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
get(uuid) {
|
||||
return super.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* create Powerpack
|
||||
* @method
|
||||
* @param {string} name - name of Powerpack
|
||||
* @param {object} params - params to create Powerpack
|
||||
* @param {string} [params.sticky_sender] -
|
||||
* @param {string} [params.local_connect]
|
||||
* @param {string} [params.application_type]
|
||||
* @param {string} [params.application_id]
|
||||
* @promise {object} return {@link PlivoGenericResponse} object
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
create(name, params = {}) {
|
||||
let errors = validate([
|
||||
{
|
||||
field: 'name',
|
||||
value: name,
|
||||
validators: [ 'isRequired', 'isString' ]
|
||||
}
|
||||
]);
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
params.name = name;
|
||||
|
||||
return super.create(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* update Powerpack
|
||||
* @method
|
||||
* @param {string} uuid - id of Powerpack
|
||||
* @param {object} params - to update Powerpack
|
||||
* @param {string} [params.name]
|
||||
* @param {string} [params.sticky_sender]
|
||||
* @param {string} [params.local_connect]
|
||||
* @param {string} [params.application_type]
|
||||
* @param {string} [params.application_id]
|
||||
* @promise {object} return {@link Powerpack} object
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
update(uuid, params) {
|
||||
let errors = validate([
|
||||
{
|
||||
field: 'uuid',
|
||||
value: uuid,
|
||||
validators: [ 'isRequired' ]
|
||||
}
|
||||
]);
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return new Powerpack(this[clientKey], {
|
||||
uuid: uuid
|
||||
}).update(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Call Detail
|
||||
* @method
|
||||
* @param {object} params - params to get all call details.
|
||||
* @promise {object[]} returns list of Call Object
|
||||
* @fail {Error} returns Error
|
||||
*/
|
||||
list(params) {
|
||||
return super.list(params);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import { ApplicationInterface } from '../resources/applications.js';
|
|||
import { ConferenceInterface } from '../resources/conferences.js';
|
||||
import { EndpointInterface } from '../resources/endpoints.js';
|
||||
import { MessageInterface } from '../resources/messages.js';
|
||||
import { PowerpackInterface } from '../resources/powerpacks.js';
|
||||
import { NumberInterface } from '../resources/numbers.js';
|
||||
import { PricingInterface } from '../resources/pricings.js';
|
||||
import { RecordingInterface } from '../resources/recordings.js';
|
||||
|
|
@ -47,6 +48,7 @@ export class Client {
|
|||
this.conferences = new ConferenceInterface(client);
|
||||
this.endpoints = new EndpointInterface(client);
|
||||
this.messages = new MessageInterface(client);
|
||||
this.powerpacks = new PowerpackInterface(client);
|
||||
this.numbers = new NumberInterface(client);
|
||||
this.pricings = new PricingInterface(client);
|
||||
this.recordings = new RecordingInterface(client);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { ApplicationInterface } from "../resources/applications";
|
|||
import { ConferenceInterface } from "../resources/conferences";
|
||||
import { EndpointInterface } from "../resources/endpoints";
|
||||
import { MessageInterface } from "../resources/messages";
|
||||
import { PowerpackInterface } from "../resources/powerpacks";
|
||||
import { NumberInterface } from "../resources/numbers";
|
||||
import { PricingInterface } from "../resources/pricings";
|
||||
import { RecordingInterface } from "../resources/recordings";
|
||||
|
|
@ -61,6 +62,7 @@ export class Client {
|
|||
this.conferences = new ConferenceInterface(client);
|
||||
this.endpoints = new EndpointInterface(client);
|
||||
this.messages = new MessageInterface(client);
|
||||
this.powerpacks = new PowerpackInterface(client);
|
||||
this.numbers = new NumberInterface(client);
|
||||
this.pricings = new PricingInterface(client);
|
||||
this.recordings = new RecordingInterface(client);
|
||||
|
|
@ -123,4 +125,4 @@ export class PhloClient {
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plivo",
|
||||
"version": "4.1.6",
|
||||
"version": "4.1.8",
|
||||
"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": [
|
||||
|
|
|
|||
|
|
@ -1,59 +1,81 @@
|
|||
import assert from 'assert';
|
||||
import sinon from 'sinon';
|
||||
import {Client} from '../lib/rest/client-test';
|
||||
import {PlivoGenericResponse} from '../lib/base.js';
|
||||
import {
|
||||
Client
|
||||
} from '../lib/rest/client-test';
|
||||
import {
|
||||
PlivoGenericResponse
|
||||
} from '../lib/base.js';
|
||||
|
||||
let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');
|
||||
|
||||
describe('message', function () {
|
||||
it('should get message', function () {
|
||||
return client.messages.get(1)
|
||||
.then(function(message) {
|
||||
.then(function (message) {
|
||||
assert.equal(message.id, 1)
|
||||
})
|
||||
});
|
||||
|
||||
it('list messages', function () {
|
||||
return client.messages.list()
|
||||
.then(function(messages) {
|
||||
.then(function (messages) {
|
||||
assert.equal(messages.length, 2)
|
||||
})
|
||||
});
|
||||
|
||||
it('should create message via interface', function () {
|
||||
return client.messages.create('src', 'dst', 'text')
|
||||
.then(function(message){
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
.then(function (message) {
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
})
|
||||
});
|
||||
|
||||
it('should send message via interface', function () {
|
||||
return client.messages.send('src', 'dst', 'text')
|
||||
.then(function(message){
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
.then(function (message) {
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
it('should throw error - id is required via interface', function () {
|
||||
return client.messages.get()
|
||||
.catch(function(err){
|
||||
.catch(function (err) {
|
||||
assert.equal(err.message, 'Missing mandatory field: id')
|
||||
})
|
||||
});
|
||||
|
||||
it('should throw error - src and powerpack both not present', function () {
|
||||
return client.messages.send(null, 'dst', 'text', {}, null)
|
||||
.catch(function(err){
|
||||
.catch(function (err) {
|
||||
assert.equal(err.message, 'Neither of src or powerpack uuid present, either one is required')
|
||||
})
|
||||
});
|
||||
|
||||
it('should throw error - src and powerpack both are present', function () {
|
||||
return client.messages.send('91235456917375', 'dst', 'text', {}, '916386027476')
|
||||
.catch(function(err){
|
||||
.catch(function (err) {
|
||||
assert.equal(err.message, 'Either of src or powerpack uuid, both of them are present')
|
||||
})
|
||||
});
|
||||
|
||||
it('list media', function (done) {
|
||||
client.messages.get('xyz')
|
||||
.then(function (message) {
|
||||
return message.listMedia({})
|
||||
})
|
||||
.then(function (mmsmedia) {
|
||||
assert(mmsmedia instanceof PlivoGenericResponse)
|
||||
done()
|
||||
})
|
||||
});
|
||||
it('should list media via plivo interface!', function (done) {
|
||||
client.messages.listMedia('xyz')
|
||||
.then(function (mmsMedia) {
|
||||
assert(mmsMedia)
|
||||
done()
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
91
test/powerpacks.js
Normal file
91
test/powerpacks.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import assert from 'assert';
|
||||
import sinon from 'sinon';
|
||||
import {
|
||||
Client
|
||||
} from '../lib/rest/client-test';
|
||||
import {
|
||||
PlivoGenericResponse
|
||||
} from '../lib/base.js';
|
||||
|
||||
let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');
|
||||
|
||||
describe('PowerpackInterface', function () {
|
||||
it('Get Details of a Powerpack', function () {
|
||||
return client.powerpacks.get('5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46')
|
||||
.then(function (powerpack) {
|
||||
assert.equal(powerpack.uuid, '5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46')
|
||||
})
|
||||
});
|
||||
it('should create powerpack via interface', function () {
|
||||
return client.powerpacks.create("node sdk test")
|
||||
.then(function (powerpack) {
|
||||
assert.equal(powerpack.name, 'node sdk test')
|
||||
})
|
||||
});
|
||||
|
||||
it('list powerpacks numbers via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.list_numbers()
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.notEqual(result.length, 0)
|
||||
})
|
||||
});
|
||||
|
||||
it('delete powerpacks via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.delete()
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.notEqual(result.response, "success")
|
||||
})
|
||||
});
|
||||
it('list powerpacks numbers via interface', function () {
|
||||
return client.powerpacks.list()
|
||||
.then(function (powerpack) {
|
||||
assert.notEqual(powerpack.length, 0)
|
||||
})
|
||||
});
|
||||
|
||||
it('add numbers to powerpack via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.add_number('14845733595')
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.Equal(result.number, "14845733595")
|
||||
})
|
||||
});
|
||||
|
||||
it('find numbers to powerpack via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.find_number('14845733595')
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.Equal(result.number, "14845733595")
|
||||
})
|
||||
});
|
||||
|
||||
it('find shortcode via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.find_shortcode('4444444')
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.Equal(result.shortcode, "4444444")
|
||||
})
|
||||
});
|
||||
it('list shortcode via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.list_shortcode('4444444')
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.notEqual(result.length, 0)
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue