-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from plivo/10dlc-api
10dlc api implementation
- Loading branch information
Showing
10 changed files
with
530 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.