Skip to content

Commit

Permalink
Prepare Video API for migration to DynamicEndpoint (#497)
Browse files Browse the repository at this point in the history
* Add implements Jsonable

* Unified & flattened request wrappers

* Implement QueryParamsRequest for video

* Use RestEndpoint in VideoClient

* Migrated tests to JUnit5

* Removed JUnit4 dependency

* Bump Jackson version
  • Loading branch information
SMadani authored Nov 29, 2023
1 parent 0f40c78 commit 27f86d1
Show file tree
Hide file tree
Showing 88 changed files with 1,085 additions and 1,275 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

# [8.0.0] - 2023-11-??
- Added `redirect_url` parameter to `SilentAuthWorkflow`
- Bumped Jackson version to 2.16.0

# [8.0.0-rc2] - 2023-11-07
- Removed packages:
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repositories {
}

dependencies {
def jacksonVersion = '2.15.3'
def jacksonVersion = '2.16.0'
def httpclientVersion = '4.5.14'
def junitVersion = '5.10.1'

Expand All @@ -36,7 +36,6 @@ dependencies {
implementation "com.vonage:jwt:1.1.0"

testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.vintage:junit-vintage-engine:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation "org.mockito:mockito-inline:4.11.0"
testImplementation "jakarta.servlet:jakarta.servlet-api:4.0.4"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/auth/TokenAuthMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* This AuthMethod uses API key and secret either as URL parameters, or as
* <code>Basic</code> in the header.
* {@code Basic} in the header.
*/
public class TokenAuthMethod implements AuthMethod {
private static final int SORT_KEY = 30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void uploadLogo(Path logoFile, LogoUploadsUrlResponse details) {
try {
LogoUploadsUrlResponse.Fields fields = details.getFields();
HttpEntity entity = MultipartEntityBuilder.create()
.addTextBody("Content-Type", fields.getContentType().toString())
.addTextBody("Content-Type", fields.getContentType())
.addTextBody("key", fields.getKey())
.addTextBody("logoType", fields.getLogoType().toString())
.addTextBody("bucket", fields.getBucket())
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/com/vonage/client/video/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.vonage.client.Jsonable;
import java.net.URI;
import java.time.Duration;

Expand Down Expand Up @@ -159,13 +157,7 @@ public String getMultiArchiveTag() {
* @return An instance of this class with the fields populated, if present.
*/
public static Archive fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, Archive.class);
}
catch (IOException ex) {
throw new VonageUnexpectedException("Failed to produce Archive from json.", ex);
}
return Jsonable.fromJson(json);
}


Expand Down
17 changes: 6 additions & 11 deletions src/main/java/com/vonage/client/video/Broadcast.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.vonage.client.Jsonable;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
* Represents properties of a live streaming broadcast.
Expand Down Expand Up @@ -174,13 +175,7 @@ public Hls getHlsSettings() {
* @return An instance of this class with the fields populated, if present.
*/
public static Broadcast fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, Broadcast.class);
}
catch (IOException ex) {
throw new VonageUnexpectedException("Failed to produce Broadcast from json.", ex);
}
return Jsonable.fromJson(json);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/vonage/client/video/BroadcastUrls.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vonage.client.video;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URI;
Expand Down Expand Up @@ -51,7 +50,7 @@ public URI getHls() {
*
* @return Details of the RTMP streams.
*/
@JsonIgnore
@JsonProperty("rtmp")
public List<Rtmp> getRtmps() {
return rtmp;
}
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/vonage/client/video/CreateSessionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
*/
package com.vonage.client.video;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.vonage.client.QueryParamsRequest;
import org.apache.http.client.methods.RequestBuilder;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* Defines the properties used to create a new video session.
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class CreateSessionRequest {
public class CreateSessionRequest implements QueryParamsRequest {
private final InetAddress location;
private final MediaMode mediaMode;
private final ArchiveMode archiveMode;
Expand All @@ -38,16 +39,24 @@ private CreateSessionRequest(Builder builder) {
}
}

void addParams(RequestBuilder request) {
@Override
public Map<String, String> makeParams() {
Map<String, String> params = new LinkedHashMap<>(4);
if (location != null) {
request.addParameter("location", location.getHostAddress());
params.put("location", location.getHostAddress());
}
if (mediaMode != null) {
request.addParameter("p2p.preference", mediaMode.toString());
params.put("p2p.preference", mediaMode.toString());
}
if (archiveMode != null) {
request.addParameter("archiveMode", getArchiveMode().toString());
params.put("archiveMode", getArchiveMode().toString());
}
return params;
}

@Deprecated
void addParams(RequestBuilder request) {
makeParams().forEach(request::addParameter);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import com.vonage.client.Jsonable;
import com.vonage.client.VonageResponseParseException;
import java.io.IOException;
import java.net.URI;
import java.util.UUID;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CreateSessionResponse {
public class CreateSessionResponse implements Jsonable {
private String sessionId, createDt;
private UUID applicationId;
private URI mediaServerUrl;
Expand Down Expand Up @@ -80,7 +81,7 @@ public static CreateSessionResponse fromJson(String json) {
return array[0];
}
catch (IOException ex) {
throw new VonageUnexpectedException("Failed to produce CreateSessionResponse from json.", ex);
throw new VonageResponseParseException("Failed to produce CreateSessionResponse from json.", ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.http.util.EntityUtils;
import java.io.IOException;

class ForceDisconnectEndpoint extends AbstractMethod<ForceDisconnectRequestWrapper, Void> {
class ForceDisconnectEndpoint extends AbstractMethod<SessionResourceRequestWrapper, Void> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {JWTAuthMethod.class};
private static final String PATH = "/v2/project/%s/session/%s/connection/%s";

Expand All @@ -38,8 +38,8 @@ protected Class<?>[] getAcceptableAuthMethods() {
}

@Override
public RequestBuilder makeRequest(ForceDisconnectRequestWrapper wrapper) {
String path = String.format(PATH, getApplicationIdOrApiKey(), wrapper.sessionId, wrapper.connectionId);
public RequestBuilder makeRequest(SessionResourceRequestWrapper wrapper) {
String path = String.format(PATH, getApplicationIdOrApiKey(), wrapper.sessionId, wrapper.resourceId);
String uri = httpWrapper.getHttpConfig().getVideoBaseUri() + path;
return RequestBuilder.delete(uri);
}
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/java/com/vonage/client/video/GetStreamEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.http.client.methods.RequestBuilder;
import java.io.IOException;

class GetStreamEndpoint extends AbstractMethod<GetStreamRequestWrapper, GetStreamResponse> {
class GetStreamEndpoint extends AbstractMethod<SessionResourceRequestWrapper, GetStreamResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {JWTAuthMethod.class};
private static final String PATH = "/v2/project/%s/session/%s/stream/%s";

Expand All @@ -36,8 +36,8 @@ protected Class<?>[] getAcceptableAuthMethods() {
}

@Override
public RequestBuilder makeRequest(GetStreamRequestWrapper request) {
String path = String.format(PATH, getApplicationIdOrApiKey(), request.sessionId, request.streamId);
public RequestBuilder makeRequest(SessionResourceRequestWrapper request) {
String path = String.format(PATH, getApplicationIdOrApiKey(), request.sessionId, request.resourceId);
String uri = httpWrapper.getHttpConfig().getVideoBaseUri() + path;
return RequestBuilder.get(uri).setHeader("Accept", "application/json");
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/com/vonage/client/video/GetStreamResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package com.vonage.client.video;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;

/**
* Represents details of a stream, as returned from {@link VideoClient#getStream(String, String)}.
Expand All @@ -34,13 +33,15 @@ protected GetStreamResponse() {
/**
* @return The video source for the stream.
*/
@JsonProperty("videoType")
public VideoType getVideoType() {
return videoType;
}

/**
* @return The name of the stream (if one was set when the client published the stream).
*/
@JsonProperty("name")
public String getName() {
return name;
}
Expand All @@ -52,12 +53,6 @@ public String getName() {
* @return An instance of this class with the fields populated, if present.
*/
public static GetStreamResponse fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, GetStreamResponse.class);
}
catch (IOException ex) {
throw new VonageUnexpectedException("Failed to produce GetStreamResponse from json.", ex);
}
return Jsonable.fromJson(json);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/vonage/client/video/Hls.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/
package com.vonage.client.video;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents HTTP Live Streaming (HLS) options for a {@link Broadcast}.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Hls {
private Boolean dvr, lowLatency;

Expand Down
25 changes: 7 additions & 18 deletions src/main/java/com/vonage/client/video/ListArchivesResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,29 @@
package com.vonage.client.video;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
class ListArchivesResponse {
class ListArchivesResponse implements Jsonable {
private Integer count;
private List<Archive> items;

protected ListArchivesResponse() {
}

@JsonProperty("count")
public Integer getCount() {
return count;
}

@JsonProperty("items")
public List<Archive> getItems() {
return items;
}

/**
* Creates an instance of this class from a JSON payload.
*
* @param json The JSON string to parse.
* @return An instance of this class with the fields populated, if present.
*/

public static ListArchivesResponse fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, ListArchivesResponse.class);
}
catch (IOException ex) {
throw new VonageUnexpectedException("Failed to produce ListArchivesResponse from json.", ex);
}
return Jsonable.fromJson(json);
}
}
Loading

0 comments on commit 27f86d1

Please sign in to comment.