From af5abb3f1a470b9e037ac91fe1f156b9f36e29ac Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:15:01 -0400 Subject: [PATCH 1/3] SWI-3816 Add SipPeer functionality Allow users to enable SMS and MMS Allow users to associate a messaging application with a SipPeer --- README.md | 20 +++ .../com/bandwidth/iris/sdk/model/SipPeer.java | 16 ++ .../SipPeerMessagingApplicationsSettings.java | 14 ++ .../iris/sdk/model/SipPeerMmsFeature.java | 43 ++++++ .../iris/sdk/model/SipPeerSmsFeature.java | 138 ++++++++++++++++++ .../bandwidth/iris/sdk/BaseModelTests.java | 4 + .../iris/sdk/IrisClientTestUtils.java | 20 +++ .../com/bandwidth/iris/sdk/SipPeerTests.java | 57 +++++++- 8 files changed, 309 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/bandwidth/iris/sdk/model/SipPeerMessagingApplicationsSettings.java create mode 100644 src/main/java/com/bandwidth/iris/sdk/model/SipPeerMmsFeature.java create mode 100644 src/main/java/com/bandwidth/iris/sdk/model/SipPeerSmsFeature.java diff --git a/README.md b/README.md index 0c3821c..8b10004 100644 --- a/README.md +++ b/README.md @@ -324,6 +324,26 @@ peer.getTn("number"); peer.moveTns(sipPeerTelephoneNumbers); ``` +### Enable SMS Settings +```java +// Zone1 for US & Canada enabled by default +SipPeerSmsFeature settings = new SipPeerSmsFeature(); +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 diff --git a/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java b/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java index d28dade..97562f9 100644 --- a/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java +++ b/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java @@ -208,4 +208,20 @@ public List 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); + } } diff --git a/src/main/java/com/bandwidth/iris/sdk/model/SipPeerMessagingApplicationsSettings.java b/src/main/java/com/bandwidth/iris/sdk/model/SipPeerMessagingApplicationsSettings.java new file mode 100644 index 0000000..2266a3e --- /dev/null +++ b/src/main/java/com/bandwidth/iris/sdk/model/SipPeerMessagingApplicationsSettings.java @@ -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; + } +} diff --git a/src/main/java/com/bandwidth/iris/sdk/model/SipPeerMmsFeature.java b/src/main/java/com/bandwidth/iris/sdk/model/SipPeerMmsFeature.java new file mode 100644 index 0000000..8875c31 --- /dev/null +++ b/src/main/java/com/bandwidth/iris/sdk/model/SipPeerMmsFeature.java @@ -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 = ""; + } +} diff --git a/src/main/java/com/bandwidth/iris/sdk/model/SipPeerSmsFeature.java b/src/main/java/com/bandwidth/iris/sdk/model/SipPeerSmsFeature.java new file mode 100644 index 0000000..ac1721a --- /dev/null +++ b/src/main/java/com/bandwidth/iris/sdk/model/SipPeerSmsFeature.java @@ -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; + } + +} diff --git a/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java b/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java index 6454f1c..7dd02f8 100644 --- a/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java +++ b/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java @@ -16,6 +16,10 @@ protected IrisClient getDefaultClient() { return new IrisClient("http://localhost:8090", "accountId", "username", "password", "v1.0"); } + protected IrisClient getPipedreamClient() { + return new IrisClient("https://d815f3b06d79650d7a886f0c2ce1955d.m.pipedream.net", "accountId", "username", "password", "v1.0"); + } + public void setMessage(String s) { this.message = s; } diff --git a/src/test/java/com/bandwidth/iris/sdk/IrisClientTestUtils.java b/src/test/java/com/bandwidth/iris/sdk/IrisClientTestUtils.java index 15a68c5..111382d 100644 --- a/src/test/java/com/bandwidth/iris/sdk/IrisClientTestUtils.java +++ b/src/test/java/com/bandwidth/iris/sdk/IrisClientTestUtils.java @@ -886,4 +886,24 @@ public class IrisClientTestUtils { " \n" + " \n" + ""; + + public static String updateSipPeerSmsSetting = ""; + + public static String updateSipPeerMmsSetting = "\n" + + " \n" + + " \n" + + " HTTP\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 569238\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static String updateSipPeerApplicationSetting = ""; + } diff --git a/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java b/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java index 6b5ab52..d1ffb5d 100644 --- a/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java +++ b/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java @@ -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; @@ -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(get(urlMatching(url)) + .willReturn(aResponse() + .withStatus(200))); + + 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))); + + 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(put(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); } } From 7cbc4ea522b690f6c622276211ce60f146e25413 Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:31:17 -0400 Subject: [PATCH 2/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8b10004..b308e49 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,8 @@ peer.moveTns(sipPeerTelephoneNumbers); ```java // Zone1 for US & Canada enabled by default SipPeerSmsFeature settings = new SipPeerSmsFeature(); +settings.setTollFree(true); +settings.setShortCode(true); peer.enableSms(settings); ``` From 8566865e9e58b2897f5e3df7e86f14baec4ee43e Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:53:44 -0400 Subject: [PATCH 3/3] Remove Pipedream Client + Fix stub methods in test --- src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java | 2 +- src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java | 4 ---- src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java | 8 ++++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java b/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java index 97562f9..0c82e42 100644 --- a/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java +++ b/src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java @@ -217,7 +217,7 @@ public void enableSms(SipPeerSmsFeature smsSettings) throws Exception { 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); + IrisPath.SIPPEERS_URI_PATH, peerId, "products", "messaging", "features", "mms" }), mmsSettings); } public void updateMessagingApplicationSettings (SipPeerMessagingApplicationsSettings settings) throws Exception { diff --git a/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java b/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java index 7dd02f8..6454f1c 100644 --- a/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java +++ b/src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java @@ -16,10 +16,6 @@ protected IrisClient getDefaultClient() { return new IrisClient("http://localhost:8090", "accountId", "username", "password", "v1.0"); } - protected IrisClient getPipedreamClient() { - return new IrisClient("https://d815f3b06d79650d7a886f0c2ce1955d.m.pipedream.net", "accountId", "username", "password", "v1.0"); - } - public void setMessage(String s) { this.message = s; } diff --git a/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java b/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java index d1ffb5d..42807ea 100644 --- a/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java +++ b/src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java @@ -191,9 +191,9 @@ public void testGetTns() throws Exception { @Test public void testEnableSms() throws Exception { String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/features/sms"; - stubFor(get(urlMatching(url)) + stubFor(post(urlMatching(url)) .willReturn(aResponse() - .withStatus(200))); + .withStatus(201).withHeader("Content-Type", "application/xml"))); String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678"; stubFor(get(urlMatching(sipPeerUrl)) @@ -211,7 +211,7 @@ 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))); + .withStatus(201).withHeader("Content-Type", "application/xml"))); String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678"; stubFor(get(urlMatching(sipPeerUrl)) @@ -225,7 +225,7 @@ public void testEnableMms() throws Exception { @Test public void testUpdateSipPeerMessagingApplication() throws Exception { String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/applicationSettings"; - stubFor(put(urlMatching(url)) + stubFor(post(urlMatching(url)) .willReturn(aResponse() .withStatus(200).withBody(IrisClientTestUtils.updateSipPeerApplicationSetting)));