Skip to content

Commit

Permalink
Merge pull request #243 from plivo/profile-api
Browse files Browse the repository at this point in the history
profile api change
  • Loading branch information
huzaif-plivo authored Apr 14, 2022
2 parents d522f92 + f03716e commit 8bd5d96
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [v4.30.0](https://github.com/plivo/plivo-node/tree/v4.30.0) (2022-04-14)
**Features - Profile Api**
- Profile api added for 10dlc support

## [v4.29.1](https://github.com/plivo/plivo-node/tree/v4.29.1) (2022-03-25)
**Bug Fix - DialElement**
- `confirmTimeout` parameter added to [The Dial element](https://www.plivo.com/docs/voice/xml/dial/)
Expand Down
161 changes: 161 additions & 0 deletions lib/resources/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import * as _ from "lodash";

import {
PlivoResource,
PlivoResourceInterface
} from '../base';
import {
extend,
validate
} from '../utils/common.js';

const action = 'Profile/';
const idField = 'profileUUID';
let actionKey = Symbol('api action');
let klassKey = Symbol('constructor');
let idKey = Symbol('id filed');
let clientKey = Symbol('make api call');



/**
* Represents a Profile
* @constructor
* @param {function} client - make api call
* @param {object} [data] - data of call
*/
export class Profile extends PlivoResource {
constructor(client, data = {}) {
super(action, Profile, idField, client);
this[actionKey] = action;
this[clientKey] = client;
if (idField in data) {
this.id = data[idField];
};

extend(this, data);
}
}

export class ProfileResponse {
constructor(params) {
params = params || {};
this.apiId = params.apiId;
this.profileUuid = params.profileUuid;
this.message = params.message;
}
}

/**
* Represents a Profile Interface
* @constructor
* @param {function} client - make api call
* @param {object} [data] - data of call
*/
export class ProfileInterface extends PlivoResource {
constructor(client, data = {}) {
super(action, Profile, idField, client);
extend(this, data);
this[clientKey] = client;
this[actionKey] = action;
this[klassKey] = Profile;
this[idKey] = idField;
}

/**
* get Profile by given profileuuid
* @method
* @param {string} profileUUID - id of profileUUID
* @promise {object} return {@link profile} object
* @fail {Error} return Error
*/
get(profileUUID) {
let params = {};
return super.customexecuteAction(action+profileUUID+'/', 'GET', params);
}

/**
* Get All Profile Detail
* @method
* @param {object} params - params limit and offset
* @promise {object[]} returns list of profile Object
* @fail {Error} returns Error
*/
list(params) {
return super.customexecuteAction(action,'GET', params);
}

/**
* delete Profile by given profileuuid
* @method
* @param {string} profileUUID - id of profileUUID
* @fail {Error} return Error
*/
delete(profileUUID) {
let params = {};
return super.customexecuteAction(action+profileUUID+'/', 'DELETE', params);
}

/**
* Create a new Profile
*
* @param {string} profile_alias
* @param {string} plivo_subaccount
* @param {string} customer_type
* @param {string} entity_type
* @param {string} company_name
* @param {string} ein
* @param {string} vertical
* @param {string} ein_issuing_country
* @param {string} stock_symbol
* @param {string} stock_exchange
* @param {string} alt_business_id_type
* @param {string} website
* @param {object} address
* @param {object} authorized_contact
* @return profileResponse response output
*/
create(profile_alias,plivo_subaccount,customer_type,entity_type, company_name,ein,vertical,ein_issuing_country,stock_symbol,stock_exchange, alt_business_id_type, website, address, authorized_contact){
let params = {}
params.profile_alias=profile_alias;
params.plivo_subaccount=plivo_subaccount;
params.customer_type=customer_type;
params.entity_type=entity_type;
params.company_name=company_name;
params.ein=ein;
params.vertical=vertical;
params.ein_issuing_country=ein_issuing_country;
params.stock_symbol=stock_symbol;
params.stock_exchange=stock_exchange;
params.alt_business_id_type=alt_business_id_type;
params.website=website;
params.address=address;
params.authorized_contact=authorized_contact;
let client = this[clientKey];
return new Promise((resolve, reject) => {
client('POST', action, params)
.then(response => {
resolve(new ProfileResponse(response.body, idField));
})
.catch(error => {
reject(error);
});
});

}
/**
* update a new Profile
*
* @param {string} profile_uuid
* @param {object } address
* @param {object } authorized_contact
* @param {string} entity_type
* @param {string} vertical
* @param {string} company_name
* @param {string} website
* @return profileResponse response output
*/
update(profile_uuid, params){
return super.customexecuteAction(action+profile_uuid+'/', 'POST', params);
}
}
4 changes: 4 additions & 0 deletions lib/rest/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import {
import{
CampaignInterface
} from '../resources/campaign.js';
import{
ProfileInterface
}from '../resources/profile.js';
import {
NumberInterface
} from '../resources/numbers.js';
Expand Down Expand Up @@ -101,6 +104,7 @@ export class Client {
this.messages = new MessageInterface(client);
this.brand = new BrandInterface(client);
this.campaign = new CampaignInterface(client);
this.profile = new ProfileInterface(client);
this.lookup = new LookupInterface(client);
this.powerpacks = new PowerpackInterface(client);
this.numbers = new NumberInterface(client);
Expand Down
2 changes: 2 additions & 0 deletions lib/rest/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { LookupInterface } from "../resources/lookup";
import { PowerpackInterface } from "../resources/powerpacks";
import { BrandInterface } from "../resources/brand.js";
import { CampaignInterface } from "../resources/campaign.js";
import { ProfileInterface } from "../resources/profile.js";
import { NumberInterface } from "../resources/numbers";
import { PricingInterface } from "../resources/pricings";
import { RecordingInterface } from "../resources/recordings";
Expand Down Expand Up @@ -94,6 +95,7 @@ export class Client {
this.powerpacks = new PowerpackInterface(client);
this.brand = new BrandInterface(client);
this.campaign = new CampaignInterface(client);
this.profile = new ProfileInterface(client);
this.numbers = new NumberInterface(client);
this.pricings = new PricingInterface(client);
this.recordings = new RecordingInterface(client);
Expand Down
119 changes: 119 additions & 0 deletions lib/rest/request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,125 @@ export function Request(config) {
}
});
}
else if(action == 'Profile/' && method == 'GET'){
resolve({
response: {},
body: {
api_id: "97a1c5ee-b019-11ec-88b1-0242ac110002",
count: 10,
limit: 2,
offset: 0,
profiles: [
{
alt_business_id_type: "NONE",
authorized_contact: {
email: "johndoe.com",
name: "John Doe",
seniority: "admin",
title: "Doe"
},
company_name: "ABC Inc.",
customer_type: "RESELLER",
ein_issuing_country: "US",
entity_type: "PUBLIC_PROFIT",
profile_alias: "vishnu1",
profile_type: "SECONDARY",
profile_uuid: "1c41faed-a38e-42a3-a966-fe7df34b51b9",
stock_symbol: "ABC",
vertical: "ENERGY"
},
{
alt_business_id_type: "NONE",
authorized_contact: {
email: "johndoe.com",
name: "John Doe",
seniority: "admin",
title: "Doe"
},
company_name: "ABC Inc.",
customer_type: "RESELLER",
ein_issuing_country: "US",
entity_type: "SOLE_PROPRIETOR",
profile_alias: "vishnu1",
profile_type: "SECONDARY",
profile_uuid: "1d77a5fe-bca4-4a6d-a7c4-58b70e8cd7a2",
stock_symbol: "ABC",
vertical: "ENERGY"
}
]
}
});
}
else if(action == 'Profile/06ecae31-4bf8-40b9-ac62-e902418e9935/' && method == 'GET'){
resolve({
response: {},
body: {
api_id: "63287a98-b018-11ec-bc21-0242ac110002",
profile: {
alt_business_id_type: "NONE",
authorized_contact: {
name: " "
},
company_name: "ABC Inc.",
customer_type: "RESELLER",
ein: "111111111",
ein_issuing_country: "US",
entity_type: "PUBLIC_PROFIT",
profile_alias: "vishnu1",
profile_type: "SECONDARY",
profile_uuid: "06ecae31-4bf8-40b9-ac62-e902418e9935",
stock_symbol: "ABC",
vertical: "ENERGY"
}
}
});
}
else if(action == 'Profile/06ecae31-4bf8-40b9-ac62-e902418e9935/' && method == 'DELETE'){
resolve({
response: {},
body: {
api_id: "eb1e71ae-b01e-11ec-88b1-0242ac110002"
}
});
}
else if(action == 'Profile/06ecae31-4bf8-40b9-ac62-e902418e9935/' && method == 'POST'){
resolve({
response: {},
body: {
api_id: "15783daa-b01e-11ec-88b1-0242ac110002",
profile: {
address: "123 New York NY 10001 IN",
alt_business_id_type: "NONE",
authorized_contact: {
email: "Doe",
name: "Joh11n Doe",
seniority: "admin",
title: "Doe"
},
company_name: "ABC Inc.",
customer_type: "RESELLER",
ein_issuing_country: "US",
entity_type: "PRIVATE_PROFIT",
primary_profile: "303edff6-8525-43e5-87e6-48c571ddca25",
profile_alias: "vishnu1",
profile_type: "SECONDARY",
profile_uuid: "1c41faed-a38e-42a3-a966-fe7df34b51b9",
stock_symbol: "ABC",
vertical: "PROFESSIONAL",
website: "google.com"
}
}
});
}
else if(action == 'Profile/' && method == 'POST'){
resolve({
response: {},
body: {
api_id: "99ab47ae-b01c-11ec-bc21-0242ac110002",
profile_uuid: "43d0616e-d50a-445a-a84e-310a089f0618"
}
});
}
else if (action == '10dlc/Campaign/CMPT4EP/' && method == 'GET'){
resolve({
response: {},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plivo",
"version": "4.29.1",
"version": "4.30.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": [
Expand Down
42 changes: 42 additions & 0 deletions test/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Client
} from '../lib/rest/client-test';
import {
PlivoGenericResponse
} from '../lib/base.js';
import assert from 'assert';
import sinon from 'sinon';

let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');

describe('profile', function () {
it('should get profile', function () {
return client.profile.get("06ecae31-4bf8-40b9-ac62-e902418e9935")
.then(function (response) {
assert.equal(response.profile.profileUuid, "06ecae31-4bf8-40b9-ac62-e902418e9935")
})
});

it('list profile', function () {
return client.profile.list({})
.then(function (response) {
assert.equal(response.profiles.length, 2)
})
});

it('delete profile', function () {
return client.profile.delete("06ecae31-4bf8-40b9-ac62-e902418e9935")
.then(function (response) {
assert.equal(response.apiId, "eb1e71ae-b01e-11ec-88b1-0242ac110002")
})
});

it('create profile', function () {
var authorized_contact = {"first_name":"Hello", "last_name":"Test", "email":"[email protected]", "title":"bro", "seniority":"admin"}
var address = {"street":"123", "city":"Band", "state":"NY", "postal_code":"10001", "country":"US"}
return client.profile.create("vishnu104", "SECONDARY", "RESELLER","PRIVATE_PROFIT","ABC Inc", "111111111", "PROFESSIONAL", "US", "ABC","NASDAQ","NONE", "google.com", address,authorized_contact)
.then(function (profile) {
assert.equal(profile.profileUuid, '43d0616e-d50a-445a-a84e-310a089f0618')
})
});
});

0 comments on commit 8bd5d96

Please sign in to comment.