Skip to content

Commit d7e4624

Browse files
authored
Merge pull request #68 from Bandwidth/SWI-3816
SWI-3816 Add SipPeer functionality
2 parents 4a6f532 + 8566865 commit d7e4624

File tree

7 files changed

+307
-3
lines changed

7 files changed

+307
-3
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,28 @@ peer.getTn("number");
324324
peer.moveTns(sipPeerTelephoneNumbers);
325325
```
326326

327+
### Enable SMS Settings
328+
```java
329+
// Zone1 for US & Canada enabled by default
330+
SipPeerSmsFeature settings = new SipPeerSmsFeature();
331+
settings.setTollFree(true);
332+
settings.setShortCode(true);
333+
peer.enableSms(settings);
334+
```
335+
336+
### Enable MMS
337+
```java
338+
peer.enableMms();
339+
```
340+
341+
### Associate a SipPeer with a Messaging Application
342+
```java
343+
SipPeerMessagingApplicationsSettings settings = new SipPeerMessagingApplicationsSettings();
344+
settings.setApplicationId("abcd-1234");
345+
346+
peer.updateMessagingApplicationSettings(settings);
347+
```
348+
327349
## Sites
328350

329351
### Create A Site

src/main/java/com/bandwidth/iris/sdk/model/SipPeer.java

+16
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,20 @@ public List<SipPeerTelephoneNumber> getTns() throws Exception {
208208
IrisPath.SIPPEERS_URI_PATH, peerId, "tns" }),
209209
SipPeerTelephoneNumbersResponse.class).getSipPeerTelephoneNumbers();
210210
}
211+
212+
public void enableSms(SipPeerSmsFeature smsSettings) throws Exception {
213+
client.post(client.buildAccountModelUri(new String[] { IrisPath.SITES_URI_PATH, siteId,
214+
IrisPath.SIPPEERS_URI_PATH, peerId, "products", "messaging", "features", "sms" }), smsSettings);
215+
}
216+
217+
public void enableMms() throws Exception {
218+
SipPeerMmsFeature mmsSettings = new SipPeerMmsFeature();
219+
client.post(client.buildAccountModelUri(new String[] { IrisPath.SITES_URI_PATH, siteId,
220+
IrisPath.SIPPEERS_URI_PATH, peerId, "products", "messaging", "features", "mms" }), mmsSettings);
221+
}
222+
223+
public void updateMessagingApplicationSettings (SipPeerMessagingApplicationsSettings settings) throws Exception {
224+
client.post(client.buildAccountModelUri(new String[] { IrisPath.SITES_URI_PATH, siteId,
225+
IrisPath.SIPPEERS_URI_PATH, peerId, "products", "messaging","applicationSettings" }), settings);
226+
}
211227
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.bandwidth.iris.sdk.model;
2+
3+
import javax.xml.bind.annotation.XmlElement;
4+
import javax.xml.bind.annotation.XmlRootElement;
5+
6+
@XmlRootElement(name = "ApplicationSettings")
7+
public class SipPeerMessagingApplicationsSettings extends BaseModel {
8+
@XmlElement(name = "HttpMessagingV2AppId")
9+
String applicationId;
10+
11+
public void setApplicationId(String applicationId) {
12+
this.applicationId = applicationId;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.bandwidth.iris.sdk.model;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlElement;
6+
import javax.xml.bind.annotation.XmlRootElement;
7+
8+
@XmlRootElement(name = "MmsFeature")
9+
@XmlAccessorType(XmlAccessType.FIELD)
10+
public class SipPeerMmsFeature extends BaseModel {
11+
@XmlElement(name = "MmsSettings")
12+
MmsSettings mmsSettings;
13+
@XmlElement(name = "Protocols")
14+
Protocols protocols;
15+
16+
public SipPeerMmsFeature()
17+
{
18+
this.mmsSettings = new MmsSettings();
19+
this.protocols = new Protocols();
20+
this.protocols.http = new Http();
21+
this.protocols.http.httpSettings = new HttpSettings();
22+
}
23+
24+
private static class MmsSettings extends BaseModel {
25+
@XmlElement(name = "Protocol")
26+
private final String protocol = "HTTP";
27+
}
28+
29+
private static class Protocols extends BaseModel {
30+
@XmlElement(name = "HTTP")
31+
Http http;
32+
}
33+
34+
private static class Http extends BaseModel {
35+
@XmlElement(name = "HttpSettings")
36+
HttpSettings httpSettings = new HttpSettings();
37+
}
38+
39+
private static class HttpSettings extends BaseModel {
40+
@XmlElement(name = "ProxyPeerId")
41+
String proxyPeerId = "";
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package com.bandwidth.iris.sdk.model;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlElement;
6+
import javax.xml.bind.annotation.XmlRootElement;
7+
8+
@XmlRootElement(name = "SipPeerSmsFeature")
9+
@XmlAccessorType(XmlAccessType.FIELD)
10+
public class SipPeerSmsFeature extends BaseModel {
11+
@XmlElement(name = "HttpSettings")
12+
HttpSettings httpSettings;
13+
@XmlElement(name = "SipPeerSmsFeatureSettings")
14+
SipPeerSmsFeatureSettings sipPeerSmsFeatureSettings;
15+
16+
public SipPeerSmsFeature() {
17+
httpSettings = new HttpSettings();
18+
sipPeerSmsFeatureSettings = new SipPeerSmsFeatureSettings();
19+
}
20+
21+
private static class HttpSettings{
22+
Integer proxyPeerId = null;
23+
}
24+
25+
private static class SipPeerSmsFeatureSettings extends BaseModel {
26+
@XmlElement(name = "A2pLongCode")
27+
String a2pLongCode;
28+
@XmlElement(name = "A2pMessageClass")
29+
String a2pMessageClass;
30+
@XmlElement(name = "A2pCampaignId")
31+
String a2pCampaignId;
32+
@XmlElement(name = "Protocol")
33+
String protocol = "HTTP";
34+
@XmlElement(name = "TollFree")
35+
boolean tollFree = false;
36+
@XmlElement(name = "ShortCode")
37+
boolean shortCode = false;
38+
@XmlElement(name = "Zone1")
39+
boolean zone1 = true;
40+
@XmlElement(name = "Zone2")
41+
boolean zone2 = false;
42+
@XmlElement(name = "Zone3")
43+
boolean zone3 = false;
44+
@XmlElement(name = "Zone4")
45+
boolean zone4 = false;
46+
@XmlElement(name = "Zone5")
47+
boolean zone5 = false;
48+
49+
}
50+
public String getA2pLongCode() {
51+
return this.sipPeerSmsFeatureSettings.a2pLongCode;
52+
}
53+
54+
public void setA2pLongCode(String a2pLongCode) {
55+
this.sipPeerSmsFeatureSettings.a2pLongCode = a2pLongCode;
56+
}
57+
58+
public String getA2pMessageClass() {
59+
return this.sipPeerSmsFeatureSettings.a2pMessageClass;
60+
}
61+
62+
public void setA2pMessageClass(String a2pMessageClass) {
63+
this.sipPeerSmsFeatureSettings.a2pMessageClass = a2pMessageClass;
64+
}
65+
66+
public String getA2pCampaignId() {
67+
return this.sipPeerSmsFeatureSettings.a2pCampaignId;
68+
}
69+
70+
public void setA2pCampaignId(String a2pCampaignId) {
71+
this.sipPeerSmsFeatureSettings.a2pCampaignId = a2pCampaignId;
72+
}
73+
74+
public String getProtocol() {
75+
return this.sipPeerSmsFeatureSettings.protocol;
76+
}
77+
78+
public void setProtocol(String protocol) {
79+
this.sipPeerSmsFeatureSettings.protocol = protocol;
80+
}
81+
82+
public boolean isTollFree() {
83+
return this.sipPeerSmsFeatureSettings.tollFree;
84+
}
85+
86+
public void setTollFree(boolean tollFree) {
87+
this.sipPeerSmsFeatureSettings.tollFree = tollFree;
88+
}
89+
90+
public boolean isShortCode() {
91+
return this.sipPeerSmsFeatureSettings.shortCode;
92+
}
93+
94+
public void setShortCode(boolean shortCode) {
95+
this.sipPeerSmsFeatureSettings.shortCode = shortCode;
96+
}
97+
98+
public boolean isZone1() {
99+
return this.sipPeerSmsFeatureSettings.zone1;
100+
}
101+
102+
public void setZone1(boolean zone1) {
103+
this.sipPeerSmsFeatureSettings.zone1 = zone1;
104+
}
105+
106+
public boolean isZone2() {
107+
return this.sipPeerSmsFeatureSettings.zone2;
108+
}
109+
110+
public void setZone2(boolean zone2) {
111+
this.sipPeerSmsFeatureSettings.zone2 = zone2;
112+
}
113+
114+
public boolean isZone3() {
115+
return this.sipPeerSmsFeatureSettings.zone3;
116+
}
117+
118+
public void setZone3(boolean zone3) {
119+
this.sipPeerSmsFeatureSettings.zone3 = zone3;
120+
}
121+
122+
public boolean isZone4() {
123+
return this.sipPeerSmsFeatureSettings.zone4;
124+
}
125+
126+
public void setZone4(boolean zone4) {
127+
this.sipPeerSmsFeatureSettings.zone4 = zone4;
128+
}
129+
130+
public boolean isZone5() {
131+
return this.sipPeerSmsFeatureSettings.zone5;
132+
}
133+
134+
public void setZone5(boolean zone5) {
135+
this.sipPeerSmsFeatureSettings.zone5 = zone5;
136+
}
137+
138+
}

src/test/java/com/bandwidth/iris/sdk/IrisClientTestUtils.java

+20
Original file line numberDiff line numberDiff line change
@@ -886,4 +886,24 @@ public class IrisClientTestUtils {
886886
" </Error>\n" +
887887
" </ErrorList>\n" +
888888
"</TnOptionOrder>";
889+
890+
public static String updateSipPeerSmsSetting = "";
891+
892+
public static String updateSipPeerMmsSetting = "<MmsFeatureResponse>\n" +
893+
" <MmsFeature>\n" +
894+
" <MmsSettings>\n" +
895+
" <Protocol>HTTP</Protocol>\n" +
896+
" </MmsSettings>\n" +
897+
" <Protocols>\n" +
898+
" <HTTP>\n" +
899+
" <HttpSettings>\n" +
900+
" <ProxyPeerId>569238</ProxyPeerId>\n" +
901+
" </HttpSettings>\n" +
902+
" </HTTP>\n" +
903+
" </Protocols>\n" +
904+
" </MmsFeature>\n" +
905+
"</MmsFeatureResponse>";
906+
907+
public static String updateSipPeerApplicationSetting = "";
908+
889909
}

src/test/java/com/bandwidth/iris/sdk/SipPeerTests.java

+54-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.bandwidth.iris.sdk;
22

3-
import com.bandwidth.iris.sdk.model.SipPeer;
4-
import com.bandwidth.iris.sdk.model.SipPeerTelephoneNumber;
5-
import com.bandwidth.iris.sdk.model.SipPeerTelephoneNumbers;
3+
import com.bandwidth.iris.sdk.model.*;
64
import org.junit.Test;
75

86
import java.util.List;
@@ -188,6 +186,59 @@ public void testGetTns() throws Exception {
188186
assertNotNull(numbers);
189187
assertEquals(2, numbers.size());
190188
assertEquals("9195551212", numbers.get(0).getFullNumber());
189+
}
190+
191+
@Test
192+
public void testEnableSms() throws Exception {
193+
String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/features/sms";
194+
stubFor(post(urlMatching(url))
195+
.willReturn(aResponse()
196+
.withStatus(201).withHeader("Content-Type", "application/xml")));
197+
198+
String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678";
199+
stubFor(get(urlMatching(sipPeerUrl))
200+
.willReturn(aResponse()
201+
.withStatus(200).withBody(IrisClientTestUtils.validSipPeerResponseXml)));
202+
203+
SipPeer peer = SipPeer.get(getDefaultClient(), "1234", "5678");
204+
205+
SipPeerSmsFeature settings = new SipPeerSmsFeature();
206+
peer.enableSms(settings);
207+
}
208+
209+
@Test
210+
public void testEnableMms() throws Exception {
211+
String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/features/mms";
212+
stubFor(post(urlMatching(url))
213+
.willReturn(aResponse()
214+
.withStatus(201).withHeader("Content-Type", "application/xml")));
215+
216+
String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678";
217+
stubFor(get(urlMatching(sipPeerUrl))
218+
.willReturn(aResponse()
219+
.withStatus(200).withBody(IrisClientTestUtils.validSipPeerResponseXml)));
220+
221+
SipPeer peer = SipPeer.get(getDefaultClient(), "1234", "5678");
222+
peer.enableMms();
223+
}
224+
225+
@Test
226+
public void testUpdateSipPeerMessagingApplication() throws Exception {
227+
String url = "/v1.0/accounts/accountId/sites/1234/sippeers/5678/products/messaging/applicationSettings";
228+
stubFor(post(urlMatching(url))
229+
.willReturn(aResponse()
230+
.withStatus(200).withBody(IrisClientTestUtils.updateSipPeerApplicationSetting)));
231+
232+
String sipPeerUrl = "/v1.0/accounts/accountId/sites/1234/sippeers/5678";
233+
stubFor(get(urlMatching(sipPeerUrl))
234+
.willReturn(aResponse()
235+
.withStatus(200).withBody(IrisClientTestUtils.validSipPeerResponseXml)));
236+
237+
SipPeer peer = SipPeer.get(getDefaultClient(), "1234", "5678");
238+
239+
SipPeerMessagingApplicationsSettings settings = new SipPeerMessagingApplicationsSettings();
240+
settings.setApplicationId("abcd-1234");
191241

242+
peer.updateMessagingApplicationSettings(settings);
192243
}
193244
}

0 commit comments

Comments
 (0)