Commit 1e50236a authored by Alex Bobkov's avatar Alex Bobkov Committed by Greg Messner
Browse files

Get active/blocked users (#89)

parent 86c1c6db
package org.gitlab4j.api; package org.gitlab4j.api;
import java.util.List; import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.SshKey;
import org.gitlab4j.api.models.User;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.SshKey;
import org.gitlab4j.api.models.User;
/** /**
* This class provides an entry point to all the GitLab API users calls. * This class provides an entry point to all the GitLab API users calls.
...@@ -24,7 +23,7 @@ public class UserApi extends AbstractApi { ...@@ -24,7 +23,7 @@ public class UserApi extends AbstractApi {
* *
* GET /users * GET /users
* *
* @return a list of Users, this list will only contain the first 20 users in the system. * @return a list of Users, this list will only contain the first 100 users in the system.
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<User> getUsers() throws GitLabApiException { public List<User> getUsers() throws GitLabApiException {
...@@ -52,7 +51,7 @@ public class UserApi extends AbstractApi { ...@@ -52,7 +51,7 @@ public class UserApi extends AbstractApi {
* *
* GET /users * GET /users
* *
* @param itemsPerPage the number of Project instances that will be fetched per page * @param itemsPerPage the number of User instances that will be fetched per page
* @return a Pager of User * @return a Pager of User
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
...@@ -60,6 +59,104 @@ public class UserApi extends AbstractApi { ...@@ -60,6 +59,104 @@ public class UserApi extends AbstractApi {
return (new Pager<User>(this, User.class, itemsPerPage, null, "users")); return (new Pager<User>(this, User.class, itemsPerPage, null, "users"));
} }
/**
* Get a list of active users. Only returns the first page
*
* GET /users?active=true
*
* @return a list of active Users, this list will only contain the first 100 users in the system.
* @throws GitLabApiException if any exception occurs
*/
public List<User> getActiveUsers() throws GitLabApiException{
GitLabApiForm formData = new GitLabApiForm()
.withParam("active", true)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {}));
}
/**
* Get a list of active users using the specified page and per page settings.
*
* GET /users?active=true
*
* @param page the page to get
* @param perPage the number of users per page
* @return the list of active Users in the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<User> getActiveUsers(int page, int perPage) throws GitLabApiException{
GitLabApiForm formData = new GitLabApiForm()
.withParam("active", true)
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {}));
}
/**
* Get a Pager of active users.
*
* GET /users?active=true
*
* @param itemsPerPage the number of active User instances that will be fetched per page
* @return a Pager of active User
* @throws GitLabApiException if any exception occurs
*/
public Pager<User> getActiveUsers(int itemsPerPage) throws GitLabApiException{
GitLabApiForm formData = new GitLabApiForm().withParam("active", true);
return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users"));
}
/**
* Get a list of blocked users. Only returns the first page
*
* GET /users?blocked=true
*
* @return a list of blocked Users, this list will only contain the first 100 users in the system.
* @throws GitLabApiException if any exception occurs
*/
public List<User> getBlockedUsers() throws GitLabApiException{
GitLabApiForm formData = new GitLabApiForm()
.withParam("blocked", true)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {}));
}
/**
* Get a list of blocked users using the specified page and per page settings.
*
* GET /users?blocked=true
*
* @param page the page to get
* @param perPage the number of users per page
* @return the list of blocked Users in the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<User> getblockedUsers(int page, int perPage) throws GitLabApiException{
GitLabApiForm formData = new GitLabApiForm()
.withParam("blocked", true)
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {}));
}
/**
* Get a Pager of blocked users.
*
* GET /users?blocked=true
*
* @param itemsPerPage the number of blocked User instances that will be fetched per page
* @return a Pager of blocked User
* @throws GitLabApiException if any exception occurs
*/
public Pager<User> getBlockedUsers(int itemsPerPage) throws GitLabApiException{
GitLabApiForm formData = new GitLabApiForm().withParam("blocked", true);
return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users"));
}
/** /**
* Get a single user. * Get a single user.
* *
......
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