Skip to content

Commit 76350b8

Browse files
committed
resolve merge conflicts
2 parents e0e74a4 + 9053839 commit 76350b8

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,22 @@ numbers.SipPeer.get(function(err,sipPeer){
704704
});
705705
```
706706

707+
### SipPeer link Application Methods
708+
709+
```Javascript
710+
numbers.SipPeer.get(function(err,sipPeer){
711+
// List application associated with this peer
712+
sipPeer.listApplication(callback);
713+
714+
// Associate an application with this peer
715+
var appId = "my-application-id";
716+
sipPeer.editApplication({httpMessagingV2AppId: appId}, callback);
717+
718+
// Dissociate all applications with this peer
719+
sipPeer.removeApplication(callback);
720+
```
721+
722+
707723
## Sites
708724
709725
### Create A Site

lib/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Application.prototype.getSipPeers = function(query, callback){
105105
return callback(err);
106106
}
107107
let sipPeers = res.associatedSipPeers.associatedSipPeer;
108-
if(!Array.isArray(sipPeers)){
108+
if(!Array.isArray(sipPeers) && sipPeers){
109109
sipPeers = [sipPeers];
110110
}
111111
callback(null,sipPeers);

lib/sipPeer.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,38 @@ SipPeer.prototype.moveTns = function(numbers, callback){
7878
this.client.makeRequest("post", url, {sipPeerTelephoneNumbers: {fullNumber: numbers}}, callback);
7979
};
8080

81+
SipPeer.prototype.listApplication = function(callback) {
82+
var url = this.client.concatAccountPath(SITE_PATH + "/" + this.siteId + "/" + SIP_PEER_PATH + "/" + this.id + "/" + "products" + "/" + "messaging" + "/" + "applicationSettings");
83+
this.client.makeRequest("get", url, function (err, results) {
84+
if (err) {
85+
callback(error);
86+
}
87+
else {
88+
var apps = results.applicationSettings;
89+
if (!Array.isArray(apps.httpMessagingV2AppId) && apps.httpMessagingV2AppId) {
90+
apps.httpMessagingV2AppId = [apps.httpMessagingV2AppId]
91+
}
92+
callback(null, apps)
93+
}
94+
})
95+
}
96+
97+
SipPeer.prototype.editApplication = function(appData, callback) {
98+
var url = this.client.concatAccountPath(SITE_PATH + "/" + this.siteId + "/" + SIP_PEER_PATH + "/" + this.id + "/" + "products" + "/" + "messaging" + "/" + "applicationSettings");
99+
const data = {applicationsSettings: appData}
100+
this.client.makeRequest("put", url, data, function (err, results) {
101+
if (err) {callback(error);}
102+
else {
103+
var apps = results.applicationSettings;
104+
callback(null, apps)
105+
}
106+
});
107+
}
108+
109+
SipPeer.prototype.removeApplication = function(callback) {
110+
var url = this.client.concatAccountPath(SITE_PATH + "/" + this.siteId + "/" + SIP_PEER_PATH + "/" + this.id + "/" + "products" + "/" + "messaging" + "/" + "applicationSettings");
111+
const data = {applicationsSettings: 'REMOVE'}
112+
this.client.makeRequest("put", url, data, callback);
113+
}
81114

82115
module.exports = SipPeer;

test/sipPeer.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,52 @@ describe("SipPeer", function(){
193193
peer.moveTns(data, done);
194194
});
195195
});
196+
describe("#listApplication", function() {
197+
it("should list application", function(done) {
198+
var span = helper.nock().get("/accounts/FakeAccountId/sites/1/sippeers/10/products/messaging/applicationSettings").reply(200, helper.xml.peerApplications, {"Content-Type": "application/xml"});
199+
var peer = new SipPeer();
200+
peer.id = 10;
201+
peer.siteId = 1;
202+
peer.client = helper.createClient();
203+
peer.listApplication(function(err, results) {
204+
if (err) {
205+
done(err);
206+
} else {
207+
results.httpMessagingV2AppId[0].should.equal(100)
208+
done();
209+
}
210+
});
211+
});
212+
});
213+
describe("#editApplication", function() {
214+
it("should edit the application", function(done) {
215+
var appData = {httpMessagingV2AppId: 100}
216+
var span = helper.nock().put("/accounts/FakeAccountId/sites/1/sippeers/10/products/messaging/applicationSettings", helper.buildXml({applicationsSettings: appData})).reply(200, helper.xml.peerApplications, {"Content-Type": "application/xml"});
217+
var peer = new SipPeer();
218+
peer.id = 10;
219+
peer.siteId = 1;
220+
peer.client = helper.createClient();
221+
var appData = {httpMessagingV2AppId: 100}
222+
peer.editApplication(appData, function(err, results) {
223+
if (err) {
224+
done(err);
225+
} else {
226+
results.httpMessagingV2AppId.should.equal(100)
227+
done();
228+
}
229+
});
230+
});
231+
});
232+
describe("#removeApplication", function() {
233+
it("should remove application", function(done) {
234+
var appData = 'REMOVE';
235+
var span = helper.nock().put("/accounts/FakeAccountId/sites/1/sippeers/10/products/messaging/applicationSettings", helper.buildXml({applicationsSettings: appData})).reply(200, helper.xml.peerApplications, {"Content-Type": "application/xml"});
236+
var peer = new SipPeer();
237+
peer.id = 10;
238+
peer.siteId = 1;
239+
peer.client = helper.createClient();
240+
peer.removeApplication(done);
241+
});
242+
});
243+
196244
});

test/xml.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"geocode": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><GeocodeRequestResponse><GeocodedAddress><AddressLine1>1 Street Name</AddressLine1><HouseNumber>1</HouseNumber><StreetName>Street</StreetName><StreetSuffix>Name</StreetSuffix><City>City</City><StateCode>State</StateCode><Zip>ZipCode</Zip><PlusFour>1234</PlusFour><Country>US</Country></GeocodedAddress></GeocodeRequestResponse>",
3+
"peerApplications": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationSettingsResponse><ApplicationSettings><HttpMessagingV2AppId>100</HttpMessagingV2AppId></ApplicationSettings></ApplicationSettingsResponse>",
34
"application": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse><Application><ApplicationId>1</ApplicationId><ServiceType>Messaging-V2</ServiceType><AppName>Test Application</AppName><MsgCallbackUrl>http://a.com</MsgCallbackUrl></Application></ApplicationProvisioningResponse>",
45
"voiceApplication": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse><Application><ApplicationId>2</ApplicationId><AppName>Test Application 2</AppName><ServiceType>Voice-V2</ServiceType><CallInitiatedCallbackUrl>http://b.com</CallInitiatedCallbackUrl></Application></ApplicationProvisioningResponse>",
56
"applications": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse><ApplicationList><Application><ApplicationId>1</ApplicationId><ServiceType>Messaging-V2</ServiceType><AppName>Test Application</AppName><MsgCallbackUrl>http://a.com</MsgCallbackUrl></Application><Application><ApplicationId>2</ApplicationId><AppName>Test Application 2</AppName><ServiceType>Voice-V2</ServiceType><CallInitiatedCallbackUrl>http://b.com</CallInitiatedCallbackUrl></Application></ApplicationList></ApplicationProvisioningResponse>",

0 commit comments

Comments
 (0)