mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-01 06:12:16 -06:00
* Added phlo client. * Finished implementaiton of initializing phlo client. * Finished logic for v2 methods of multiparty call(not members). * Added test cases for multiparty call. * Finished logic for phlo get api. * Added member method structure. * Finished implementation of phlo.run(). * Finished api calls for multi party(except abort transfer). * Deleted old rest.js file. * Finished abortTranfer implementation with test cases. * Finished implementation of member.resumeCall(). * Finished all member functions. * Reverted debugging logic. * Removed console.log * Added samples for all apis. method structure change for abort transfer. * Resolved nsp issue. * Audit fix. * Package Lock Fix. * Added test proxy for test cases. * Resolved issue in request.js json format. * Improved comments. * Added test cases for .get() methods. * Removed async await to support older browsers. * Modified examples of phlo, removed async await. * Resolved example issues, remove auth credentials. * Removed es6 declaration syntaxes from phlo example. * Added logic to pass payload. * changed beta version 4.1-beta.1 * changed beta version 4.1-beta.1 * changed beta version 4.1-beta.1 * changes in changelog & readme- Add PHLO support
118 lines
No EOL
4 KiB
JavaScript
118 lines
No EOL
4 KiB
JavaScript
import { Request } from './request.js';
|
|
import { camelCaseRequestWrapper } from './utils';
|
|
import { name, version } from '../../package.json';
|
|
import { Phlo, PhloInterface } from "../resources/phlo";
|
|
import { CallInterface } from "../resources/call";
|
|
import { SubaccountInterface, AccountInterface } from "../resources/accounts";
|
|
import { ApplicationInterface } from "../resources/applications";
|
|
import { ConferenceInterface } from "../resources/conferences";
|
|
import { EndpointInterface } from "../resources/endpoints";
|
|
import { MessageInterface } from "../resources/messages";
|
|
import { NumberInterface } from "../resources/numbers";
|
|
import { PricingInterface } from "../resources/pricings";
|
|
import { RecordingInterface } from "../resources/recordings";
|
|
import { Response } from "../utils/plivoxml";
|
|
import { validateSignature } from "../utils/security";
|
|
|
|
exports.Response = function () {
|
|
return new Response();
|
|
}
|
|
|
|
exports.validateSignature = function (uri, nonce, signature, auth_token) {
|
|
return validateSignature(uri, nonce, signature, auth_token);
|
|
}
|
|
|
|
/**
|
|
* Plivo API client which can be used to access the Plivo APIs.
|
|
* To set a proxy or timeout, pass in options.proxy (url) or options.timeout (number in ms)
|
|
* You can also pass in additional parameters accepted by the node requests module.
|
|
*/
|
|
export class Client {
|
|
constructor(authId, authToken, options) {
|
|
if (!(this instanceof Client)) {
|
|
return new Client(authId, authToken, options);
|
|
}
|
|
authId = authId || process.env.PLIVO_AUTH_ID;
|
|
authToken = authToken || process.env.PLIVO_AUTH_TOKEN;
|
|
|
|
if (authId == null) {
|
|
throw (new Error('Please provide authId'));
|
|
}
|
|
if (authToken == null) {
|
|
throw (new Error('Please provide authToken'));
|
|
}
|
|
|
|
options = Object.assign({}, {
|
|
authId: authId,
|
|
authToken: authToken,
|
|
version: 'v1',
|
|
url: 'https://api.plivo.com/v1/Account/' + authId,
|
|
userAgent: `${'plivo-node'}/${version || 'Unknown Version'} (Node: ${process.version})`,
|
|
}, options);
|
|
|
|
let client = camelCaseRequestWrapper(Request(options));
|
|
|
|
this.calls = new CallInterface(client);
|
|
this.accounts = new AccountInterface(client);
|
|
this.subaccounts = this.subAccounts = new SubaccountInterface(client);
|
|
this.applications = new ApplicationInterface(client);
|
|
this.conferences = new ConferenceInterface(client);
|
|
this.endpoints = new EndpointInterface(client);
|
|
this.messages = new MessageInterface(client);
|
|
this.numbers = new NumberInterface(client);
|
|
this.pricings = new PricingInterface(client);
|
|
this.recordings = new RecordingInterface(client);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Plivo API client which can be used to access the Plivo APIs.
|
|
* To set a proxy or timeout, pass in options.proxy (url) or options.timeout (number in ms)
|
|
* You can also pass in additional parameters accepted by the node requests module.
|
|
*/
|
|
export class PhloClient {
|
|
constructor(authId, authToken, options) {
|
|
|
|
if (!(this instanceof PhloClient)) {
|
|
return new PhloClient(authId, authToken, options);
|
|
}
|
|
authId = authId || process.env.PLIVO_AUTH_ID;
|
|
authToken = authToken || process.env.PLIVO_AUTH_TOKEN;
|
|
|
|
if (authId == null) {
|
|
throw (new Error('Please provide authId'));
|
|
}
|
|
if (authToken == null) {
|
|
throw (new Error('Please provide authToken'));
|
|
}
|
|
|
|
options = Object.assign({}, {
|
|
authId: authId,
|
|
authToken: authToken,
|
|
version: 'v1',
|
|
url: 'https://phlorunner.plivo.com/v1',
|
|
userAgent: `${'plivo-node'}/${version || 'Unknown Version'} (Node: ${process.version})`,
|
|
}, options);
|
|
|
|
let client = camelCaseRequestWrapper(Request(options));
|
|
|
|
|
|
this.phlo = function (phloId) {
|
|
let dd = new Phlo(client, { phloId: phloId, authId: authId });
|
|
return dd;
|
|
};
|
|
|
|
this.phlo.get = function (phloId) {
|
|
return new Promise((resolve, reject) => {
|
|
let dd = new PhloInterface(client);
|
|
dd.get(phloId).then(function (data) {
|
|
data.authId = authId;
|
|
resolve(data);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
|
|
}
|
|
} |