Skip to content

Commit

Permalink
Merge pull request #224 from plivo/10dlc-api
Browse files Browse the repository at this point in the history
10dlc api implementation
  • Loading branch information
huzaif-plivo authored Dec 2, 2021
2 parents 6ccd99f + 277917c commit 04de28a
Show file tree
Hide file tree
Showing 10 changed files with 530 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.25.0](https://github.com/plivo/plivo-node/tree/v4.25.0) (2021-12-02)
**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**
- The [Add Multiparty Call API](https://www.plivo.com/docs/voice/api/multiparty-call/participants#add-a-participant) allows for greater functionality by accepting options like `start recording audio`, `stop recording audio`, and their HTTP methods.
Expand Down
134 changes: 134 additions & 0 deletions lib/resources/brand.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

}
}
139 changes: 139 additions & 0 deletions lib/resources/campaign.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

}

}
8 changes: 8 additions & 0 deletions lib/rest/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions lib/rest/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 04de28a

Please sign in to comment.