Skip to content

Commit

Permalink
Add remaining clients (#20)
Browse files Browse the repository at this point in the history
* add clients, update vpb client to pb client

* add tests

* fix test name

* modify changelog

* leave vpb as is,add new pb client

* upgrade version, fix javadocs

* fix javadoc

* add all clients

* Update CHANGELOG.md

Co-authored-by: Matt Wisniewski <mwisniewski@jwplayer.com>

Co-authored-by: Matt Wisniewski <mwisniewski@jwplayer.com>
  • Loading branch information
shwetamurthy20 and polishmatt committed Nov 1, 2021
1 parent 7897f67 commit 866f9a7
Show file tree
Hide file tree
Showing 20 changed files with 1,452 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.0

* Add V2 Clients for Text tracks, Tags, Usage, Player Bidding Configs, Originals, Media Renditions, Thumbnails.
* Update Playlists client to include watchlist.

## 1.0.0

* Add the following V2 clients-
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- dependencies versions -->
<guava.version>28.1-jre</guava.version>
<guava.version>29.0-jre</guava.version>
<commons-lang3.version>3.9</commons-lang3.version>
<unirest.version>1.4.9</unirest.version>
<!-- test dependencies versions -->
Expand Down
119 changes: 119 additions & 0 deletions src/main/java/com/jwplayer/jwplatform/client/MediaRenditionClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.jwplayer.jwplatform.client;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.google.common.base.Preconditions;
import com.jwplayer.jwplatform.exception.JWPlatformException;
import com.jwplayer.jwplatform.rest.HttpCalls;

/**
* JW Platform MediaRendition API client.
*
* <p>
* An API client for the JW Platform MediaRendition API. For the API documentation
* see: <a href=
* "https://developer.jwplayer.com/jwplayer/reference#introduction-to-api-v2">Introduction
* to api v2</a>
*
* <p>
* Example: MediaRenditionClient client = MediaRenditionClient.getClient(secret);
*/
public class MediaRenditionClient extends JWPlatformClientV2 {

private String path;
private final String secret;

/**
* Instantiate a new {@code MediaRenditionClient} instance.
*
* @param secret - your api secret
*/
private MediaRenditionClient(String secret) {
this.secret = secret;
this.path = "https://api.jwplayer.com/v2/sites/%s/media/%s/media_renditions/";
headers = new HashMap<>();
headers.put("Authorization", "Bearer " + this.secret);
headers.put("accept", "application/json");
headers.put("Content-Type", "application/json");
}

/**
* see {@link #MediaRenditionClient(String)}.
*/
public static MediaRenditionClient getClient(String secret) {
Preconditions.checkNotNull(secret, "API Secret must not be null!");
return new MediaRenditionClient(secret);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - PropertyID
* @param params - Parameters to be included in the request
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-media-renditions">List Renditions</a>
*/
public JSONObject listMediaRenditions(String siteId, String mediaId, Map<String, String> params) throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
this.path = String.format(this.path, siteId, mediaId);
return HttpCalls.request(this.path, params, false, "GET", headers);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - Unique identifier for a resource
* @param bodyParams - Parameters to be included in the request body
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/post_v2-sites-site-id-media-media-id-media-renditions">Create Rendition</a>
*/
public JSONObject createRendition(String siteId, String mediaId,Map<String, String> bodyParams) throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
this.path = String.format(this.path, siteId, mediaId);
final boolean isBodyParams = bodyParams.size() > 0;
return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - Unique identifier for a resource
* @param renditionId - Unique identifier for a rendition
* @param params - Parameters to be included in the request
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-media-renditions-rendition-id-">Get Rendition By ID</a>
*/
public JSONObject getRenditionById(String siteId, String mediaId, String renditionId, Map<String, String> params)
throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
Preconditions.checkNotNull(renditionId, "Rendition ID must not be null!");
this.path = String.format(this.path, siteId, mediaId)+renditionId+"/";
return HttpCalls.request(this.path, params, false, "GET", headers);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - Unique identifier for a resource
* @param renditionId - Unique identifier for a rendition
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/delete_v2-sites-site-id-media-media-id-media-renditions-rendition-id-">Delete Rendition</a>
*/
public JSONObject deleteRendition(String siteId, String mediaId, String renditionId) throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
Preconditions.checkNotNull(renditionId, "Rendition ID must not be null!");
this.path = String.format(this.path, siteId, mediaId)+renditionId+"/";
return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers);
}
}
139 changes: 139 additions & 0 deletions src/main/java/com/jwplayer/jwplatform/client/OriginalClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.jwplayer.jwplatform.client;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.google.common.base.Preconditions;
import com.jwplayer.jwplatform.exception.JWPlatformException;
import com.jwplayer.jwplatform.rest.HttpCalls;

