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