Commit 2bd1f51e authored by Greg Messner's avatar Greg Messner
Browse files

Now only includes with_custom_attributes param if enabled (#252).

parent 161e6aad
...@@ -538,9 +538,12 @@ public abstract class AbstractApi implements Constants { ...@@ -538,9 +538,12 @@ public abstract class AbstractApi implements Constants {
* @return a MultivaluedMap instance containing "page" and "per_page" params * @return a MultivaluedMap instance containing "page" and "per_page" params
*/ */
protected MultivaluedMap<String, String> getPageQueryParams(int page, int perPage, boolean customAttributesEnabled) { protected MultivaluedMap<String, String> getPageQueryParams(int page, int perPage, boolean customAttributesEnabled) {
GitLabApiForm form = new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
if (customAttributesEnabled) if (customAttributesEnabled)
return (new GitLabApiForm().withParam("with_custom_attributes", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage).asMap()); return (form.withParam("with_custom_attributes", true).asMap());
return (new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage).asMap());
return (form.asMap());
} }
/** /**
...@@ -559,8 +562,11 @@ public abstract class AbstractApi implements Constants { ...@@ -559,8 +562,11 @@ public abstract class AbstractApi implements Constants {
* @return a MultivaluedMap instance containing the "per_page" param with the default value * @return a MultivaluedMap instance containing the "per_page" param with the default value
*/ */
protected MultivaluedMap<String, String> getDefaultPerPageParam(boolean customAttributesEnabled) { protected MultivaluedMap<String, String> getDefaultPerPageParam(boolean customAttributesEnabled) {
GitLabApiForm form = new GitLabApiForm().withParam(PER_PAGE_PARAM, getDefaultPerPage());
if (customAttributesEnabled) if (customAttributesEnabled)
return (new GitLabApiForm().withParam("with_custom_attributes", true).withParam(PER_PAGE_PARAM, getDefaultPerPage()).asMap()); return (form.withParam("with_custom_attributes", true).asMap());
return (new GitLabApiForm().withParam(PER_PAGE_PARAM, getDefaultPerPage()).asMap());
return (form.asMap());
} }
} }
...@@ -24,6 +24,20 @@ public class UserApi extends AbstractApi { ...@@ -24,6 +24,20 @@ public class UserApi extends AbstractApi {
super(gitLabApi); super(gitLabApi);
} }
/**
* Enables custom attributes to be returned when fetching User instances.
*/
public void enableCustomAttributes() {
customAttributesEnabled = true;
}
/**
* Disables custom attributes to be returned when fetching User instances.
*/
public void disableCustomAttributes() {
customAttributesEnabled = false;
}
/** /**
* Get a list of users. Only returns the first page * Get a list of users. Only returns the first page
* <p> * <p>
...@@ -64,8 +78,7 @@ public class UserApi extends AbstractApi { ...@@ -64,8 +78,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Pager<User> getUsers(int itemsPerPage) throws GitLabApiException { public Pager<User> getUsers(int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("with_custom_attributes", customAttributesEnabled); return (new Pager<User>(this, User.class, itemsPerPage, creatGitLabApiForm().asMap(), "users"));
return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users"));
} }
/** /**
...@@ -77,8 +90,7 @@ public class UserApi extends AbstractApi { ...@@ -77,8 +90,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<User> getActiveUsers() throws GitLabApiException { public List<User> getActiveUsers() throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm()
.withParam("with_custom_attributes", customAttributesEnabled)
.withParam("active", true) .withParam("active", true)
.withParam(PER_PAGE_PARAM, getDefaultPerPage()); .withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "users"); Response response = get(Response.Status.OK, formData.asMap(), "users");
...@@ -97,8 +109,7 @@ public class UserApi extends AbstractApi { ...@@ -97,8 +109,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<User> getActiveUsers(int page, int perPage) throws GitLabApiException { public List<User> getActiveUsers(int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm()
.withParam("with_custom_attributes", customAttributesEnabled)
.withParam("active", true) .withParam("active", true)
.withParam(PAGE_PARAM, page) .withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage); .withParam(PER_PAGE_PARAM, perPage);
...@@ -117,9 +128,7 @@ public class UserApi extends AbstractApi { ...@@ -117,9 +128,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Pager<User> getActiveUsers(int itemsPerPage) throws GitLabApiException { public Pager<User> getActiveUsers(int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm().withParam("active", true);
.withParam("active", true)
.withParam("with_custom_attributes", customAttributesEnabled);
return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users")); return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users"));
} }
...@@ -173,8 +182,7 @@ public class UserApi extends AbstractApi { ...@@ -173,8 +182,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<User> getBlockedUsers() throws GitLabApiException { public List<User> getBlockedUsers() throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm()
.withParam("with_custom_attributes", customAttributesEnabled)
.withParam("blocked", true) .withParam("blocked", true)
.withParam(PER_PAGE_PARAM, getDefaultPerPage()); .withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "users"); Response response = get(Response.Status.OK, formData.asMap(), "users");
...@@ -193,8 +201,7 @@ public class UserApi extends AbstractApi { ...@@ -193,8 +201,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<User> getblockedUsers(int page, int perPage) throws GitLabApiException { public List<User> getblockedUsers(int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm()
.withParam("with_custom_attributes", customAttributesEnabled)
.withParam("blocked", true) .withParam("blocked", true)
.withParam(PAGE_PARAM, page) .withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage); .withParam(PER_PAGE_PARAM, perPage);
...@@ -213,9 +220,7 @@ public class UserApi extends AbstractApi { ...@@ -213,9 +220,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Pager<User> getBlockedUsers(int itemsPerPage) throws GitLabApiException { public Pager<User> getBlockedUsers(int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm().withParam("blocked", true);
.withParam("blocked", true)
.withParam("with_custom_attributes", customAttributesEnabled);
return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users")); return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users"));
} }
...@@ -262,9 +267,7 @@ public class UserApi extends AbstractApi { ...@@ -262,9 +267,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public User getUser(String username) throws GitLabApiException { public User getUser(String username) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm().withParam("username", username, true);
.withParam("username", username, true)
.withParam("with_custom_attributes", customAttributesEnabled);
Response response = get(Response.Status.OK, formData.asMap(), "users"); Response response = get(Response.Status.OK, formData.asMap(), "users");
List<User> users = response.readEntity(new GenericType<List<User>>() { List<User> users = response.readEntity(new GenericType<List<User>>() {
}); });
...@@ -299,10 +302,9 @@ public class UserApi extends AbstractApi { ...@@ -299,10 +302,9 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<User> findUsers(String emailOrUsername) throws GitLabApiException { public List<User> findUsers(String emailOrUsername) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm()
.withParam("search", emailOrUsername, true) .withParam("search", emailOrUsername, true)
.withParam(PER_PAGE_PARAM, getDefaultPerPage()) .withParam(PER_PAGE_PARAM, getDefaultPerPage());
.withParam("with_custom_attributes", customAttributesEnabled);
Response response = get(Response.Status.OK, formData.asMap(), "users"); Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() { return (response.readEntity(new GenericType<List<User>>() {
})); }));
...@@ -320,11 +322,10 @@ public class UserApi extends AbstractApi { ...@@ -320,11 +322,10 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<User> findUsers(String emailOrUsername, int page, int perPage) throws GitLabApiException { public List<User> findUsers(String emailOrUsername, int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm()
.withParam("search", emailOrUsername, true) .withParam("search", emailOrUsername, true)
.withParam(PAGE_PARAM, page) .withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage) .withParam(PER_PAGE_PARAM, perPage);
.withParam("with_custom_attributes", customAttributesEnabled);
Response response = get(Response.Status.OK, formData.asMap(), "users"); Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() { return (response.readEntity(new GenericType<List<User>>() {
})); }));
...@@ -341,9 +342,7 @@ public class UserApi extends AbstractApi { ...@@ -341,9 +342,7 @@ public class UserApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Pager<User> findUsers(String emailOrUsername, int itemsPerPage) throws GitLabApiException { public Pager<User> findUsers(String emailOrUsername, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = creatGitLabApiForm().withParam("search", emailOrUsername, true);
.withParam("search", emailOrUsername, true)
.withParam("with_custom_attributes", customAttributesEnabled);
return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users")); return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "users"));
} }
...@@ -908,12 +907,15 @@ public class UserApi extends AbstractApi { ...@@ -908,12 +907,15 @@ public class UserApi extends AbstractApi {
.withParam("shared_runners_minutes_limit", user.getSharedRunnersMinutesLimit(), false)); .withParam("shared_runners_minutes_limit", user.getSharedRunnersMinutesLimit(), false));
} }
public void enableCustomAttributes() { /**
this.customAttributesEnabled = true; * Creates a GitLabApiForm instance that will optionally include the
} * with_custom_attributes query param if enabled.
*
public UserApi withCustomAttributes() { * @return a GitLabApiForm instance that will optionally include the
enableCustomAttributes(); * with_custom_attributes query param if enabled
return this; */
private GitLabApiForm creatGitLabApiForm() {
GitLabApiForm formData = new GitLabApiForm();
return (customAttributesEnabled ? formData.withParam("with_custom_attributes", true) : formData);
} }
} }
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