/**
* JW Platform Original API client.
*
* <p>
* An API client for the JW Platform Original API. For the API documentation
* see: <a href=
* "https://developer.jwplayer.com/jwplayer/reference#introduction-to-api-v2">Introduction
* to api v2</a>
*
* <p>
* Example: OriginalClient client = OriginalClient.getClient(secret);
*/
public class OriginalClient extends JWPlatformClientV2 {

private String path;
private final String secret;

/**
* Instantiate a new {@code OriginalClient} instance.
*
* @param secret - your api secret
*/
private OriginalClient(String secret) {
this.secret = secret;
this.path = "https://api.jwplayer.com/v2/sites/%s/media/%s/originals/";
headers = new HashMap<>();
headers.put("Authorization", "Bearer " + this.secret);
headers.put("accept", "application/json");
headers.put("Content-Type", "application/json");
}

/**
* see {@link #OriginalClient(String)}.
*/
public static OriginalClient getClient(String secret) {
Preconditions.checkNotNull(secret, "API Secret must not be null!");
return new OriginalClient(secret);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - PropertyID
* @param params - Parameters to be included in the request
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-originals">List Originals</a>
*/
public JSONObject listOriginals(String siteId, String mediaId, Map<String, String> params) throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
this.path = String.format(this.path, siteId, mediaId);
return HttpCalls.request(this.path, params, false, "GET", headers);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - Unique identifier for a resource
* @param bodyParams - Parameters to be included in the request body
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/post_v2-sites-site-id-media-media-id-originals">Create Originals</a>
*/
public JSONObject createOriginals(String siteId, String mediaId,Map<String, String> bodyParams) throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
this.path = String.format(this.path, siteId, mediaId);
final boolean isBodyParams = bodyParams.size() > 0;
return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - Unique identifier for a resource
* @param originalId - Unique identifier for a rendition
* @param params - Parameters to be included in the request
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-originals-original-id-">Get Original By ID</a>
*/
public JSONObject getOriginalById(String siteId, String mediaId, String originalId, Map<String, String> params)
throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
Preconditions.checkNotNull(originalId, "Original ID must not be null!");
this.path = String.format(this.path, siteId, mediaId)+ originalId + "/";
return HttpCalls.request(this.path, params, false, "GET", headers);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - Unique identifier for a resource
* @param originalId - Unique identifier for an original
* @param bodyParams - Parameters to be included in the request body
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/patch_v2-sites-site-id-media-media-id-originals-original-id-">Update Original</a>
*/
public JSONObject updateOriginal(String siteId, String mediaId, String originalId, Map<String, String> bodyParams)
throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Config ID must not be null!");
this.path = String.format(this.path, siteId, mediaId) + originalId + "/";
final boolean isBodyParams = bodyParams.size() > 0;
return HttpCalls.request(this.path, bodyParams, isBodyParams, "PATCH", headers);
}

/**
*
* @param siteId - PropertyID
* @param mediaId - Unique identifier for a resource
* @param originalId - Unique identifier for a rendition
* @return JSON response from Media API
* @throws JWPlatformException See <a href=
* "https://developer.jwplayer.com/jwplayer/reference/delete_v2-sites-site-id-media-media-id-originals-original-id-">Delete Rendition</a>
*/
public JSONObject deleteOriginal(String siteId, String mediaId, String originalId) throws JWPlatformException {
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
Preconditions.checkNotNull(originalId, "Original ID must not be null!");
this.path = String.format(this.path, siteId, mediaId) + originalId + "/";
return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers);
}

}
Loading

0 comments on commit 866f9a7

Please sign in to comment.