Skip to content

Commit f21b739

Browse files
moretonbEsendexDev
authored andcommitted
Add opt outs (#12)
Adds the ability to get and create opt out resources. Includes some changes and improvements to the existing tests to increase coverage for regression protection. Usage: * Create an instance of the optout service ```java UserPassword userPassword = new UserPassword("YourUsername","YourPassword"); BasicServiceFactory serviceFactory = ServiceFactory.createBasicAuthenticatingFactory(userPassword); OptOutService optOutService = serviceFactory.getOptOutService(); ``` * Get single opt out ```java OptOutResponse optout = optOutService.getOptOut("b6a39581-9cfc-40ea-9b40-9320444cf49d"); ``` * Get paged opt outs ```java OptOutCollectionResponse optouts = optOutService.getOptOuts(1, 15); ``` * Create an opt out ```java FromAddress fromAddress = new FromAddress(); fromAddress.setPhoneNumber("99887744556322"); OptOutRequest request = new OptOutRequestImpl(); request.setAccountReference("EX006789"); request.setFromAddress(fromAddress); OptOutResponse optout = optOutService.createOptOut(request); ```
1 parent 88e5187 commit f21b739

File tree

51 files changed

+1989
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1989
-464
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Esendex Java SDK
2+
================
3+
4+
[![Build Status](https://travis-ci.org/esendex/esendex-java-sdk.svg?branch=master)](https://travis-ci.org/esendex/esendex-java-sdk)
5+
6+
The Esendex Java SDK is an easy to use client for the Esendex REST API which you can use to integrate SMS and Voice messaging into any application built with the JVM.
7+
8+
It contains a set of services for sending SMS and Voice messages, receiving SMS, tracking the status of your sent messages and more.
9+
10+
Full details at http://developers.esendex.com/SDKs/Java-SDK

esendex-java-sdk.iml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
</content>
1313
<orderEntry type="inheritedJdk" />
1414
<orderEntry type="sourceFolder" forTests="false" />
15-
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
16-
<orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.7" level="project" />
15+
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
16+
<orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.9" level="project" />
1717
<orderEntry type="library" name="Maven: xmlpull:xmlpull:1.1.3.1" level="project" />
1818
<orderEntry type="library" name="Maven: xpp3:xpp3_min:1.1.4c" level="project" />
19-
<orderEntry type="library" name="Maven: junit:junit:4.9" level="project" />
20-
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
21-
<orderEntry type="library" name="Maven: com.pyruby:java-stub-server:0.12" level="project" />
22-
<orderEntry type="library" name="Maven: org.mortbay.jetty:jetty:6.1.26" level="project" />
23-
<orderEntry type="library" name="Maven: org.mortbay.jetty:jetty-util:6.1.26" level="project" />
24-
<orderEntry type="library" name="Maven: org.mortbay.jetty:servlet-api:2.5-20081211" level="project" />
25-
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" />
19+
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
20+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
21+
<orderEntry type="library" scope="TEST" name="Maven: com.pyruby:java-stub-server:0.14" level="project" />
22+
<orderEntry type="library" scope="TEST" name="Maven: org.mortbay.jetty:jetty:6.1.26" level="project" />
23+
<orderEntry type="library" scope="TEST" name="Maven: org.mortbay.jetty:jetty-util:6.1.26" level="project" />
24+
<orderEntry type="library" scope="TEST" name="Maven: org.mortbay.jetty:servlet-api:2.5-20081211" level="project" />
25+
<orderEntry type="library" scope="TEST" name="Maven: javax.servlet:servlet-api:2.5" level="project" />
2626
</component>
2727
</module>

pom.xml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@
66
<properties>
77
<buildnumber>0</buildnumber>
88
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
9+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
910
</properties>
1011
<groupId>esendex-java-sdk</groupId>
1112
<artifactId>esendex-java-sdk</artifactId>
12-
<version>3.0.0</version>
13+
<version>3.1.0</version>
14+
15+
<profiles>
16+
<profile>
17+
<id>doclint-java8-disable</id>
18+
<activation>
19+
<jdk>[1.8,)</jdk>
20+
</activation>
21+
<properties>
22+
<javadoc.opts>-Xdoclint:none</javadoc.opts>
23+
</properties>
24+
</profile>
25+
</profiles>
26+
1327
<build>
1428
<plugins>
29+
<plugin>
30+
<groupId>org.codehaus.mojo</groupId>
31+
<artifactId>versions-maven-plugin</artifactId>
32+
<version>2.2</version>
33+
</plugin>
1534
<plugin>
1635
<artifactId>maven-compiler-plugin</artifactId>
1736
<version>2.3.2</version>
@@ -60,7 +79,7 @@
6079
<goal>jar</goal>
6180
</goals>
6281
<configuration>
63-
<additionalparam>-Xdoclint:none</additionalparam>
82+
<additionalparam>${javadoc.opts}</additionalparam>
6483
</configuration>
6584
</execution>
6685
</executions>
@@ -87,27 +106,39 @@
87106
</resource>
88107
</resources>
89108
</build>
109+
90110
<dependencies>
91111
<dependency>
92112
<groupId>commons-logging</groupId>
93113
<artifactId>commons-logging</artifactId>
94-
<version>1.1.1</version>
114+
<version>1.2</version>
95115
</dependency>
96116
<dependency>
97117
<groupId>com.thoughtworks.xstream</groupId>
98118
<artifactId>xstream</artifactId>
99-
<version>1.4.7</version>
119+
<version>1.4.9</version>
100120
</dependency>
101121
<dependency>
102122
<groupId>junit</groupId>
103123
<artifactId>junit</artifactId>
104-
<version>4.9</version>
124+
<version>4.12</version>
125+
<scope>test</scope>
105126
</dependency>
106127
<dependency>
107128
<groupId>com.pyruby</groupId>
108129
<artifactId>java-stub-server</artifactId>
109-
<version>0.12</version>
130+
<version>0.14</version>
131+
<scope>test</scope>
110132
</dependency>
111133
</dependencies>
112134

135+
<reporting>
136+
<plugins>
137+
<plugin>
138+
<groupId>org.codehaus.mojo</groupId>
139+
<artifactId>versions-maven-plugin</artifactId>
140+
<version>2.2</version>
141+
</plugin>
142+
</plugins>
143+
</reporting>
113144
</project>

src/main/java/esendex/sdk/java/ServiceFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ public SurveysService getSurveysService() {
8989
return new SurveysServiceImpl(authenticator);
9090
}
9191

92+
/**
93+
* Obtains a service suitable for operations on the opt-outs resource.
94+
* @return the service
95+
*/
96+
public OptOutService getOptOutService() {
97+
return new OptOutServiceImpl(authenticator);
98+
}
99+
92100
}

src/main/java/esendex/sdk/java/http/HttpQuery.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public class HttpQuery {
2828
public static final Key<String> ACCOUNT_REFERENCE
2929
= new Key<String>("accountreference");
3030

31+
public static final Key<String> FROM
32+
= new Key<String>("from");
33+
3134
public static final String ACCOUNT_FILTER = "account";
3235

3336

src/main/java/esendex/sdk/java/model/domain/impl/ContactResponseAssembler.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99

1010
public class ContactResponseAssembler {
1111

12-
public ContactResponse createResponse(ContactDto dto) {
12+
public ContactResponse createResponse(ContactDto dto) {
1313

14-
ContactResponseImpl resp = new ContactResponseImpl();
14+
ContactResponseImpl resp = new ContactResponseImpl();
1515

16-
resp.setFirstName(dto.getFirstname());
17-
resp.setId(dto.getId());
16+
resp.setFirstName(dto.getFirstname());
17+
resp.setId(dto.getId());
1818
resp.setAccountReference(dto.getAccountReference());
19-
resp.setLastName(dto.getLastname());
20-
resp.setMobileNumber(dto.getPhoneNumber());
21-
resp.setQuickName(dto.getQuickname());
19+
resp.setLastName(dto.getLastname());
20+
resp.setMobileNumber(dto.getPhoneNumber());
21+
resp.setQuickName(dto.getQuickname());
2222

23+
return resp;
24+
}
2325

24-
return resp;
25-
}
26+
public List<ContactResponse> createCollectionResponse(ContactCollectionDto col) {
2627

27-
public List<ContactResponse> createCollectionResponse(ContactCollectionDto col) {
28+
List<ContactResponse> list = new ArrayList<>();
29+
if (col != null) {
30+
for (ContactDto dto : col.getContacts()) {
31+
list.add(createResponse(dto));
32+
}
33+
}
2834

29-
List<ContactResponse> list = new ArrayList<ContactResponse>();
30-
if (col != null) {
31-
for (ContactDto dto : col.getContacts()) {
32-
list.add(createResponse(dto));
33-
}
34-
}
35-
return list;
36-
}
35+
return list;
36+
}
3737
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package esendex.sdk.java.model.domain.impl;
2+
3+
public class FromAddress {
4+
5+
private String phoneNumber;
6+
7+
public String getPhoneNumber() { return phoneNumber; }
8+
9+
public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; }
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package esendex.sdk.java.model.domain.impl;
2+
3+
import esendex.sdk.java.model.domain.response.OptOutCollectionResponse;
4+
import esendex.sdk.java.model.domain.response.OptOutResponse;
5+
6+
import java.util.Iterator;
7+
import java.util.List;
8+
9+
public class OptOutCollectionResponseImpl extends PageableImpl implements OptOutCollectionResponse {
10+
11+
private List<OptOutResponse> optouts;
12+
13+
public OptOutCollectionResponseImpl(List<OptOutResponse> optouts) {
14+
this.optouts = optouts;
15+
}
16+
17+
public List<OptOutResponse> getOptOuts() {
18+
return optouts;
19+
}
20+
21+
public void setOptouts(List<OptOutResponse> optouts) {
22+
this.optouts = optouts;
23+
}
24+
25+
@Override
26+
public Iterator<OptOutResponse> iterator() {
27+
return null;
28+
}
29+
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package esendex.sdk.java.model.domain.impl;
2+
3+
import esendex.sdk.java.model.domain.request.OptOutRequest;
4+
import esendex.sdk.java.model.transfer.optout.FromAddressDto;
5+
import esendex.sdk.java.model.transfer.optout.OptOutRequestDto;
6+
7+
public class OptOutRequestAssembler {
8+
9+
public OptOutRequestDto createOptOutDto(OptOutRequest optOutRequest) {
10+
11+
OptOutRequestDto dto = new OptOutRequestDto();
12+
13+
FromAddressDto fromAddress = new FromAddressDto();
14+
fromAddress.setPhoneNumber(optOutRequest.getFromAddress().getPhoneNumber());
15+
16+
dto.setFromAddress(fromAddress);
17+
dto.setAccountReference(optOutRequest.getAccountReference());
18+
19+
return dto;
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package esendex.sdk.java.model.domain.impl;
2+
3+
import esendex.sdk.java.model.domain.request.OptOutRequest;
4+
5+
public class OptOutRequestImpl implements OptOutRequest {
6+
private String accountReference;
7+
private FromAddress fromAddress;
8+
9+
@Override
10+
public String getAccountReference() {
11+
return accountReference;
12+
}
13+
14+
@Override
15+
public void setAccountReference(String accountReference) {
16+
this.accountReference = accountReference;
17+
}
18+
19+
@Override
20+
public FromAddress getFromAddress() {
21+
return fromAddress;
22+
}
23+
24+
@Override
25+
public void setFromAddress(FromAddress fromAddress) {
26+
this.fromAddress = fromAddress;
27+
}
28+
}

0 commit comments

Comments
 (0)