Commit d0c57228 authored by Ruben Vitt's avatar Ruben Vitt Committed by Greg Messner
Browse files

feat-impl: custom attributes for users (#252)

parent 55518136
......@@ -113,13 +113,13 @@ public abstract class AbstractApi implements Constants {
protected GitLabApiClient getApiClient() {
return (gitLabApi.getApiClient());
}
/**
* Encode a string to be used as in-path argument for a gitlab api request.
*
*
* Standard URL encoding changes spaces to plus signs, but for arguments that are part of the path,
* like the :file_path in a "Get raw file" request, gitlab expects spaces to be encoded with %20.
*
*
* @param s the string to encode
* @return encoded version of s with spaces encoded as %2F
* @throws GitLabApiException if encoding throws an exception
......@@ -517,6 +517,7 @@ public abstract class AbstractApi implements Constants {
return (new GitLabApiException(thrown));
}
/**
* Creates a MultivaluedMap instance containing "page" and "per_page" params.
*
......@@ -525,6 +526,20 @@ public abstract class AbstractApi implements Constants {
* @return a MultivaluedMap instance containing "page" and "per_page" params
*/
protected MultivaluedMap<String, String> getPageQueryParams(int page, int perPage) {
return (new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage).asMap());
}
/**
* Creates a MultivaluedMap instance containing "page" and "per_page" params.
*
* @param page the page to get
* @param perPage the number of projects per page
* @param customAttributesEnabled enables customAttributes for this query
* @return a MultivaluedMap instance containing "page" and "per_page" params
*/
protected MultivaluedMap<String, String> getPageQueryParams(int page, int perPage, boolean customAttributesEnabled) {
if (customAttributesEnabled)
return (new GitLabApiForm().withParam("with_custom_attributes", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage).asMap());
return (new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage).asMap());
}
......@@ -536,4 +551,16 @@ public abstract class AbstractApi implements Constants {
protected MultivaluedMap<String, String> getDefaultPerPageParam() {
return (new GitLabApiForm().withParam(PER_PAGE_PARAM, getDefaultPerPage()).asMap());
}
/**
* Creates a MultivaluedMap instance containing the "per_page" param with the default value.
*
* @param customAttributesEnabled enables customAttributes for this query
* @return a MultivaluedMap instance containing the "per_page" param with the default value
*/
protected MultivaluedMap<String, String> getDefaultPerPageParam(boolean customAttributesEnabled) {
if (customAttributesEnabled)
return (new GitLabApiForm().withParam("with_custom_attributes", true).withParam(PER_PAGE_PARAM, getDefaultPerPage()).asMap());
return (new GitLabApiForm().withParam(PER_PAGE_PARAM, getDefaultPerPage()).asMap());
}
}
This diff is collapsed.
package org.gitlab4j.api.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Date;
import java.util.List;
......@@ -7,6 +9,7 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@XmlAccessorType(XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
public class AbstractUser {
private String avatarUrl;
......@@ -17,6 +20,7 @@ public class AbstractUser {
private Date confirmedAt;
private Date createdAt;
private Date currentSignInAt;
private List<CustomAttribute> customAttributes;
private String email;
private Boolean external;
private Integer id;
......@@ -288,4 +292,12 @@ public class AbstractUser {
public void setSkipConfirmation(Boolean skipConfirmation) {
this.skipConfirmation = skipConfirmation;
}
public List<CustomAttribute> getCustomAttributes() {
return customAttributes;
}
public void setCustomAttributes(List<CustomAttribute> customAttributes) {
this.customAttributes = customAttributes;
}
}
package org.gitlab4j.api.models;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@XmlAccessorType(XmlAccessType.FIELD)
public class CustomAttribute {
private String key;
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public CustomAttribute withKey(String key) {
this.key = key;
return this;
}
public CustomAttribute withValue(String value) {
this.value = value;
return this;
}
}
package org.gitlab4j.api.models;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement
public class User extends AbstractUser {
......@@ -103,4 +104,9 @@ public class User extends AbstractUser {
setSharedRunnersMinutesLimit(sharedRunnersMinuteLimit);
return this;
}
public User withCustomAttributes(List<CustomAttribute> customAttributes) {
setCustomAttributes(customAttributes);
return this;
}
}
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