3
3
4
4
import java .util .Map ;
5
5
6
+
6
7
/**
7
8
* Responsible for sending GET requests to YouTube.
8
9
*/
@@ -13,7 +14,9 @@ public interface YoutubeClient {
13
14
*
14
15
* @param url The URL to which the GET request is made.
15
16
* @param headers A map of additional headers to include in the request.
17
+ *
16
18
* @return The body of the response as a {@link String}.
19
+ *
17
20
* @throws TranscriptRetrievalException If the request to YouTube fails.
18
21
*/
19
22
String get (String url , Map <String , String > headers ) throws TranscriptRetrievalException ;
@@ -24,9 +27,31 @@ public interface YoutubeClient {
24
27
*
25
28
* @param endpoint The endpoint to which the GET request is made.
26
29
* @param params A map of parameters to include in the request.
30
+ *
27
31
* @return The body of the response as a {@link String}.
32
+ *
28
33
* @throws TranscriptRetrievalException If the request to YouTube fails.
29
34
*/
30
35
String get (YtApiV3Endpoint endpoint , Map <String , String > params ) throws TranscriptRetrievalException ;
36
+
37
+
38
+ /**
39
+ * Creates a string representation of the specified parameters.
40
+ *
41
+ * @param params A map of parameters to include in the request.
42
+ *
43
+ * @return A string representation of the specified parameters.
44
+ */
45
+ default String createParamsString (Map <String , String > params ) {
46
+ StringBuilder paramString = new StringBuilder ();
47
+
48
+ for (Map .Entry <String , String > entry : params .entrySet ()) {
49
+ String value = entry .getValue ().replaceAll (" " , "%20" );
50
+ paramString .append (entry .getKey ()).append ("=" ).append (value ).append ("&" );
51
+ }
52
+
53
+ paramString .deleteCharAt (paramString .length () - 1 );
54
+ return paramString .toString ();
55
+ }
31
56
}
32
57
0 commit comments