@@ -54,6 +54,7 @@ public class GitLabApiClient {
5454
5555 private ClientConfig clientConfig ;
5656 private Client apiClient ;
57+ private String baseUrl ;
5758 private String hostUrl ;
5859 private TokenType tokenType = TokenType .PRIVATE ;
5960 private String authToken ;
@@ -91,7 +92,7 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenTyp
9192 /**
9293 * Construct an instance to communicate with a GitLab API server using GitLab API version 4, and the specified
9394 * server URL, private token, and secret token.
94- *
95+ *
9596 * @param hostUrl the URL to the GitLab API server
9697 * @param privateToken the private token to authenticate with
9798 */
@@ -102,7 +103,7 @@ public GitLabApiClient(String hostUrl, String privateToken) {
102103 /**
103104 * Construct an instance to communicate with a GitLab API server using GitLab API version 4, and the specified
104105 * server URL, private token, and secret token.
105- *
106+ *
106107 * @param hostUrl the URL to the GitLab API server
107108 * @param tokenType the type of auth the token is for, PRIVATE or ACCESS
108109 * @param authToken the token to authenticate with
@@ -141,7 +142,7 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenTyp
141142 /**
142143 * Construct an instance to communicate with a GitLab API server using GitLab API version 4, and the specified
143144 * server URL, private token, and secret token.
144- *
145+ *
145146 * @param hostUrl the URL to the GitLab API server
146147 * @param privateToken the private token to authenticate with
147148 * @param secretToken use this token to validate received payloads
@@ -153,7 +154,7 @@ public GitLabApiClient(String hostUrl, String privateToken, String secretToken)
153154 /**
154155 * Construct an instance to communicate with a GitLab API server using GitLab API version 4, and the specified
155156 * server URL, private token, and secret token.
156- *
157+ *
157158 * @param hostUrl the URL to the GitLab API server
158159 * @param tokenType the type of auth the token is for, PRIVATE or ACCESS
159160 * @param authToken the token to authenticate with
@@ -166,7 +167,7 @@ public GitLabApiClient(String hostUrl, TokenType tokenType, String authToken, St
166167 /**
167168 * Construct an instance to communicate with a GitLab API server using GitLab API version 4, and the specified
168169 * server URL and private token.
169- *
170+ *
170171 * @param hostUrl the URL to the GitLab API server
171172 * @param privateToken the private token to authenticate with
172173 * @param secretToken use this token to validate received payloads
@@ -177,7 +178,7 @@ public GitLabApiClient(String hostUrl, String privateToken, String secretToken,
177178 }
178179
179180 /**
180- * Construct an instance to communicate with a GitLab API server using the specified GitLab API version,
181+ * Construct an instance to communicate with a GitLab API server using the specified GitLab API version,
181182 * server URL and private token.
182183 *
183184 * @param apiVersion the ApiVersion specifying which version of the API to use
@@ -191,7 +192,7 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, String privateToke
191192 }
192193
193194 /**
194- * Construct an instance to communicate with a GitLab API server using the specified GitLab API version,
195+ * Construct an instance to communicate with a GitLab API server using the specified GitLab API version,
195196 * server URL and private token.
196197 *
197198 * @param apiVersion the ApiVersion specifying which version of the API to use
@@ -205,6 +206,7 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenTyp
205206
206207 // Remove the trailing "/" from the hostUrl if present
207208 this .hostUrl = (hostUrl .endsWith ("/" ) ? hostUrl .replaceAll ("/$" , "" ) : hostUrl );
209+ this .baseUrl = this .hostUrl ;
208210 if (ApiVersion .OAUTH2_CLIENT != apiVersion ) {
209211 this .hostUrl += apiVersion .getApiNamespace ();
210212 }
@@ -265,7 +267,6 @@ TokenType getTokenType() {
265267 /**
266268 * Set the ID of the user to sudo as.
267269 *
268- * @param sudoAsId the ID of the user to sudo as
269270 */
270271 Integer getSudoAsId () {
271272 return (sudoAsId );
@@ -282,29 +283,44 @@ void setSudoAsId(Integer sudoAsId) {
282283
283284 /**
284285 * Construct a REST URL with the specified path arguments.
285- *
286+ *
286287 * @param pathArgs variable list of arguments used to build the URI
287288 * @return a REST URL with the specified path arguments
288289 * @throws IOException if an error occurs while constructing the URL
289290 */
290291 protected URL getApiUrl (Object ... pathArgs ) throws IOException {
292+ String url = appendPathArgs (this .hostUrl , pathArgs );
293+ return (new URL (url ));
294+ }
295+
296+ /**
297+ * Construct a REST URL with the specified path arguments using
298+ * Gitlab base url.
299+ *
300+ * @param pathArgs variable list of arguments used to build the URI
301+ * @return a REST URL with the specified path arguments
302+ * @throws IOException if an error occurs while constructing the URL
303+ */
304+ protected URL getUrlWithBase (Object ... pathArgs ) throws IOException {
305+ String url = appendPathArgs (this .baseUrl , pathArgs );
306+ return (new URL (url ));
307+ }
291308
292- StringBuilder url = new StringBuilder ();
293- url . append ( hostUrl );
309+ private String appendPathArgs ( String url , Object ... pathArgs ) {
310+ StringBuilder urlBuilder = new StringBuilder ( url );
294311 for (Object pathArg : pathArgs ) {
295312 if (pathArg != null ) {
296- url .append ("/" );
297- url .append (pathArg .toString ());
313+ urlBuilder .append ("/" );
314+ urlBuilder .append (pathArg .toString ());
298315 }
299316 }
300-
301- return (new URL (url .toString ()));
317+ return urlBuilder .toString ();
302318 }
303319
304320 /**
305321 * Validates the secret token (X-GitLab-Token) header against the expected secret token, returns true if valid,
306322 * otherwise returns false.
307- *
323+ *
308324 * @param response the Response instance sent from the GitLab server
309325 * @return true if the response's secret token is valid, otherwise returns false
310326 */
@@ -323,7 +339,7 @@ protected boolean validateSecretToken(Response response) {
323339 /**
324340 * Perform an HTTP GET call with the specified query parameters and path objects, returning
325341 * a ClientResponse instance with the data returned from the endpoint.
326- *
342+ *
327343 * @param queryParams multivalue map of request parameters
328344 * @param pathArgs variable list of arguments used to build the URI
329345 * @return a ClientResponse instance with the data returned from the endpoint
@@ -337,7 +353,7 @@ protected Response get(MultivaluedMap<String, String> queryParams, Object... pat
337353 /**
338354 * Perform an HTTP GET call with the specified query parameters and URL, returning
339355 * a ClientResponse instance with the data returned from the endpoint.
340- *
356+ *
341357 * @param queryParams multivalue map of request parameters
342358 * @param url the fully formed path to the GitLab API endpoint
343359 * @return a ClientResponse instance with the data returned from the endpoint
@@ -349,7 +365,7 @@ protected Response get(MultivaluedMap<String, String> queryParams, URL url) {
349365 /**
350366 * Perform an HTTP GET call with the specified query parameters and path objects, returning
351367 * a ClientResponse instance with the data returned from the endpoint.
352- *
368+ *
353369 * @param queryParams multivalue map of request parameters
354370 * @param accepts if non-empty will set the Accepts header to this value
355371 * @param pathArgs variable list of arguments used to build the URI
@@ -364,7 +380,7 @@ protected Response getWithAccepts(MultivaluedMap<String, String> queryParams, St
364380 /**
365381 * Perform an HTTP GET call with the specified query parameters and URL, returning
366382 * a ClientResponse instance with the data returned from the endpoint.
367- *
383+ *
368384 * @param queryParams multivalue map of request parameters
369385 * @param url the fully formed path to the GitLab API endpoint
370386 * @param accepts if non-empty will set the Accepts header to this value
@@ -377,7 +393,7 @@ protected Response getWithAccepts(MultivaluedMap<String, String> queryParams, UR
377393 /**
378394 * Perform an HTTP POST call with the specified form data and path objects, returning
379395 * a ClientResponse instance with the data returned from the endpoint.
380- *
396+ *
381397 * @param formData the Form containing the name/value pairs
382398 * @param pathArgs variable list of arguments used to build the URI
383399 * @return a ClientResponse instance with the data returned from the endpoint
@@ -391,7 +407,7 @@ protected Response post(Form formData, Object... pathArgs) throws IOException {
391407 /**
392408 * Perform an HTTP POST call with the specified form data and path objects, returning
393409 * a ClientResponse instance with the data returned from the endpoint.
394- *
410+ *
395411 * @param queryParams multivalue map of request parameters
396412 * @param pathArgs variable list of arguments used to build the URI
397413 * @return a Response instance with the data returned from the endpoint
@@ -405,7 +421,7 @@ protected Response post(MultivaluedMap<String, String> queryParams, Object... pa
405421 /**
406422 * Perform an HTTP POST call with the specified form data and URL, returning
407423 * a ClientResponse instance with the data returned from the endpoint.
408- *
424+ *
409425 * @param formData the Form containing the name/value pairs
410426 * @param url the fully formed path to the GitLab API endpoint
411427 * @return a ClientResponse instance with the data returned from the endpoint
@@ -501,7 +517,7 @@ protected Response upload(String name, File fileToUpload, String mediaTypeString
501517 /**
502518 * Perform an HTTP PUT call with the specified form data and path objects, returning
503519 * a ClientResponse instance with the data returned from the endpoint.
504- *
520+ *
505521 * @param queryParams multivalue map of request parameters
506522 * @param pathArgs variable list of arguments used to build the URI
507523 * @return a ClientResponse instance with the data returned from the endpoint
@@ -561,7 +577,7 @@ protected Response put(Form formData, URL url) {
561577 /**
562578 * Perform an HTTP DELETE call with the specified form data and path objects, returning
563579 * a Response instance with the data returned from the endpoint.
564- *
580+ *
565581 * @param queryParams multivalue map of request parameters
566582 * @param pathArgs variable list of arguments used to build the URI
567583 * @return a Response instance with the data returned from the endpoint
@@ -574,7 +590,7 @@ protected Response delete(MultivaluedMap<String, String> queryParams, Object...
574590 /**
575591 * Perform an HTTP DELETE call with the specified form data and URL, returning
576592 * a Response instance with the data returned from the endpoint.
577- *
593+ *
578594 * @param queryParams multivalue map of request parameters
579595 * @param url the fully formed path to the GitLab API endpoint
580596 * @return a Response instance with the data returned from the endpoint
0 commit comments