package org.gitlab4j.api; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; import org.gitlab4j.api.models.Application; /** * This class implements the client side API for the GitLab Applications API. * See Applications API at GitLab for more information. */ public class ApplicationsApi extends AbstractApi { public ApplicationsApi(GitLabApi gitLabApi) { super(gitLabApi); } /** * Get all OATH applications. * *
GitLab Endpoint: GET /api/v4/applications
* * @return a List of OAUTH Application instances * @throws GitLabApiException if any exception occurs */ public List getApplications() throws GitLabApiException { return (getApplications(getDefaultPerPage()).all()); } /** * Get all OAUTH applications using the specified page and per page setting * *
GitLab Endpoint: GET /api/v4/applications
* * @param page the page to get * @param perPage the number of items per page * @return a list of OAUTH Applications in the specified range * @throws GitLabApiException if any exception occurs */ public List getApplications(int page, int perPage) throws GitLabApiException { Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage), "applications"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of all OAUTH applications. * *
GitLab Endpoint: GET /api/v4/applications
* * @param itemsPerPage the number of items per page * @return a Pager of Application instances in the specified range * @throws GitLabApiException if any exception occurs */ public Pager getApplications(int itemsPerPage) throws GitLabApiException { return (new Pager(this, Application.class, itemsPerPage, null, "applications")); } /** * Get a Stream of all OAUTH Application instances. * *
GitLab Endpoint: GET /api/v4/applications
* * @return a Stream of OAUTH Application instances * @throws GitLabApiException if any exception occurs */ public Stream getApplicationsStream() throws GitLabApiException { return (getApplications(getDefaultPerPage()).stream()); } /** * Create an OAUTH Application. * *
GitLab Endpoint: POST /api/v4/applications
* * @param name the name for the OAUTH Application * @param redirectUri the redirect URI for the OAUTH Application * @param scopes the scopes of the application (api, read_user, sudo, read_repository, openid, profile, email) * @return the created Application instance * @throws GitLabApiException if any exception occurs */ public Application createApplication(String name, String redirectUri, ApplicationScope[] scopes) throws GitLabApiException { if (scopes == null || scopes.length == 0) { throw new GitLabApiException("scopes cannot be null or empty"); } return (createApplication(name, redirectUri, Arrays.asList(scopes))); } /** * Create an OAUTH Application. * *
GitLab Endpoint: POST /api/v4/applications
* * @param name the name for the OAUTH Application * @param redirectUri the redirect URI for the OAUTH Application * @param scopes the scopes of the application (api, read_user, sudo, read_repository, openid, profile, email) * @return the created Application instance * @throws GitLabApiException if any exception occurs */ public Application createApplication(String name, String redirectUri, List scopes) throws GitLabApiException { if (scopes == null || scopes.isEmpty()) { throw new GitLabApiException("scopes cannot be null or empty"); } String scopesString = scopes.stream().map(ApplicationScope::toString).collect(Collectors.joining(",")); GitLabApiForm formData = new GitLabApiForm() .withParam("name", name, true) .withParam("redirect_uri", redirectUri, true) .withParam("scopes", scopesString, true); Response response = post(Response.Status.CREATED, formData, "applications"); return (response.readEntity(Application.class)); } /** * Delete the specified OAUTH Application. * *
GitLab Endpoint: DELETE /api/v4/applications/:applicationId
* * @param applicationId the ID of the OUAUTH Application to delete * @throws GitLabApiException if any exception occurs */ public void deleteApplication(Integer applicationId) throws GitLabApiException { delete(Response.Status.NO_CONTENT, null, "applications", applicationId); } }