UserApi.java 7.67 KiB
package org.gitlab4j.api;
import java.util.List;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.models.User;
/**
 * This class provides an entry point to all the GitLab API users calls.
public class UserApi extends AbstractApi {
    UserApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    /**
     * Get a list of users. Only returns the first page
     * GET /users
     * @return a list of Users, this list will only contain the first 20 users in the system.
     * @throws GitLabApiException if any exception occurs
    public List<User> getUsers() throws GitLabApiException {
        Response response = get(Response.Status.OK, null, "users");
        return (response.readEntity(new GenericType<List<User>>() {
        }));
    /**
     * Get a list of users using the specified page and per page settings.
     * GET /users
     * @param page the page to get
     * @param perPage the number of users per page
     * @return the list of Users in the specified range
     * @throws GitLabApiException if any exception occurs
    public List<User> getUsers(int page, int perPage) throws GitLabApiException {
        GitLabApiForm formData = new GitLabApiForm()
                .withParam("page", page, false)
                .withParam("per_page", perPage, false);
        Response response = get(Response.Status.OK, formData.asMap(), "users");
        return (response.readEntity(new GenericType<List<User>>() {
        }));
    /**
     * Get a single user.
     * GET /users/:id
     * @param userId the ID of the user to get
     * @return the User instance for the specified user ID
     * @throws GitLabApiException if any exception occurs
    public User getUser(int userId) throws GitLabApiException {
        Response response = get(Response.Status.OK, null, "users", userId);
        return (response.readEntity(User.class));
    /**
     * Search users by Email or username