From 23fbb1fe423a8b9e564d50bce66ea6ccf11b1262 Mon Sep 17 00:00:00 2001 From: Dhruv Chauhan Date: Fri, 1 Apr 2022 16:29:19 +0530 Subject: [PATCH] add methods for 10dlc number linking --- lib/resources/campaign.js | 82 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/lib/resources/campaign.js b/lib/resources/campaign.js index 6e240b6a..5879e85a 100644 --- a/lib/resources/campaign.js +++ b/lib/resources/campaign.js @@ -45,6 +45,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 @@ -84,7 +97,6 @@ export class CampaignCreateResponse { return super.customexecuteAction(action,'GET', params); } - /** * create Campaign * @method @@ -133,7 +145,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, limit=10, offset=0) { + return super.customexecuteAction(action+campaignID+'/Number/?limit='+limit+'&offset='+offset, 'GET'); + } + + /** + * linkNumber link number to Campaign + * @method + * @param {string} campaignID + * @param {string} number + * @promise {object} return {@link Campaign} object + * @fail {Error} return Error + */ + linkNumber(campaignID, number) { + let params = {} + params.number=number; + 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