diff --git a/lib/resources/campaign.js b/lib/resources/campaign.js index 514c160f..675325d1 100644 --- a/lib/resources/campaign.js +++ b/lib/resources/campaign.js @@ -47,6 +47,19 @@ export class CampaignCreateResponse { } } +export class LinkUnlinkNumberResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + if (params.message) + this.message = params.message; + if (params.error) + this.error = params.error; + if (params.remark) + this.remark = params.remark; + } +} + /** * Represents a Campaign Interface * @constructor @@ -86,7 +99,6 @@ export class CampaignCreateResponse { return super.customexecuteAction(action,'GET', params); } - /** * create Campaign * @method @@ -135,7 +147,75 @@ export class CampaignCreateResponse { reject(error); }); }); + } + + /** + * getNumber CampaignNumbers by given campaignId, number + * @method + * @param {string} campaignID - id of Campaign + * @param {string} number - number + * @promise {object} return {@link Campaign} object + * @fail {Error} return Error + */ + getNumber(campaignID, number) { + return super.customexecuteAction(action+campaignID+'/Number/'+number+'/', 'GET'); + } + /** + * listNumber CampaignNumbers by given campaignId + * @method + * @param {string} campaignID - id of Campaign + * @param {number} limit + * @param {number} offset + * @promise {object} returns {@link Campaign} object + * @fail {Error} return Error + */ + listNumber(campaignID, params) { + return super.customexecuteAction(action+campaignID+'/Number/', 'GET', params); + } + + /** + * linkNumber link number to Campaign + * @method + * @param {string} campaignID + * @param {list} numbers + * @promise {object} return {@link Campaign} object + * @fail {Error} return Error + */ + linkNumber(campaignID, numbers) { + let params = {} + params.numbers=numbers; + let client = this[clientKey]; + return new Promise((resolve, reject) => { + client('POST', action+campaignID+'/Number/', params) + .then(response => { + resolve(new LinkUnlinkNumberResponse(response.body)); + }) + .catch(error => { + reject(error); + }); + }); } + /** + * unlinkNumber unlink number from Campaign + * @method + * @param {string} campaignID + * @param {string} number + * @promise {object} return {@link Campaign} object + * @fail {Error} return Error + */ + unlinkNumber(campaignID, number) { + let params = {} + let client = this[clientKey]; + return new Promise((resolve, reject) => { + client('DELETE', action+campaignID+'/Number/'+number+'/', params) + .then(response => { + resolve(new LinkUnlinkNumberResponse(response.body)); + }) + .catch(error => { + reject(error); + }); + }); + } } \ No newline at end of file