Commit a42bc84e authored by Greg Messner's avatar Greg Messner
Browse files

Added support for /namespaces calls.

No related merge requests found
Showing with 35 additions and 21 deletions
+35 -21
......@@ -47,6 +47,7 @@ Available Sub APIs
CommitsApi
GroupApi
MergeRequestApi
NamespaceApi
ProjectApi
RepositoryApi
RepositoryFileApi
......@@ -70,7 +71,13 @@ List<Group> groups = gitLabApi.getGroupApi().getGroups();
MergeRequestApi:
```java
// Get a list of the merge requests for the specified project
List<MergeRequest> mregeRequests = gitLabApi.getMergeRequestApi().getMergeRequests(1234);
List<MergeRequest> mergeRequests = gitLabApi.getMergeRequestApi().getMergeRequests(1234);
```
NamespaceApi:
```java
// Get all namespaces that match "foobar" in their name or path
List<Namespace> namespaces = gitLabApi.getNamespaceApi().findNamespaces("foobar");
```
ProjectApi:
......
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<Namespace> getNamespaces() throws GitLabApiException {
Response response = get(Response.Status.OK, null, "namespaces");
return (response.readEntity(new GenericType<List<Namespace>>() {
}));
}
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<Namespace> 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<List<Namespace>>() {
}));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment