Skip to content

Commit

Permalink
feat: Add Network capability to Application (#545)
Browse files Browse the repository at this point in the history
* feat: Add Network APIs to Application

* Bump versions

* Test network_apis
  • Loading branch information
SMadani authored Oct 15, 2024
1 parent ecb1b8f commit 7dd46a2
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

# [8.12.0] - 2024-10-??
- Added `network_apis` capability to Application API
- Added `@JsonCreator` annotation to webhook classes' `fromJson(String)` method

# [8.11.0] - 2024-09-25
- Added custom user agent property setting to `HttpConfig`
- Added RCS channel to Messages API
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.vonage</groupId>
<artifactId>server-sdk</artifactId>
<version>8.11.0</version>
<version>8.12.0</version>

<name>Vonage Java Server SDK</name>
<description>Java client for Vonage APIs</description>
Expand Down Expand Up @@ -45,7 +45,7 @@
<java.testVersion>21</java.testVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nexusUrl>https://oss.sonatype.org</nexusUrl>
<jackson.version>2.17.2</jackson.version>
<jackson.version>2.18.0</jackson.version>
<jjwt.version>0.12.6</jjwt.version>
</properties>

Expand Down Expand Up @@ -86,13 +86,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.0</version>
<version>5.11.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.13.0</version>
<version>5.14.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -190,7 +190,7 @@

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
</plugin>

<plugin>
Expand Down Expand Up @@ -228,7 +228,7 @@

<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.10.0</version>
<version>3.10.1</version>
<configuration>
<linksource>true</linksource>
</configuration>
Expand Down Expand Up @@ -291,7 +291,7 @@
<plugins>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.6</version>
<version>3.2.7</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/HttpWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class HttpWrapper {
private static final String
CLIENT_NAME = "vonage-java-sdk",
CLIENT_VERSION = "8.11.0",
CLIENT_VERSION = "8.12.0",
JAVA_VERSION = System.getProperty("java.version"),
USER_AGENT = String.format("%s/%s java/%s", CLIENT_NAME, CLIENT_VERSION, JAVA_VERSION);

Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/vonage/client/application/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public Builder removeCapability(Capability.Type type) {
capabilities.rtc == null &&
capabilities.messages == null &&
capabilities.vbc == null &&
capabilities.verify == null
capabilities.verify == null &&
capabilities.networkApis == null
) {
capabilities = null;
}
Expand Down Expand Up @@ -278,6 +279,7 @@ public static class Capabilities extends JsonableBaseObject {
private Rtc rtc;
private Vbc vbc;
private Verify verify;
private NetworkApis networkApis;

/**
* Voice capability.
Expand Down Expand Up @@ -323,14 +325,24 @@ public Vbc getVbc() {
* Verify capability.
*
* @return The Verify capability, or {@code null} if absent.
*
* @since 8.6.0
*/
@JsonProperty("verify")
public Verify getVerify() {
return verify;
}

/**
* Network APIs capability.
*
* @return The Network APIs capability, or {@code null} if absent.
* @since 8.12.0
*/
@JsonProperty("network_apis")
public NetworkApis getNetworkApis() {
return networkApis;
}

private void setCapability(Capability.Type type, Capability capability) {
switch (type) {
case VOICE:
Expand All @@ -348,6 +360,9 @@ private void setCapability(Capability.Type type, Capability capability) {
case VERIFY:
verify = (Verify) capability;
break;
case NETWORK:
networkApis = (NetworkApis) capability;
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ public enum Type {
*
* @since 8.6.0
*/
VERIFY
VERIFY,

/**
* Network APIs
*
* @since 8.12.0
*/
NETWORK
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright 2024 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client.application.capabilities;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URI;

/**
* Network APIs capability configuration settings.
*
* @since 8.12.0
*/
public final class NetworkApis extends Capability {
private URI redirectUri;
private String networkApplicationId;

private NetworkApis() {
}

private NetworkApis(Builder builder) {
super(builder);
redirectUri = builder.redirectUri;
networkApplicationId = builder.networkApplicationId;
}

@Override
public Type getType() {
return Type.NETWORK;
}

/**
* Gets the Redirect URL.
*
* @return The redirect URI, or {@code null} if absent.
*/
@JsonProperty("redirect_uri")
public URI getRedirectUri() {
return redirectUri;
}

/**
* Gets the network application ID (this is different from the Vonage application ID).
*
* @return The network application ID as a string, or {@code null} if absent.
*/
@JsonProperty("network_application_id")
public String getNetworkApplicationId() {
return networkApplicationId;
}

/**
* Entry point for constructing an instance of this class.
*
* @return A new Builder.
*/
public static Builder builder() {
return new Builder();
}

public static class Builder extends Capability.Builder<NetworkApis, Builder> {
private URI redirectUri;
private String networkApplicationId;

private Builder() {}

/**
* Sets the Redirect URL.
*
* @param redirectUri The redirect URL as a string.
* @return This builder.
*/
public Builder redirectUri(String redirectUri) {
return redirectUri(URI.create(redirectUri));
}

/**
* Sets the Redirect URL.
*
* @param redirectUri The redirect URL.
* @return This builder.
*/
public Builder redirectUri(URI redirectUri) {
this.redirectUri = redirectUri;
return this;
}

/**
* Sets the network application ID (this is different from the Vonage application ID).
*
* @param networkApplicationId The network application ID as a string.
* @return This builder.
*/
public Builder networkApplicationId(String networkApplicationId) {
this.networkApplicationId = networkApplicationId;
return this;
}

/**
* Builds the NetworkApis object.
*
* @return A new Network APIs capability.
*/
@Override
public NetworkApis build() {
return new NetworkApis(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vonage.client.application.capabilities;


/**
* VBC capability configuration settings.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ public List<Content> getContent() {
* @return The deserialized webhook response object.
* @throws com.vonage.client.VonageResponseParseException If the response could not be deserialized.
*/
@JsonCreator
public static InboundMessage fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public String getWhatsappConversationId() {
*
* @return An instance of this class with the fields populated, if present.
*/
@JsonCreator
public static MessageStatus fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/vonage/client/sms/MessageEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vonage.client.sms;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
Expand Down Expand Up @@ -198,6 +199,7 @@ public Integer getConcatPart() {
*
* @return An instance of this class with the fields populated, if present.
*/
@JsonCreator
public static MessageEvent fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vonage.client.verify2;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
Expand Down Expand Up @@ -176,6 +177,7 @@ public URI getSilentAuthUrl() {
* @return The deserialized webhook response object.
* @throws VonageResponseParseException If the response could not be deserialized.
*/
@JsonCreator
public static VerificationCallback fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/vonage/client/voice/AnswerWebhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
Expand Down Expand Up @@ -107,6 +108,7 @@ public URI getRegionUrl() {
*
* @return A new instance of this class.
*/
@JsonCreator
public static AnswerWebhook fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/vonage/client/voice/EventWebhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
Expand Down Expand Up @@ -292,6 +293,7 @@ public String getReason() {
*
* @return A new instance of this class.
*/
@JsonCreator
public static EventWebhook fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.function.Executable;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,6 +74,10 @@ public class ApplicationClientTest extends AbstractClientTest<ApplicationClient>
" }\n" +
" }\n" +
" },\n" +
" \"network_apis\": {\n" +
" \"network_application_id\": \"2bzfIFqRG128IcjSj1YhZNtw6LADG\",\n" +
" \"redirect_uri\": \"https://my-redirect-uri.example.com\"\n" +
" },\n" +
" \"rtc\": {\n" +
" \"webhooks\": {\n" +
" \"event_url\": {\n" +
Expand Down Expand Up @@ -133,6 +138,11 @@ static void assertEqualsSampleApplication(Application response) {
assertEquals("https://example.com/webhooks/status", message.getWebhooks().get(Webhook.Type.STATUS).getAddress());
assertEquals(HttpMethod.POST, message.getWebhooks().get(Webhook.Type.STATUS).getMethod());

NetworkApis networkApis = capabilities.getNetworkApis();
assertEquals(Capability.Type.NETWORK, networkApis.getType());
assertEquals("2bzfIFqRG128IcjSj1YhZNtw6LADG", networkApis.getNetworkApplicationId());
assertEquals(URI.create("https://my-redirect-uri.example.com"), networkApis.getRedirectUri());

Rtc rtc = capabilities.getRtc();
assertEquals(Capability.Type.RTC, rtc.getType());
assertEquals("https://example.com/webhooks/event", rtc.getWebhooks().get(Webhook.Type.EVENT).getAddress());
Expand Down
Loading

0 comments on commit 7dd46a2

Please sign in to comment.