From cba8ea4298b3bbf9b0a5e9e07f5e95da1f90d14d Mon Sep 17 00:00:00 2001 From: narayana Date: Sun, 31 Oct 2021 10:51:18 +0530 Subject: [PATCH 1/3] version bump --- CHANGELOG.md | 3 + lib/resources/brand.js | 134 ++++++++++++++++++++++++++++++ lib/resources/campaign.js | 139 +++++++++++++++++++++++++++++++ lib/rest/client-test.js | 8 ++ lib/rest/client.js | 4 + lib/rest/request-test.js | 166 ++++++++++++++++++++++++++++++++++++++ lib/rest/utils.js | 2 + package.json | 2 +- test/brand.js | 36 +++++++++ test/campaign.js | 36 +++++++++ 10 files changed, 529 insertions(+), 1 deletion(-) create mode 100644 lib/resources/brand.js create mode 100644 lib/resources/campaign.js create mode 100644 test/brand.js create mode 100644 test/campaign.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 927f26a8..4571af63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## [v4.24.0](https://github.com/plivo/plivo-node/tree/v4.24.0) (2021-12-02) +-- 10dlc Api support. + ## [v4.23.1](https://github.com/plivo/plivo-node/tree/v4.23.1) (2021-10-13) **Bug Fix** - LiveCallInterface. diff --git a/lib/resources/brand.js b/lib/resources/brand.js new file mode 100644 index 00000000..15ab9dbc --- /dev/null +++ b/lib/resources/brand.js @@ -0,0 +1,134 @@ +import * as _ from "lodash"; + +import { + PlivoResource, + PlivoResourceInterface +} from '../base'; +import { + extend, + validate +} from '../utils/common.js'; + +const action = '10dlc/Brand/'; +const idField = 'brand_id'; +let clientKey = Symbol(); +let idKey = Symbol('id filed'); + + +/** + * Represents a Brand + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ + export class Brand extends PlivoResource { + constructor(client, data = {}) { + super(action, Brand, idField, client); + this[actionKey] = action; + this[clientKey] = client; + + extend(this, data); + } +} + + +export class BrandCreationResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.brand = params.brand; + } +} + +/** + * Represents a Brand Interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ + export class BrandInterface extends PlivoResource { + constructor(client, data = {}) { + super(action, Brand, idField, client); + extend(this, data); + this[clientKey] = client; + } + + /** + * get Brand by given id + * @method + * @param {string} brandID - id of brand + * @promise {object} return {@link Brand} object + * @fail {Error} return Error + */ + get(brandId) { + let params = {} + return super.customexecuteAction(action+brandId+'/', 'GET', params); + } + /** + * Get All Brand Detail + * @method + * @param {object} params - params type and status to get all brand details. + * @promise {object[]} returns list of Brand Object + * @fail {Error} returns Error + */ + list(params) { + return super.customexecuteAction(action, 'GET', params); + } + + /** + * Brand Registration + * @method + * @param {object} params + * @param {string} city + * @param {string} company_name + * @param {string} country + * @param {string} ein + * @param {string} ein_issuing_country + * @param {string} email + * @param {string} entity_type + * @param {string} postal_code + * @param {string} registration_status + * @param {string} state + * @param {string} stock_exchange + * @param {string} stock_symbol + * @param {string} street + * @param {string} vertical + * @param {string} [params.website] - + * @param {string} [params.secondary_vetting] + * @param {string} [params.first_name] + * @param {string} [params.last_name] + * @param {string} [params.alt_business_id_type] + * @param {string} [params.alt_business_id] + * @promise {object} return {@link PlivoGenericResponse} object + * @fail {Error} return Error + */ + create(city,company_name,country,ein,ein_issuing_country,email,entity_type,phone,postal_code,registration_status,state,stock_exchange,stock_symbol,street,vertical, params = {}) { + params.city=city; + params.company_name=company_name; + params.country=country; + params.ein=ein; + params.ein_issuing_country=ein_issuing_country; + params.email=email; + params.entity_type=entity_type; + params.phone=phone; + params.postal_code=postal_code; + params.registration_status=registration_status; + params.state=state; + params.stock_exchange=stock_exchange; + params.stock_symbol=stock_symbol; + params.street=street; + params.vertical=vertical; + let client = this[clientKey]; + let idField = this[idKey]; + return new Promise((resolve, reject) => { + client('POST', action, params) + .then(response => { + resolve(new BrandCreationResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }); + + } +} \ No newline at end of file diff --git a/lib/resources/campaign.js b/lib/resources/campaign.js new file mode 100644 index 00000000..6e240b6a --- /dev/null +++ b/lib/resources/campaign.js @@ -0,0 +1,139 @@ +import * as _ from "lodash"; + +import { + PlivoResource, + PlivoResourceInterface +} from '../base'; +import { + extend, + validate +} from '../utils/common.js'; + +const action = '10dlc/Campaign/'; +const idField = 'brandID'; +let actionKey = Symbol('api action'); +let klassKey = Symbol('constructor'); +let idKey = Symbol('id filed'); +let clientKey = Symbol('make api call'); + + + +/** + * Represents a Campaign + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ + export class Campaign extends PlivoResource { + constructor(client, data = {}) { + super(action, Campaign, idField, client); + this[actionKey] = action; + this[clientKey] = client; + if (idField in data) { + this.id = data[idField]; + }; + + extend(this, data); + } +} + +export class CampaignCreateResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.campaign = params.campaign; + } +} + +/** + * Represents a Campaign Interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ + export class CampaignInterface extends PlivoResource { + constructor(client, data = {}) { + super(action, Campaign, idField, client); + extend(this, data); + this[clientKey] = client; + this[actionKey] = action; + this[klassKey] = Campaign; + this[idKey] = idField; + } + + /** + * get Campaign by given id + * @method + * @param {string} campaignID - id of Campaign + * @promise {object} return {@link Campaign} object + * @fail {Error} return Error + */ + get(campaignID) { + let params = {}; + return super.customexecuteAction(action+campaignID+'/', 'GET', params); + } + + /** + * Get All Campaign Detail + * @method + * @param {object} params - params brand and usecase to get all campaign details. + * @promise {object[]} returns list of campaign Object + * @fail {Error} returns Error + */ + list(params) { + return super.customexecuteAction(action,'GET', params); + } + + + /** + * create Campaign + * @method + * @param {string} brand_id + * @param {string} campaign_alias + * @param {string} vertical + * @param {string} usecase + * @param {list} sub_usecases + * @param {string} description + * @param {boolean} embedded_link + * @param {boolean} embedded_phone + * @param {boolean} age_gated + * @param {boolean} direct_lending + * @param {boolean} subscriber_optin + * @param {boolean} subscriber_optout + * @param {boolean} subscriber_help + * @param {string} sample1 + * @param {string} sample2 + * @promise {object} return {@link PlivoGenericResponse} object + * @fail {Error} return Error + */ + create(brand_id,campaign_alias,vertical,usecase,sub_usecases,description,embedded_link,embedded_phone,age_gated,direct_lending,subscriber_optin,subscriber_optout,subscriber_help,sample1,sample2) { + let params = {} + params.brand_id=brand_id; + params.campaign_alias=campaign_alias; + params.vertical=vertical; + params.usecase=usecase; + params.sub_usecases=sub_usecases; + params.description=description; + params.embedded_link=embedded_link; + params.embedded_phone=embedded_phone; + params.age_gated=age_gated; + params.direct_lending=direct_lending; + params.subscriber_optin=subscriber_optin; + params.subscriber_optout=subscriber_optout; + params.subscriber_help=subscriber_help; + params.sample1=sample1; + params.sample2=sample2; + let client = this[clientKey]; + return new Promise((resolve, reject) => { + client('POST', action, params) + .then(response => { + resolve(new CampaignCreateResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }); + + } + +} \ No newline at end of file diff --git a/lib/rest/client-test.js b/lib/rest/client-test.js index eb77ed76..0a88610c 100644 --- a/lib/rest/client-test.js +++ b/lib/rest/client-test.js @@ -33,6 +33,12 @@ import { import { PowerpackInterface } from '../resources/powerpacks.js'; +import { + BrandInterface +} from '../resources/brand.js'; +import{ + CampaignInterface +} from '../resources/campaign.js'; import { NumberInterface } from '../resources/numbers.js'; @@ -91,6 +97,8 @@ export class Client { this.conferences = new ConferenceInterface(client); this.endpoints = new EndpointInterface(client); this.messages = new MessageInterface(client); + this.brand = new BrandInterface(client); + this.campaign = new CampaignInterface(client); this.lookup = new LookupInterface(client); this.powerpacks = new PowerpackInterface(client); this.numbers = new NumberInterface(client); diff --git a/lib/rest/client.js b/lib/rest/client.js index fdc3cbe4..3c797679 100644 --- a/lib/rest/client.js +++ b/lib/rest/client.js @@ -10,6 +10,8 @@ import { EndpointInterface } from "../resources/endpoints"; import { MessageInterface } from "../resources/messages"; import { LookupInterface } from "../resources/lookup"; import { PowerpackInterface } from "../resources/powerpacks"; +import { BrandInterface } from "../resources/brand.js"; +import { CampaignInterface } from "../resources/campaign.js"; import { NumberInterface } from "../resources/numbers"; import { PricingInterface } from "../resources/pricings"; import { RecordingInterface } from "../resources/recordings"; @@ -87,6 +89,8 @@ export class Client { this.messages = new MessageInterface(client); this.lookup = new LookupInterface(client); this.powerpacks = new PowerpackInterface(client); + this.brand = new BrandInterface(client); + this.campaign = new CampaignInterface(client); this.numbers = new NumberInterface(client); this.pricings = new PricingInterface(client); this.recordings = new RecordingInterface(client); diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index 3f0abe0a..f7fceb20 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -1158,6 +1158,172 @@ export function Request(config) { } }); } + else if (action == '10dlc/Brand/BRPXS6E/' && method == 'GET'){ + resolve({ + response: {}, + body: { + api_id: "71aa47e0-3750-11ec-8e4c-0242ac110002", + brand: { + brand_id: "BRPXS6E", + company_name: "ABC Inc.", + ein: "111111111", + ein_issuing_country: "US", + email: "johndoe@abc.com", + entity_type: "PRIVATE_PROFIT", + registration_status: "COMPLETED", + vertical: "RETAIL", + website: "http://www.abcmobile.com" + } + } + }); + } + else if (action == '10dlc/Campaign/CMPT4EP/' && method == 'GET'){ + resolve({ + response: {}, + body: { + api_id: "12ae5a32-3751-11ec-8e4c-0242ac110002", + campaign: { + brand_id: "BHYYNCK", + campaign_id: "CMPT4EP", + mno_metadata: { + AT_T: { + tpm: 4500 + }, + T_Mobile: { + brand_tier: "TOP" + }, + Verizon_Wireless: {} + }, + reseller_id: "RPDPPUM", + usecase: "ACCOUNT_NOTIFICATION" + } + } + }); + } + else if (action == '10dlc/Brand/' && method == 'GET'){ + resolve({ + response: {}, + body: { + api_id: "b9df43c0-374c-11ec-97b3-0242ac110002", + brands: [ + { + brand_id: "ABCDEFG", + company_name: "ABC Inc.", + ein: "111111111", + ein_issuing_country: "US", + email: "johndoe@abc.com", + entity_type: "PRIVATE_PROFIT", + registration_status: "COMPLETED", + vertical: "RETAIL", + website: "http://www.abcmobile.com" + }, + { + brand_id: "QWERTYU", + company_name: "ABC Inc.", + ein: "111111111", + ein_issuing_country: "US", + email: "johndoe@abc.com", + entity_type: "PRIVATE_PROFIT", + registration_status: "COMPLETED", + vertical: "RETAIL", + website: "http://www.abcmobile.com" + } + ] + } + }); + } + else if (action == '10dlc/Campaign/' && method == 'GET'){ + resolve({ + response: {}, + body: { + api_id: "5e639fd0-374e-11ec-8e4c-0242ac110002", + campaigns: [ + { + brand_id: "BHYYNCK", + campaign_id: "CMPT4EP", + mno_metadata: { + AT_T: { + tpm: 4500 + }, + T_Mobile: { + brand_tier: "TOP" + }, + Verizon_Wireless: {} + }, + reseller_id: "RPDPPUM", + usecase: "ACCOUNT_NOTIFICATION" + }, + { + brand_id: "B8OD95Z", + campaign_id: "CAIKXXT", + mno_metadata: { + AT_T: { + tpm: 4500 + }, + T_Mobile: { + brand_tier: "TOP" + }, + US_Cellular: {}, + Verizon_Wireless: {} + }, + reseller_id: "", + usecase: "MIXED" + } + ] + } + }); + } + else if (action == '10dlc/Brand/' && method == 'POST'){ + resolve({ + response: {}, + body: { + api_id: "a52a5398-3751-11ec-8e4c-0242ac110002", + brand: { + alt_business_id_type: "GIIN", + brand_id: "BVI0UQA", + city: "New York", + country: "US", + ein_issuing_country: "US", + email: "johndoe@abc.com", + entity_type: "SOLE_PROPRIETOR", + first_name: "John", + last_name: "Doe", + phone: "+11234567890", + postal_code: "10001", + registration_status: "PENDING", + state: "NY", + stock_exchange: "NASDAQ", + stock_symbol: "ABC", + street: "123", + vertical: "RETAIL", + website: "http://www.abcmobile.com" + } + } + }); + } + else if (action == '10dlc/Campaign/' && method == 'POST'){ + resolve({ + response: {}, + body: { + api_id: "12ae5a32-3751-11ec-8e4c-0242ac110002", + campaign: { + brand_id: "BHYYNCK", + campaign_id: "CMPT4EP", + mno_metadata: { + AT_T: { + tpm: 4500 + }, + T_Mobile: { + brand_tier: "TOP" + }, + Verizon_Wireless: {} + }, + reseller_id: "RPDPPUM", + usecase: "ACCOUNT_NOTIFICATION" + } + } + }); + } else if (action == 'Powerpack/5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46/' && method == 'GET'){ resolve({ response: {}, diff --git a/lib/rest/utils.js b/lib/rest/utils.js index 934836cf..389b651e 100644 --- a/lib/rest/utils.js +++ b/lib/rest/utils.js @@ -53,6 +53,8 @@ export function camelCaseRequestWrapper(requestFunc) { .replace('priority_1', 'priority1') .replace('priority_2', 'priority2') .replace('priority_3', 'priority3') + .replace('sample_1', 'sample1') + .replace('sample_2', 'sample2') .replace('country_iso_2', 'country_iso2'); }); diff --git a/package.json b/package.json index 38d9b64e..771a4e4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.23.1", + "version": "4.24.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": [ diff --git a/test/brand.js b/test/brand.js new file mode 100644 index 00000000..229124f0 --- /dev/null +++ b/test/brand.js @@ -0,0 +1,36 @@ +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('brand', function () { + it('should get brand', function () { + return client.brand.get('BRPXS6E') + .then(function (brand) { + assert.equal(brand.brand.brandId, 'BRPXS6E') + }) + }); + + it('list brand', function () { + return client.brand.list() + .then(function (brand) { + assert.equal(brand.brands.length, 2) + }) + }); + + it('create brand', function () { + return client.brand.create("New York","ABC Inc.", "US", "111111111","US","johndoe@abc.com","PRIVATE_PROFIT","+11234567890","10001","PENDING", + "NY", "NASDAQ","ABC","123", "RETAIL") + .then(function (brand) { + assert.equal(brand.brand.brandId, 'BVI0UQA') + }) + }); + + + }); \ No newline at end of file diff --git a/test/campaign.js b/test/campaign.js new file mode 100644 index 00000000..b442f26c --- /dev/null +++ b/test/campaign.js @@ -0,0 +1,36 @@ +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('campaign', function () { + it('should get campaign', function () { + return client.campaign.get("CMPT4EP") + .then(function (response) { + assert.equal(response.campaign.campaignId, "CMPT4EP") + }) + }); + + it('list campaign', function () { + return client.campaign.list() + .then(function (response) { + assert.equal(response.campaigns.length, 2) + }) + }); + + it('create campaign', function () { + return client.campaign.create("B8OD95Z","campaign name sssample","INSURANCE","MIXED",[ + "CUSTOMER_CARE", + "2FA" + ],"sample description text",false,false,false,false,true,true,true,"sample1","sample2") + .then(function (campaign) { + assert.equal(campaign.campaign.brandId, 'BHYYNCK') + }) + }); + }); \ No newline at end of file From fb0e6f2f5b27f9a2b4d76ac73de5e5d707ea6c96 Mon Sep 17 00:00:00 2001 From: Narayana Shanubhogh Date: Thu, 2 Dec 2021 11:30:27 +0530 Subject: [PATCH 2/3] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 771a4e4e..c15b9f56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.24.0", + "version": "4.25.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": [ From 277917c8841373d5f36c40f0c49f14825d657223 Mon Sep 17 00:00:00 2001 From: Mohammed Huzaif Date: Thu, 2 Dec 2021 14:43:23 +0530 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be55bec..e446d073 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Change Log ## [v4.25.0](https://github.com/plivo/plivo-node/tree/v4.25.0) (2021-12-02) -**Features - SMS: 10dlc Api support** -- Brand and Campaign API. +**Features - Messaging: 10DLC API** +- 10DLC API's for brand and campaign support ## [v4.24.0](https://github.com/plivo/plivo-node/tree/v4.24.0) (2021-11-30) **Features - Voice: Multiparty calls**