33
44import java .util .Map ;
55
6+
67/**
78 * Responsible for sending GET requests to YouTube.
89 */
@@ -13,7 +14,9 @@ public interface YoutubeClient {
1314 *
1415 * @param url The URL to which the GET request is made.
1516 * @param headers A map of additional headers to include in the request.
17+ *
1618 * @return The body of the response as a {@link String}.
19+ *
1720 * @throws TranscriptRetrievalException If the request to YouTube fails.
1821 */
1922 String get (String url , Map <String , String > headers ) throws TranscriptRetrievalException ;
@@ -24,9 +27,31 @@ public interface YoutubeClient {
2427 *
2528 * @param endpoint The endpoint to which the GET request is made.
2629 * @param params A map of parameters to include in the request.
30+ *
2731 * @return The body of the response as a {@link String}.
32+ *
2833 * @throws TranscriptRetrievalException If the request to YouTube fails.
2934 */
3035 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+ }
3156}
3257
0 commit comments