mirror of
https://github.com/donl/plivo-node.git
synced 2026-05-25 22:07:10 -06:00
commit
05fa8ba80d
11 changed files with 189 additions and 6 deletions
|
|
@ -1,5 +1,14 @@
|
|||
# Change Log
|
||||
|
||||
## [4.11.0](https://github.com/plivo/plivo-node/releases/tag/v4.11.0)(2020-10-30)
|
||||
- Change lookup API endpoint and response.
|
||||
|
||||
## [4.10.0](https://github.com/plivo/plivo-node/releases/tag/v4.10.0)(2020-09-21)
|
||||
- Add Lookup API support.
|
||||
|
||||
## [4.9.0](https://github.com/plivo/plivo-node/releases/tag/v4.8.0)(2020-08-25)
|
||||
- Add Powerpack for MMS
|
||||
|
||||
## [4.8.0](https://github.com/plivo/plivo-node/releases/tag/v4.8.0)(2020-07-23)
|
||||
- Add retries to multiple regions for voice requests.
|
||||
|
||||
|
|
|
|||
15
README.md
15
README.md
|
|
@ -77,6 +77,21 @@ client.calls.create(
|
|||
|
||||
```
|
||||
|
||||
### Lookup a number
|
||||
|
||||
```javascript
|
||||
let plivo = require('plivo');
|
||||
let client = new plivo.Client('AUTH_ID', 'AUTH_TOKEN');
|
||||
|
||||
client.lookup.get(
|
||||
"<number-goes-here>"
|
||||
).then(function(response) {
|
||||
console.log(response);
|
||||
}).catch(function(error) {
|
||||
console.log(error);
|
||||
});
|
||||
```
|
||||
|
||||
### Generate Plivo XML
|
||||
|
||||
```javascript
|
||||
|
|
|
|||
10
examples/lookup.js
Normal file
10
examples/lookup.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let plivo = require('plivo');
|
||||
let client = new plivo.Client('', '');
|
||||
|
||||
client.lookup.get(
|
||||
""
|
||||
).then(function(response) {
|
||||
console.log(response);
|
||||
}).catch(function(error) {
|
||||
console.log(error);
|
||||
});
|
||||
51
lib/resources/lookup.js
Normal file
51
lib/resources/lookup.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import {
|
||||
extend,
|
||||
validate
|
||||
} from '../utils/common.js';
|
||||
|
||||
import {
|
||||
PlivoResource,
|
||||
PlivoResourceInterface
|
||||
} from '../base';
|
||||
|
||||
import * as _ from "lodash";
|
||||
|
||||
const clientKey = Symbol();
|
||||
const action = 'Number/'; // unused as it is overridden, only for unit tests
|
||||
const idField = 'OVERRIDDEN';
|
||||
const LOOKUP_API_BASE_URL = 'https://lookup.plivo.com/v1/Number'
|
||||
|
||||
export class Number extends PlivoResource {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Number, idField, client);
|
||||
extend(this, data);
|
||||
this[clientKey] = client;
|
||||
}
|
||||
}
|
||||
|
||||
export class LookupInterface extends PlivoResourceInterface {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Number, idField, client);
|
||||
extend(this, data);
|
||||
this[clientKey] = client;
|
||||
}
|
||||
|
||||
get(number, type = 'carrier') {
|
||||
let errors = validate([{
|
||||
field: 'number',
|
||||
value: number,
|
||||
validators: ['isRequired']
|
||||
}]);
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
let params = {
|
||||
type: type,
|
||||
overrideUrl: `${LOOKUP_API_BASE_URL}/${number}`,
|
||||
};
|
||||
|
||||
return super.get(number, params);
|
||||
}
|
||||
}
|
||||
|
|
@ -75,6 +75,14 @@ export class Powerpack extends PlivoResource {
|
|||
}
|
||||
}
|
||||
|
||||
if (params.service != undefined) {
|
||||
if (query == '') {
|
||||
query = 'service=' + params.service;
|
||||
} else {
|
||||
query += '&service=' + params.service;
|
||||
}
|
||||
}
|
||||
|
||||
query = query + '&';
|
||||
|
||||
return query;
|
||||
|
|
@ -92,15 +100,21 @@ export class Powerpack extends PlivoResource {
|
|||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
add_number(number) {
|
||||
add_number(number, service = '') {
|
||||
var params = {};
|
||||
params['rent'] = 'false';
|
||||
if (service != '') {
|
||||
params['service'] = service
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
add_tollfree(tollfree) {
|
||||
add_tollfree(tollfree, service = '') {
|
||||
var params = {};
|
||||
params['rent'] = 'false';
|
||||
if (service != '') {
|
||||
params['service'] = service
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
|
|
@ -134,12 +148,18 @@ export class Powerpack extends PlivoResource {
|
|||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', params);
|
||||
}
|
||||
find_shortcode(shortcode) {
|
||||
find_shortcode(shortcode, service = '') {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/' + shortcode + '/';
|
||||
if (service != '') {
|
||||
path = path + '&service=' + service
|
||||
}
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
find_tollfree(tollfree) {
|
||||
find_tollfree(tollfree, service = '') {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
if (service != '') {
|
||||
path = path + '&service=' + service
|
||||
}
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
buy_add_number(params) {
|
||||
|
|
@ -151,6 +171,9 @@ export class Powerpack extends PlivoResource {
|
|||
if (params.country_iso2 != undefined) {
|
||||
params['country_iso'] = params.country_iso2;
|
||||
}
|
||||
if (params.service != undefined) {
|
||||
params['service'] = params.service;
|
||||
}
|
||||
var test = super.customexecuteGetNumberAction('PhoneNumber/', 'GET', params);
|
||||
return test.then((val) => {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + val + '/';
|
||||
|
|
@ -229,6 +252,9 @@ export class Numbers extends PlivoResource {
|
|||
if (params.country_iso2 != undefined) {
|
||||
params['country_iso'] = params.country_iso2;
|
||||
}
|
||||
if (params.service != undefined) {
|
||||
params['service'] = params.service;
|
||||
}
|
||||
var test = super.customexecuteGetNumberAction('PhoneNumber/', 'GET', params);
|
||||
return test.then((val) => {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + val + '/';
|
||||
|
|
@ -294,6 +320,13 @@ export class Numbers extends PlivoResource {
|
|||
query += '&offset=' + params.offset;
|
||||
}
|
||||
}
|
||||
if (params.service != undefined) {
|
||||
if (query == '') {
|
||||
query = 'service=' + params.service;
|
||||
} else {
|
||||
query += '&service=' + params.service;
|
||||
}
|
||||
}
|
||||
|
||||
query = query + '&';
|
||||
|
||||
|
|
@ -304,9 +337,12 @@ export class Numbers extends PlivoResource {
|
|||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
add(number) {
|
||||
add(number, service='') {
|
||||
var params = {};
|
||||
params['rent'] = 'false';
|
||||
if (service != '') {
|
||||
params['service'] = service
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ import {
|
|||
import {
|
||||
MessageInterface
|
||||
} from '../resources/messages.js';
|
||||
import {
|
||||
LookupInterface
|
||||
} from '../resources/lookup.js';
|
||||
import {
|
||||
PowerpackInterface
|
||||
} from '../resources/powerpacks.js';
|
||||
|
|
@ -81,6 +84,7 @@ export class Client {
|
|||
this.conferences = new ConferenceInterface(client);
|
||||
this.endpoints = new EndpointInterface(client);
|
||||
this.messages = new MessageInterface(client);
|
||||
this.lookup = new LookupInterface(client);
|
||||
this.powerpacks = new PowerpackInterface(client);
|
||||
this.numbers = new NumberInterface(client);
|
||||
this.pricings = new PricingInterface(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 { LookupInterface } from "../resources/lookup";
|
||||
import { PowerpackInterface } from "../resources/powerpacks";
|
||||
import { NumberInterface } from "../resources/numbers";
|
||||
import { PricingInterface } from "../resources/pricings";
|
||||
|
|
@ -75,6 +76,7 @@ export class Client {
|
|||
this.conferences = new ConferenceInterface(client);
|
||||
this.endpoints = new EndpointInterface(client);
|
||||
this.messages = new MessageInterface(client);
|
||||
this.lookup = new LookupInterface(client);
|
||||
this.powerpacks = new PowerpackInterface(client);
|
||||
this.numbers = new NumberInterface(client);
|
||||
this.pricings = new PricingInterface(client);
|
||||
|
|
|
|||
|
|
@ -905,6 +905,36 @@ export function Request(config) {
|
|||
});
|
||||
}
|
||||
|
||||
// ============= Lookup ===================
|
||||
else if (action == 'Lookup/Number/+14154305555' && method == 'GET') {
|
||||
resolve({
|
||||
response: {},
|
||||
body: {
|
||||
api_id: "930692a3-6f09-45b5-80f5-5585565fb30e",
|
||||
phone_number: "+14154305555",
|
||||
country: {
|
||||
iso2: "US",
|
||||
iso3: "USA",
|
||||
name: "United States"
|
||||
},
|
||||
format: {
|
||||
e164: "+14154305555",
|
||||
international: "+1 415-430-5555",
|
||||
national: "(415) 430-5555",
|
||||
rfc3966: "tel:+1-415-430-5555"
|
||||
},
|
||||
carrier: {
|
||||
mobile_country_code: "310",
|
||||
mobile_network_code: "160",
|
||||
name: "Cingular Wireless",
|
||||
ported: "yes",
|
||||
type: "mobile"
|
||||
},
|
||||
resource_uri: "/v1/Lookup/Number/+14154305555?type=carrier"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ============= Pricings ===================
|
||||
else if (method == 'GET' && action == 'Pricing/') {
|
||||
resolve({
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ export function Request(config) {
|
|||
options.url = apiVoiceUris[0] + config.authId + '/' + action;
|
||||
delete params.is_voice_request;
|
||||
isVoiceReq = true;
|
||||
} else if (params.hasOwnProperty('override_url')) {
|
||||
// currently used by Lookup API but is generic enough to be used
|
||||
// by any product in future.
|
||||
options.url = params.override_url;
|
||||
delete params.override_url;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plivo",
|
||||
"version": "4.8.0",
|
||||
"version": "4.11.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": [
|
||||
|
|
|
|||
21
test/lookup.js
Normal file
21
test/lookup.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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('LookupInterface', function() {
|
||||
it('should lookup number', function() {
|
||||
return client.lookup.get('+14154305555')
|
||||
.then(function(number) {
|
||||
assert.equal(number.numberFormat.e164, '+14154305555')
|
||||
assert.equal(number.phoneNumber, '+14154305555')
|
||||
assert.equal(number.resourceUri, '/v1/Number/+14154305555?type=carrier')
|
||||
})
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue