Skip to content

Commit

Permalink
Merge pull request #68 from Bandwidth/SWI-3816
Browse files Browse the repository at this point in the history
SWI-3816 Add SipPeer functionality
  • Loading branch information
ajrice6713 committed Oct 30, 2023
2 parents 4a6f532 + 8566865 commit d7e4624
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 3 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,28 @@ peer.getTn("number");
peer.moveTns(sipPeerTelephoneNumbers);
```

### Enable SMS Settings
```java
// Zone1 for US & Canada enabled by default
SipPeerSmsFeature settings = new SipPeerSmsFeature();
settings.setTollFree(true);
settings.setShortCode(true);
peer.enableSms(settings);
```

### Enable MMS
```java
peer.enableMms();
```

### Associate a SipPeer with a Messaging Application
```java
SipPeerMessagingApplicationsSettings settings = new SipPeerMessagingApplicationsSettings();
settings.setApplicationId("abcd-1234");

peer.updateMessagingApplicationSettings(settings);
```

## Sites

### Create A Site
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,20 @@ public List<SipPeerTelephoneNumber> getTns() throws Exception {
IrisPath.SIPPEERS_URI_PATH, peerId, "tns" }),
SipPeerTelephoneNumbersResponse.class).getSipPeerTelephoneNumbers();
}

public void enableSms(SipPeerSmsFeature smsSettings) throws Exception {
client.post(client.buildAccountModelUri(new String[] { IrisPath.SITES_URI_PATH, siteId,
IrisPath.SIPPEERS_URI_PATH, peerId, "products", "messaging", "features", "sms" }), smsSettings);
}

public void enableMms() throws Exception {
SipPeerMmsFeature mmsSettings = new SipPeerMmsFeature();
client.post(client.buildAccountModelUri(new String[] { IrisPath.SITES_URI_PATH, siteId,
IrisPath.SIPPEERS_URI_PATH, peerId, "products", "messaging", "features", "mms" }), mmsSettings);
}

public void updateMessagingApplicationSettings (SipPeerMessagingApplicationsSettings settings) throws Exception {
client.post(client.buildAccountModelUri(new String[] { IrisPath.SITES_URI_PATH, siteId,
IrisPath.SIPPEERS_URI_PATH, peerId, "products", "messaging","applicationSettings" }), settings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bandwidth.iris.sdk.model;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "ApplicationSettings")
public class SipPeerMessagingApplicationsSettings extends BaseModel {
@XmlElement(name = "HttpMessagingV2AppId")
String applicationId;

public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/bandwidth/iris/sdk/model/SipPeerMmsFeature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.bandwidth.iris.sdk.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "MmsFeature")
@XmlAccessorType(XmlAccessType.FIELD)
public class SipPeerMmsFeature extends BaseModel {
@XmlElement(name = "MmsSettings")
MmsSettings mmsSettings;
@XmlElement(name = "Protocols")
Protocols protocols;

public SipPeerMmsFeature()
{
this.mmsSettings = new MmsSettings();
this.protocols = new Protocols();
this.protocols.http = new Http();
this.protocols.http.httpSettings = new HttpSettings();
}

private static class MmsSettings extends BaseModel {
@XmlElement(name = "Protocol")
private final String protocol = "HTTP";
}

private static class Protocols extends BaseModel {
@XmlElement(name = "HTTP")
Http http;
}

private static class Http extends BaseModel {
@XmlElement(name = "HttpSettings")
HttpSettings httpSettings = new HttpSettings();
}

private static class HttpSettings extends BaseModel {
@XmlElement(name = "ProxyPeerId")
String proxyPeerId = "";
}
}
138 changes: 138 additions & 0 deletions src/main/java/com/bandwidth/iris/sdk/model/SipPeerSmsFeature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.bandwidth.iris.sdk.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "SipPeerSmsFeature")
@XmlAccessorType(XmlAccessType.FIELD)
public class SipPeerSmsFeature extends BaseModel {
@XmlElement(name = "HttpSettings")
HttpSettings httpSettings;
@XmlElement(name = "SipPeerSmsFeatureSettings")
SipPeerSmsFeatureSettings sipPeerSmsFeatureSettings;

public SipPeerSmsFeature() {
httpSettings = new HttpSettings();
sipPeerSmsFeatureSettings = new SipPeerSmsFeatureSettings();
}

private static class HttpSettings{
Integer proxyPeerId = null;
}

private static class SipPeerSmsFeatureSettings extends BaseModel {
@XmlElement(name = "A2pLongCode")
String a2pLongCode;
@XmlElement(name = "A2pMessageClass")
String a2pMessageClass;
@XmlElement(name = "A2pCampaignId")
String a2pCampaignId;
@XmlElement(name = "Protocol")
String protocol = "HTTP";
@XmlElement(name = "TollFree")
boolean tollFree = false;
@XmlElement(name = "ShortCode")
boolean shortCode = false;
@XmlElement(name = "Zone1")
boolean zone1 = true;
@XmlElement(name = "Zone2")
boolean zone2 = false;
@XmlElement(name = "Zone3")
boolean zone3 = false;
@XmlElement(name = "Zone4")
boolean zone4 = false;
@XmlElement(name = "Zone5")
boolean zone5 = false;

}
public String getA2pLongCode() {
return this.sipPeerSmsFeatureSettings.a2pLongCode;
}

public void setA2pLongCode(String a2pLongCode) {
this.sipPeerSmsFeatureSettings.a2pLongCode = a2pLongCode;
}

public String getA2pMessageClass() {
return this.sipPeerSmsFeatureSettings.a2pMessageClass;
}

public void setA2pMessageClass(String a2pMessageClass) {
this.sipPeerSmsFeatureSettings.a2pMessageClass = a2pMessageClass;
}

public String getA2pCampaignId() {
return this.sipPeerSmsFeatureSettings.a2pCampaignId;
}

public void setA2pCampaignId(String a2pCampaignId) {
this.sipPeerSmsFeatureSettings.a2pCampaignId = a2pCampaignId;
}

public String getProtocol() {
return this.sipPeerSmsFeatureSettings.protocol;
}

public void setProtocol(String protocol) {
this.sipPeerSmsFeatureSettings.protocol = protocol;
}

public boolean isTollFree() {
return this.sipPeerSmsFeatureSettings.tollFree;
}

public void setTollFree(boolean tollFree) {
this.sipPeerSmsFeatureSettings.tollFree = tollFree;
}

public boolean isShortCode() {
return this.sipPeerSmsFeatureSettings.shortCode;
}

public void setShortCode(boolean shortCode) {
this.sipPeerSmsFeatureSettings.shortCode = shortCode;
}

public boolean isZone1() {
return this.sipPeerSmsFeatureSettings.zone1;
}

public void setZone1(boolean zone1) {
this.sipPeerSmsFeatureSettings.zone1 = zone1;
}

public boolean isZone2() {
return this.sipPeerSmsFeatureSettings.zone2;
}

public void setZone2(boolean zone2) {
this.sipPeerSmsFeatureSettings.zone2 = zone2;
}

public boolean isZone3() {
return this.sipPeerSmsFeatureSettings.zone3;
}

public void setZone3(boolean zone3) {
this.sipPeerSmsFeatureSettings.zone3 = zone3;
}

public boolean isZone4() {
return this.sipPeerSmsFeatureSettings.zone4;
}

public void setZone4(boolean zone4) {
this.sipPeerSmsFeatureSettings.zone4 = zone4;
}

public boolean isZone5() {
return this.sipPeerSmsFeatureSettings.zone5;
}

public void setZone5(boolean zone5) {
this.sipPeerSmsFeatureSettings.zone5 = zone5;
}

}
20 changes: 20 additions & 0 deletions src/test/java/com/bandwidth/iris/sdk/IrisClientTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,24 @@ public class IrisClientTestUtils {
" </Error>\n" +
" </ErrorList>\n" +
"</TnOptionOrder>";

public static String updateSipPeerSmsSetting = "";

public static String updateSipPeerMmsSetting = "<MmsFeatureResponse>\n" +
" <MmsFeature>\n" +
" <MmsSettings>\n" +
" <Protocol>HTTP</Protocol>\n" +
" </MmsSettings>\n" +
" <Protocols>\n" +
" <HTTP>\n" +
" <HttpSettings>\n" +
" <ProxyPeerId>569238</ProxyPeerId>\n" +
" </HttpSettings>\n" +
" </HTTP>\n" +
" </Protocols>\n" +
" </MmsFeature>\n" +
"</MmsFeatureResponse>";

public static String updateSipPeerApplicationSetting = "";

}
57 changes: 54 additions & 3 deletions src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.bandwidth.iris.sdk;

import com.bandwidth.iris.sdk.model.SipPeer;
import com.bandwidth.iris.sdk.model.SipPeerTelephoneNumber;
import com.bandwidth.iris.sdk.model.SipPeerTelephoneNumbers;
import com.bandwidth.iris.sdk.model.*;
import org.junit.Test;

import java.util.List;
Expand Down Expand Up @@ -188,6 +186,59 @@ public void testGetTns() throws Exception {
assertNotNull(numbers);
assertEquals(2, numbers.size());
assertEquals("9195551212", numbers.get(0).getFullNumber());
}

@Test
public void testEnableSms() throws Exception {
String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/features/sms";
stubFor(post(urlMatching(url))
.willReturn(aResponse()
.withStatus(201).withHeader("Content-Type", "application/xml")));

String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678";
stubFor(get(urlMatching(sipPeerUrl))
.willReturn(aResponse()
.withStatus(200).withBody(IrisClientTestUtils.validSipPeerResponseXml)));

SipPeer peer = SipPeer.get(getDefaultClient(), "1234", "5678");

SipPeerSmsFeature settings = new SipPeerSmsFeature();
peer.enableSms(settings);
}

@Test
public void testEnableMms() throws Exception {
String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/features/mms";
stubFor(post(urlMatching(url))
.willReturn(aResponse()
.withStatus(201).withHeader("Content-Type", "application/xml")));

String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678";
stubFor(get(urlMatching(sipPeerUrl))
.willReturn(aResponse()
.withStatus(200).withBody(IrisClientTestUtils.validSipPeerResponseXml)));

SipPeer peer = SipPeer.get(getDefaultClient(), "1234", "5678");
peer.enableMms();
}

@Test
public void testUpdateSipPeerMessagingApplication() throws Exception {
String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/applicationSettings";
stubFor(post(urlMatching(url))
.willReturn(aResponse()
.withStatus(200).withBody(IrisClientTestUtils.updateSipPeerApplicationSetting)));

String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678";
stubFor(get(urlMatching(sipPeerUrl))
.willReturn(aResponse()
.withStatus(200).withBody(IrisClientTestUtils.validSipPeerResponseXml)));

SipPeer peer = SipPeer.get(getDefaultClient(), "1234", "5678");

SipPeerMessagingApplicationsSettings settings = new SipPeerMessagingApplicationsSettings();
settings.setApplicationId("abcd-1234");

peer.updateMessagingApplicationSettings(settings);
}
}

0 comments on commit d7e4624

Please sign in to comment.