Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.messners.gitlab.api;
  
  import java.net.URL;

This class is the base class for all the sub API classes. It provides implementations of delete(), get(), post() and put() that are re-used by all the sub-classes.

Author(s):
Greg Messner <greg@messners.com>
 
 public abstract class AbstractApi {
 
 	private GitLabApi gitLabApi;
 	
 	public AbstractApi (GitLabApi gitLabApi) {
 		this. = gitLabApi;
 	}
 
 	protected GitLabApiClient getApiClient () {
 		return (.getApiClient());
 	}	


Perform an HTTP GET call with the specified query parameters and path objects, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
queryParams
pathArgs
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
 
 	protected Response get (Response.Status expectedStatusMultivaluedMap<StringStringqueryParamsObject ... pathArgs)
 			throws GitLabApiException {	
 		try {
 			return validate(getApiClient().get(queryParamspathArgs), expectedStatus);
 		} catch (Exception e) {
 			throw handle(e);
 		}
 	}

Perform an HTTP GET call with the specified query parameters and URL, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
queryParams
url
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
 
 	protected Response get (Response.Status expectedStatusMultivaluedMap<StringStringqueryParamsURL url)
 			throws GitLabApiException {		
 		try {
 			return validate(getApiClient().get(queryParamsurl), expectedStatus);
 		} catch (Exception e) {
 			throw handle(e);
 		}	
 	}


Perform an HTTP POST call with the specified form data and path objects, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
formData
pathArgs
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
 
 	protected Response post (Response.Status expectedStatusForm formDataObject ... pathArgsthrows GitLabApiException {
 		try {
 			return validate(getApiClient().post(formDatapathArgs), expectedStatus);
 		} catch (Exception e) {
 			throw handle(e);
 		}
 	}


Perform an HTTP POST call with the specified form data and URL, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
formData
url
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
 
 	protected Response post (Response.Status expectedStatusForm formDataURL urlthrows GitLabApiException {
 		try {
 			return validate(getApiClient().post(formDataurl), expectedStatus);
 		} catch (Exception e) {
			throw handle(e);
		}
	}


Perform an HTTP PUT call with the specified form data and path objects, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
queryParams
pathArgs
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
	protected  Response put (Response.Status expectedStatusMultivaluedMap<StringStringqueryParamsObject ... pathArgsthrows GitLabApiException {
		try {
			return validate(getApiClient().put(queryParamspathArgs), expectedStatus);
catch (Exception e) {
			throw handle(e);
		}
	}


Perform an HTTP PUT call with the specified form data and URL, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
queryParams
url
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
	protected Response put (Response.Status expectedStatusMultivaluedMap<StringStringqueryParamsURL urlthrows GitLabApiException {
		try {
			return validate(getApiClient().put(queryParamsurl), expectedStatus);
catch (Exception e) {
			throw handle(e);
		}	
	}


Perform an HTTP DELETE call with the specified form data and path objects, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
queryParams
pathArgs
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
	protected  Response delete (Response.Status expectedStatusMultivaluedMap<StringStringqueryParamsObject ... pathArgs)
		try {
			return validate(getApiClient().delete(queryParamspathArgs), expectedStatus);
catch (Exception e) {
			throw handle(e);
		}	
	}


Perform an HTTP DELETE call with the specified form data and URL, returning a ClientResponse instance with the data returned from the endpoint.

Parameters:
expectedStatus the HTTP status that should be returned from the server
queryParams
url
Returns:
a ClientResponse instance with the data returned from the endpoint
Throws:
GitLabApiException
	protected Response delete (Response.Status expectedStatusMultivaluedMap<StringStringqueryParamsURL urlthrows GitLabApiException {
		try {
			return validate(getApiClient().delete(queryParamsurl), expectedStatus);
catch (Exception e) {
			throw handle(e);
		}
	}


Convenience method for adding query and form parameters to a get() or post() call.

Parameters:
formData
name
value
	protected void addFormParam(Form formDataString nameObject valuethrows IllegalArgumentException {
		addFormParam(formDatanamevaluefalse);
	}


Convenience method for adding query and form parameters to a get() or post() call. If required is true and value is null, will throw an IllegalArgumentException.

Parameters:
formData
name
value
required
Throws:
java.lang.IllegalArgumentException if a required parameter is null or empty
	protected void addFormParam(Form formDataString nameObject valueboolean requiredthrows IllegalArgumentException {
			if (value == null) {
				if (required) {
					throw new IllegalArgumentException(name + " cannot be empty or null");
				}
				return;
			}
			String stringValue = value.toString().trim();
			if (required && stringValue.length() == 0) {
				throw new IllegalArgumentException(name + " cannot be empty or null");
			}
			formData.param(namestringValue);
	}

Validates response.

Parameters:
response response
expected expected respone status
Returns:
original response if the response status is expected
Throws:
GitLabApiException in case of unexpected response status
	protected Response validate(Response responseResponse.Status expectedthrows GitLabApiException {
		if (response.getStatus() != expected.getStatusCode()) {
			throw new GitLabApiException(response);
		}
		return response;
	}

Wraps exception if needed

Parameters:
thrown exception
Returns:
never returns
Throws:
GitLabApiException always
	protected GitLabApiException handle(Exception thrownthrows GitLabApiException {
		if (thrown instanceof GitLabApiException) { throw (GitLabApiExceptionthrown; }
		throw new GitLabApiException(thrown);
	}
New to GrepCode? Check out our FAQ X