Skip to content

Commit 7f9f332

Browse files
Ali-BenZarrouk-MBepels
authored andcommitted
Add support for updating Conversations webhooks
* Added update conversation webhook call includes unit tests Refactoring ConversationWebhookTest to use mocking instead of Spying service Refactored DTOs * Added an example for updating conversation webhook * Fixed comments on PR and upgraded to Java 11 Added status to ConversationWebhook Reverted Conversation web hook request for backwards compatibility Extracted creation of objects used in tests to TestUtil Added support for default values in example of testing update of conversation web hook * Updated travis ci to support Oracle JDK 11 * Updated major version * Renaming of DTO and testing against 11th of oracle and open jdks * Updated README.md * Updated travis ci job to remove matrix that was causing an extra build job to run
1 parent defc2c0 commit 7f9f332

15 files changed

+396
-151
lines changed

.travis.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,5 @@ dist: trusty
33
before_script: cd api/
44
script: mvn test -Ptest -DskipTests=false -Dhttps.protocols=TLSv1.2 -DmessageBirdAccessKey=test_iQpAp0KCs5GCsMpDhIx2leuNB -DmessageBirdMSISDN=31612345678
55
jdk:
6-
- oraclejdk8
7-
- oraclejdk9
8-
- openjdk7
9-
- openjdk8
10-
matrix:
11-
include:
12-
- jdk: oraclejdk7
13-
dist: precise
6+
- oraclejdk11
7+
- openjdk11

