From a42bc84e33cc5262974946b6cb1b9586a7dc3f2d Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Fri, 14 Apr 2017 19:17:59 -0700 Subject: [PATCH] Added support for /namespaces calls. --- README.md | 9 +++- .../java/org/gitlab4j/api/NamespaceApi.java | 47 +++++++++++-------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index f8dc5341..8a1b6bf9 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Available Sub APIs CommitsApi GroupApi MergeRequestApi +NamespaceApi ProjectApi RepositoryApi RepositoryFileApi @@ -70,7 +71,13 @@ List groups = gitLabApi.getGroupApi().getGroups(); MergeRequestApi: ```java // Get a list of the merge requests for the specified project - List mregeRequests = gitLabApi.getMergeRequestApi().getMergeRequests(1234); + List mergeRequests = gitLabApi.getMergeRequestApi().getMergeRequests(1234); +``` + +NamespaceApi: +```java +// Get all namespaces that match "foobar" in their name or path + List namespaces = gitLabApi.getNamespaceApi().findNamespaces("foobar"); ``` ProjectApi: diff --git a/src/main/java/org/gitlab4j/api/NamespaceApi.java b/src/main/java/org/gitlab4j/api/NamespaceApi.java index 6cd6a599..3162ff4b 100644 --- a/src/main/java/org/gitlab4j/api/NamespaceApi.java +++ b/src/main/java/org/gitlab4j/api/NamespaceApi.java @@ -1,9 +1,11 @@ package org.gitlab4j.api; -import javax.ws.rs.core.Form; +import java.util.List; + +import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; -import org.gitlab4j.api.models.Session; +import org.gitlab4j.api.models.Namespace; /** * This class implements the client side API for the GitLab namespace calls. @@ -15,28 +17,33 @@ public class NamespaceApi extends AbstractApi { } /** - * Login to get private token. + * Get a list of the namespaces of the authenticated user. If the user is an administrator, + * a list of all namespaces in the GitLab instance is shown. * - * POST /session + * GET /namespaces * - * @param username the username to login - * @param email the email address to login - * @param password the password of the user - * @return a Session instance with info on the logged in user + * @return a List of Namespace instances * @throws GitLabApiException if any exception occurs */ - public Session login(String username, String email, String password) throws GitLabApiException { - - if ((username == null || username.trim().length() == 0) && (email == null || email.trim().length() == 0)) { - throw new IllegalArgumentException("both username and email cannot be empty or null"); - } - - Form formData = new Form(); - addFormParam(formData, "email", email, false); - addFormParam(formData, "password", password, true); - addFormParam(formData, "login", username, false); + public List getNamespaces() throws GitLabApiException { + Response response = get(Response.Status.OK, null, "namespaces"); + return (response.readEntity(new GenericType>() { + })); + } - Response response = post(Response.Status.CREATED, formData, "session"); - return (response.readEntity(Session.class)); + /** + * Get all namespaces that match a string in their name or path. + * + * GET /namespaces?search=:query + * + * @param query the search string + * @return the Namespace List with the matching namespaces + * @throws GitLabApiException if any exception occurs + */ + public List findNamespaces(String query) throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm().withParam("search", query, true); + Response response = get(Response.Status.OK, formData.asMap(), "namespaces"); + return (response.readEntity(new GenericType>() { + })); } } -- GitLab