Skip to content

Commit 866f9a7

Browse files
Add remaining clients (#20)
* 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>
1 parent 7897f67 commit 866f9a7

20 files changed

+1452
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.1.0
2+
3+
* Add V2 Clients for Text tracks, Tags, Usage, Player Bidding Configs, Originals, Media Renditions, Thumbnails.
4+
* Update Playlists client to include watchlist.
5+
16
## 1.0.0
27

38
* Add the following V2 clients-

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<maven.compiler.source>1.8</maven.compiler.source>
8282
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
8383
<!-- dependencies versions -->
84-
<guava.version>28.1-jre</guava.version>
84+
<guava.version>29.0-jre</guava.version>
8585
<commons-lang3.version>3.9</commons-lang3.version>
8686
<unirest.version>1.4.9</unirest.version>
8787
<!-- test dependencies versions -->
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.jwplayer.jwplatform.client;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.json.JSONObject;
7+
8+
import com.google.common.base.Preconditions;
9+
import com.jwplayer.jwplatform.exception.JWPlatformException;
10+
import com.jwplayer.jwplatform.rest.HttpCalls;
11+
12+
/**
13+
* JW Platform MediaRendition API client.
14+
*
15+
* <p>
16+
* An API client for the JW Platform MediaRendition API. For the API documentation
17+
* see: <a href=
18+
* "https://developer.jwplayer.com/jwplayer/reference#introduction-to-api-v2">Introduction
19+
* to api v2</a>
20+
*
21+
* <p>
22+
* Example: MediaRenditionClient client = MediaRenditionClient.getClient(secret);
23+
*/
24+
public class MediaRenditionClient extends JWPlatformClientV2 {
25+
26+
private String path;
27+
private final String secret;
28+
29+
/**
30+
* Instantiate a new {@code MediaRenditionClient} instance.
31+
*
32+
* @param secret - your api secret
33+
*/
34+
private MediaRenditionClient(String secret) {
35+
this.secret = secret;
36+
this.path = "https://api.jwplayer.com/v2/sites/%s/media/%s/media_renditions/";
37+
headers = new HashMap<>();
38+
headers.put("Authorization", "Bearer " + this.secret);
39+
headers.put("accept", "application/json");
40+
headers.put("Content-Type", "application/json");
41+
}
42+
43+
/**
44+
* see {@link #MediaRenditionClient(String)}.
45+
*/
46+
public static MediaRenditionClient getClient(String secret) {
47+
Preconditions.checkNotNull(secret, "API Secret must not be null!");
48+
return new MediaRenditionClient(secret);
49+
}
50+
51+
/**
52+
*
53+
* @param siteId - PropertyID
54+
* @param mediaId - PropertyID
55+
* @param params - Parameters to be included in the request
56+
* @return JSON response from Media API
57+
* @throws JWPlatformException See <a href=
58+
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-media-renditions">List Renditions</a>
59+
*/
60+
public JSONObject listMediaRenditions(String siteId, String mediaId, Map<String, String> params) throws JWPlatformException {
61+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
62+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
63+
this.path = String.format(this.path, siteId, mediaId);
64+
return HttpCalls.request(this.path, params, false, "GET", headers);
65+
}
66+
67+
/**
68+
*
69+
* @param siteId - PropertyID
70+
* @param mediaId - Unique identifier for a resource
71+
* @param bodyParams - Parameters to be included in the request body
72+
* @return JSON response from Media API
73+
* @throws JWPlatformException See <a href=
74+
* "https://developer.jwplayer.com/jwplayer/reference/post_v2-sites-site-id-media-media-id-media-renditions">Create Rendition</a>
75+
*/
76+
public JSONObject createRendition(String siteId, String mediaId,Map<String, String> bodyParams) throws JWPlatformException {
77+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
78+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
79+
this.path = String.format(this.path, siteId, mediaId);
80+
final boolean isBodyParams = bodyParams.size() > 0;
81+
return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers);
82+
}
83+
84+
/**
85+
*
86+
* @param siteId - PropertyID
87+
* @param mediaId - Unique identifier for a resource
88+
* @param renditionId - Unique identifier for a rendition
89+
* @param params - Parameters to be included in the request
90+
* @return JSON response from Media API
91+
* @throws JWPlatformException See <a href=
92+
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-media-renditions-rendition-id-">Get Rendition By ID</a>
93+
*/
94+
public JSONObject getRenditionById(String siteId, String mediaId, String renditionId, Map<String, String> params)
95+
throws JWPlatformException {
96+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
97+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
98+
Preconditions.checkNotNull(renditionId, "Rendition ID must not be null!");
99+
this.path = String.format(this.path, siteId, mediaId)+renditionId+"/";
100+
return HttpCalls.request(this.path, params, false, "GET", headers);
101+
}
102+
103+
/**
104+
*
105+
* @param siteId - PropertyID
106+
* @param mediaId - Unique identifier for a resource
107+
* @param renditionId - Unique identifier for a rendition
108+
* @return JSON response from Media API
109+
* @throws JWPlatformException See <a href=
110+
* "https://developer.jwplayer.com/jwplayer/reference/delete_v2-sites-site-id-media-media-id-media-renditions-rendition-id-">Delete Rendition</a>
111+
*/
112+
public JSONObject deleteRendition(String siteId, String mediaId, String renditionId) throws JWPlatformException {
113+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
114+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
115+
Preconditions.checkNotNull(renditionId, "Rendition ID must not be null!");
116+
this.path = String.format(this.path, siteId, mediaId)+renditionId+"/";
117+
return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers);
118+
}
119+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package com.jwplayer.jwplatform.client;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.json.JSONObject;
7+
8+
import com.google.common.base.Preconditions;
9+
import com.jwplayer.jwplatform.exception.JWPlatformException;
10+
import com.jwplayer.jwplatform.rest.HttpCalls;
11+
12+
/**
13+
* JW Platform Original API client.
14+
*
15+
* <p>
16+
* An API client for the JW Platform Original API. For the API documentation
17+
* see: <a href=
18+
* "https://developer.jwplayer.com/jwplayer/reference#introduction-to-api-v2">Introduction
19+
* to api v2</a>
20+
*
21+
* <p>
22+
* Example: OriginalClient client = OriginalClient.getClient(secret);
23+
*/
24+
public class OriginalClient extends JWPlatformClientV2 {
25+
26+
private String path;
27+
private final String secret;
28+
29+
/**
30+
* Instantiate a new {@code OriginalClient} instance.
31+
*
32+
* @param secret - your api secret
33+
*/
34+
private OriginalClient(String secret) {
35+
this.secret = secret;
36+
this.path = "https://api.jwplayer.com/v2/sites/%s/media/%s/originals/";
37+
headers = new HashMap<>();
38+
headers.put("Authorization", "Bearer " + this.secret);
39+
headers.put("accept", "application/json");
40+
headers.put("Content-Type", "application/json");
41+
}
42+
43+
/**
44+
* see {@link #OriginalClient(String)}.
45+
*/
46+
public static OriginalClient getClient(String secret) {
47+
Preconditions.checkNotNull(secret, "API Secret must not be null!");
48+
return new OriginalClient(secret);
49+
}
50+
51+
/**
52+
*
53+
* @param siteId - PropertyID
54+
* @param mediaId - PropertyID
55+
* @param params - Parameters to be included in the request
56+
* @return JSON response from Media API
57+
* @throws JWPlatformException See <a href=
58+
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-originals">List Originals</a>
59+
*/
60+
public JSONObject listOriginals(String siteId, String mediaId, Map<String, String> params) throws JWPlatformException {
61+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
62+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
63+
this.path = String.format(this.path, siteId, mediaId);
64+
return HttpCalls.request(this.path, params, false, "GET", headers);
65+
}
66+
67+
/**
68+
*
69+
* @param siteId - PropertyID
70+
* @param mediaId - Unique identifier for a resource
71+
* @param bodyParams - Parameters to be included in the request body
72+
* @return JSON response from Media API
73+
* @throws JWPlatformException See <a href=
74+
* "https://developer.jwplayer.com/jwplayer/reference/post_v2-sites-site-id-media-media-id-originals">Create Originals</a>
75+
*/
76+
public JSONObject createOriginals(String siteId, String mediaId,Map<String, String> bodyParams) throws JWPlatformException {
77+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
78+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
79+
this.path = String.format(this.path, siteId, mediaId);
80+
final boolean isBodyParams = bodyParams.size() > 0;
81+
return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers);
82+
}
83+
84+
/**
85+
*
86+
* @param siteId - PropertyID
87+
* @param mediaId - Unique identifier for a resource
88+
* @param originalId - Unique identifier for a rendition
89+
* @param params - Parameters to be included in the request
90+
* @return JSON response from Media API
91+
* @throws JWPlatformException See <a href=
92+
* "https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-media-media-id-originals-original-id-">Get Original By ID</a>
93+
*/
94+
public JSONObject getOriginalById(String siteId, String mediaId, String originalId, Map<String, String> params)
95+
throws JWPlatformException {
96+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
97+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
98+
Preconditions.checkNotNull(originalId, "Original ID must not be null!");
99+
this.path = String.format(this.path, siteId, mediaId)+ originalId + "/";
100+
return HttpCalls.request(this.path, params, false, "GET", headers);
101+
}
102+
103+
/**
104+
*
105+
* @param siteId - PropertyID
106+
* @param mediaId - Unique identifier for a resource
107+
* @param originalId - Unique identifier for an original
108+
* @param bodyParams - Parameters to be included in the request body
109+
* @return JSON response from Media API
110+
* @throws JWPlatformException See <a href=
111+
* "https://developer.jwplayer.com/jwplayer/reference/patch_v2-sites-site-id-media-media-id-originals-original-id-">Update Original</a>
112+
*/
113+
public JSONObject updateOriginal(String siteId, String mediaId, String originalId, Map<String, String> bodyParams)
114+
throws JWPlatformException {
115+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
116+
Preconditions.checkNotNull(mediaId, "Config ID must not be null!");
117+
this.path = String.format(this.path, siteId, mediaId) + originalId + "/";
118+
final boolean isBodyParams = bodyParams.size() > 0;
119+
return HttpCalls.request(this.path, bodyParams, isBodyParams, "PATCH", headers);
120+
}
121+
122+
/**
123+
*
124+
* @param siteId - PropertyID
125+
* @param mediaId - Unique identifier for a resource
126+
* @param originalId - Unique identifier for a rendition
127+
* @return JSON response from Media API
128+
* @throws JWPlatformException See <a href=
129+
* "https://developer.jwplayer.com/jwplayer/reference/delete_v2-sites-site-id-media-media-id-originals-original-id-">Delete Rendition</a>
130+
*/
131+
public JSONObject deleteOriginal(String siteId, String mediaId, String originalId) throws JWPlatformException {
132+
Preconditions.checkNotNull(siteId, "Site ID must not be null!");
133+
Preconditions.checkNotNull(mediaId, "Media ID must not be null!");
134+
Preconditions.checkNotNull(originalId, "Original ID must not be null!");
135+
this.path = String.format(this.path, siteId, mediaId) + originalId + "/";
136+
return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers);
137+
}
138+
139+
}

0 commit comments

Comments
 (0)