README.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,7 @@ cd java-rest-api/api
2323
mvn install
2424
```
2525

26-
If you are using maven simply add the messagebird API to your dependencies like this:
27-
28-
```
29-
<dependency>
30-
<groupId>com.messagebird</groupId>
31-
<artifactId>messagebird-api</artifactId>
32-
<version>2.1.1</version>
33-
</dependency>
34-
```
35-
36-
In case you are building without maven you still need maven to build the libraries but
37-
then simply copy the following jar's over to your project
38-
39-
```
40-
messagebird-api-2.1.1.jar
41-
jackson-core-2.9.8.jar
42-
jackson-databind-2.9.8.jar
43-
jackson-dataformat-csv-2.9.8.jar
44-
jackson-annotations-2.9.8.jar
45-
```
46-
26+
If you are using maven, please refer to the [mvn repository](https://mvnrepository.com/artifact/com.messagebird/messagebird-api) and choose your desired package version.
4727

4828
Examples
4929
--------

api/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.messagebird</groupId>
66
<artifactId>messagebird-api</artifactId>
7-
<version>2.1.2</version> <!--
7+
<version>3.0.0</version> <!--
88
are you going to bump a major number?
99
then you are pleased to replace com.messagebird.Base64 with some library, for example net.iharder.base64
1010
-->
@@ -43,7 +43,7 @@
4343
<developerConnection>scm:git:[email protected]:messagebird/java-rest-api.git</developerConnection>
4444
<url>[email protected]:messagebird/java-rest-api.git</url>
4545
<tag>HEAD</tag>
46-
</scm>
46+
</scm>
4747

4848
<profiles>
4949
<profile>
@@ -67,7 +67,7 @@
6767
<profile>
6868
<id>disable-doclint</id>
6969
<activation>
70-
<jdk>[1.8,)</jdk>
70+
<jdk>[11,)</jdk>
7171
</activation>
7272
<properties>
7373
<doclint>none</doclint>
@@ -140,7 +140,7 @@
140140
<plugin>
141141
<groupId>org.apache.maven.plugins</groupId>
142142
<artifactId>maven-javadoc-plugin</artifactId>
143-
<version>3.0.0</version>
143+
<version>3.1.0</version>
144144
<executions>
145145
<execution>
146146
<phase>package</phase>
@@ -177,8 +177,8 @@
177177
<artifactId>maven-compiler-plugin</artifactId>
178178
<version>3.7.0</version>
179179
<configuration>
180-
<source>1.7</source>
181-
<target>1.7</target>
180+
<source>11</source>
181+
<target>11</target>
182182
</configuration>
183183
</plugin>
184184
<plugin>

api/src/main/java/com/messagebird/MessageBirdClient.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,27 @@ public void deleteConversationWebhook(final String webhookId)
855855
* @param request Webhook to create.
856856
* @return Newly created webhook.
857857
*/
858-
public ConversationWebhook sendConversationWebhook(final ConversationWebhookRequest request)
858+
public ConversationWebhook sendConversationWebhook(final ConversationWebhookCreateRequest request)
859859
throws UnauthorizedException, GeneralException {
860860
String url = CONVERSATIONS_BASE_URL + CONVERSATION_WEBHOOK_PATH;
861861
return messageBirdService.sendPayLoad(url, request, ConversationWebhook.class);
862862
}
863863

864+
/**
865+
* Update an existing webhook.
866+
*
867+
* @param request update request.
868+
* @return Updated webhook.
869+
*/
870+
public ConversationWebhook updateConversationWebhook(final String id, final ConversationWebhookUpdateRequest request) throws UnauthorizedException, GeneralException {
871+
if (id == null || id.isEmpty()) {
872+
throw new IllegalArgumentException("Conversation webhook ID must be specified.");
873+
}
874+
875+
String url = CONVERSATIONS_BASE_URL + CONVERSATION_WEBHOOK_PATH + "/" + id;
876+
return messageBirdService.sendPayLoad("PATCH", url, request, ConversationWebhook.class);
877+
}
878+
864879
/**
865880
* Gets a single webhook.
866881
*

api/src/main/java/com/messagebird/MessageBirdServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
5757

5858
private final String accessKey;
5959
private final String serviceUrl;
60-
private final String clientVersion = "2.1.1";
60+
private final String clientVersion = "3.0.0";
6161
private final String userAgentString;
6262
private Proxy proxy = null;
6363

api/src/main/java/com/messagebird/objects/conversations/ConversationWebhook.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Date;
44
import java.util.List;
5+
import java.util.stream.Collectors;
56

67
/**
78
* Webhooks enable real-time notifications of conversation events to be
@@ -15,6 +16,7 @@ public class ConversationWebhook {
1516
private String id;
1617
private String channelId;
1718
private String url;
19+
private ConversationWebhookStatus status;
1820
private List<ConversationWebhookEvent> events;
1921
private Date createdDatetime;
2022
private Date updatedDatetime;
@@ -43,6 +45,14 @@ public void setUrl(String url) {
4345
this.url = url;
4446
}
4547

48+
public ConversationWebhookStatus getStatus() {
49+
return status;
50+
}
51+
52+
public void setStatus(ConversationWebhookStatus status) {
53+
this.status = status;
54+
}
55+
4656
public List<ConversationWebhookEvent> getEvents() {
4757
return events;
4858
}
@@ -73,9 +83,12 @@ public String toString() {
7383
"id='" + id + '\'' +
7484
", channelId='" + channelId + '\'' +
7585
", url='" + url + '\'' +
76-
", events=" + events +
86+
", status='" + status + '\'' +
87+
", events=" + events.stream().map(ConversationWebhookEvent::toString).collect(Collectors.joining(",")) +
7788
", createdDatetime=" + createdDatetime +
7889
", updatedDatetime=" + updatedDatetime +
7990
'}';
8091
}
92+
93+
8194
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.messagebird.objects.conversations;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
6+
/**
7+
* Contains common fields for webhook requests.
8+
*/
9+
public abstract class ConversationWebhookBaseRequest {
10+
protected String url;
11+
protected List<ConversationWebhookEvent> events;
12+
13+
public String getUrl() {
14+
return url;
15+
}
16+
17+
public void setUrl(String url) {
18+
this.url = url;
19+
}
20+
21+
public List<ConversationWebhookEvent> getEvents() {
22+
return events;
23+
}
24+
25+
public void setEvents(List<ConversationWebhookEvent> events) {
26+
this.events = events;
27+
}
28+
29+
protected abstract String getRequestName();
30+
31+
protected abstract String getStringRepresentationOfExtraParameters();
32+
33+
@Override
34+
public String toString() {
35+
return getRequestName() + "{" +
36+
getStringRepresentationOfExtraParameters() + '\'' +
37+
", url='" + url + '\'' +
38+
", events=" + events.stream().map(ConversationWebhookEvent::toString).collect(Collectors.joining(",")) +
39+
'}';
40+
}
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.messagebird.objects.conversations;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Request object used to create webhooks.
7+
*/
8+
public class ConversationWebhookCreateRequest extends ConversationWebhookBaseRequest{
9+
10+
private String channelId;
11+
12+
public ConversationWebhookCreateRequest(
13+
final String channelId,
14+
final String url,
15+
final List<ConversationWebhookEvent> events
16+
) {
17+
this.channelId = channelId;
18+
this.url = url;
19+
this.events = events;
20+
}
21+
22+
@Override
23+
protected String getRequestName() {
24+
return "ConversationWebhookCreateRequest";
25+
}
26+
27+
@Override
28+
protected String getStringRepresentationOfExtraParameters() {
29+
return "channelId='" + channelId;
30+
}
31+
}

api/src/main/java/com/messagebird/objects/conversations/ConversationWebhookRequest.java

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.messagebird.objects.conversations;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
6+
/**
7+
* Indicates whether a conversation webhook is <strong>enabled</strong> or <strong>disabled</strong>.
8+
*/
9+
public enum ConversationWebhookStatus {
10+
ENABLED("enabled"),
11+
DISABLED("disabled");
12+
13+
private final String status;
14+
15+
ConversationWebhookStatus(final String status) {
16+
this.status = status;
17+
}
18+
19+
@JsonCreator
20+
public static ConversationWebhookStatus forValue(final String value) {
21+
for (ConversationWebhookStatus conversationWebhookStatus : ConversationWebhookStatus.values()) {
22+
if (conversationWebhookStatus.getStatus().equals(value)) {
23+
return conversationWebhookStatus;
24+
}
25+
}
26+
27+
return null;
28+
}
29+
30+
@JsonValue
31+
public String toJson() {
32+
return getStatus();
33+
}
34+
35+
public String getStatus() {
36+
return status;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return getStatus();
42+
}
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.messagebird.objects.conversations;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Request object used to update webhook.
7+
*/
8+
public class ConversationWebhookUpdateRequest extends ConversationWebhookBaseRequest {
9+
private ConversationWebhookStatus status;
10+
11+
public ConversationWebhookUpdateRequest(
12+
final ConversationWebhookStatus status,
13+
final String url,
14+
final List<ConversationWebhookEvent> events
15+
) {
16+
this.status = status;
17+
this.url = url;
18+
this.events = events;
19+
}
20+
21+
public ConversationWebhookStatus getStatus() {
22+
return status;
23+
}
24+
25+
public void setStatus(ConversationWebhookStatus status) {
26+
this.status = status;
27+
}
28+
29+
@Override
30+
protected String getRequestName() {
31+
return "ConversationWebhookUpdateRequest";
32+
}
33+
34+
@Override
35+
protected String getStringRepresentationOfExtraParameters() {
36+
return "status='" + status;
37+
}
38+
}

0 commit comments

Comments
 (0)