Skip to content

Commit

Permalink
Merge pull request #244 from plivo/10dlc-number-linking
Browse files Browse the repository at this point in the history
add methods for 10dlc number linking
  • Loading branch information
huzaif-plivo authored Apr 14, 2022
2 parents 5f86b4e + 8c5d6b4 commit d522f92
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion lib/resources/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,7 +99,6 @@ export class CampaignCreateResponse {
return super.customexecuteAction(action,'GET', params);
}


/**
* create Campaign
* @method
Expand Down Expand Up @@ -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);
});
});
}
}

0 comments on commit d522f92

Please sign in to comment.