-
Notifications
You must be signed in to change notification settings - Fork 250
[feature] Add support for user profiles API #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ | |
import org.zendesk.client.v2.model.TwitterMonitor; | ||
import org.zendesk.client.v2.model.User; | ||
import org.zendesk.client.v2.model.UserField; | ||
import org.zendesk.client.v2.model.UserProfile; | ||
import org.zendesk.client.v2.model.UserRelatedInfo; | ||
import org.zendesk.client.v2.model.View; | ||
import org.zendesk.client.v2.model.dynamic.DynamicContentItem; | ||
|
@@ -1344,6 +1345,84 @@ public void changeUserPassword(User user, String oldPassword, String newPassword | |
handleStatus())); | ||
} | ||
|
||
public List<UserProfile> getUserProfilesForUser(User user) { | ||
return getUserProfilesForUser(user.getId()); | ||
} | ||
|
||
public List<UserProfile> getUserProfilesForUser(long userId) { | ||
return complete( | ||
submit( | ||
req("GET", tmpl("/users/{user_id}/profiles").set("user_id", userId)), | ||
handleList(UserProfile.class, "profiles"))); | ||
} | ||
|
||
public UserProfile getUserProfile(UserProfile userProfile) { | ||
return getUserProfile(userProfile.getId()); | ||
} | ||
|
||
public UserProfile getUserProfile(String userProfileId) { | ||
return complete( | ||
submit( | ||
req("GET", tmpl("/user_profiles/{profile_id}").set("profile_id", userProfileId)), | ||
handle(UserProfile.class, "profile"))); | ||
} | ||
|
||
public UserProfile getUserProfilebyIdentifier(String identifier) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about renaming the variable to |
||
return complete( | ||
submit( | ||
req( | ||
"GET", | ||
tmpl("/user_profiles?identifier={identifier}").set("identifier", identifier)), | ||
handle(UserProfile.class, "profile"))); | ||
} | ||
|
||
public UserProfile createOrUpdateUserProfile(UserProfile userProfile) { | ||
return createOrUpdateUserProfile( | ||
userProfile, | ||
userProfile.getIdentifiers().get(0).getType(), | ||
userProfile.getIdentifiers().get(0).getValue()); | ||
} | ||
|
||
public UserProfile createOrUpdateUserProfile( | ||
UserProfile userProfile, String identifierType, String identifierValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about aligning with the |
||
String identifier = | ||
String.format( | ||
"%s:%s:%s:%s", | ||
userProfile.getSource(), userProfile.getType(), identifierType, identifierValue); | ||
|
||
return complete( | ||
submit( | ||
req( | ||
"PUT", | ||
tmpl("/user_profiles?identifier={identifier}").set("identifier", identifier), | ||
JSON, | ||
json(Collections.singletonMap("profile", userProfile))), | ||
handle(UserProfile.class, "profile"))); | ||
} | ||
|
||
public UserProfile updateUserProfile(UserProfile userProfile) { | ||
|
||
return complete( | ||
submit( | ||
req( | ||
"PUT", | ||
tmpl("/user_profiles/{profile_id}").set("profile_id", userProfile.getId()), | ||
JSON, | ||
json(Collections.singletonMap("profile", userProfile))), | ||
handle(UserProfile.class, "profile"))); | ||
} | ||
|
||
public void deleteUserProfile(UserProfile userProfile) { | ||
deleteUserProfile(userProfile.getId()); | ||
} | ||
|
||
public void deleteUserProfile(String userProfileId) { | ||
complete( | ||
submit( | ||
req("DELETE", tmpl("/user_profiles/{profile_id}").set("profile_id", userProfileId)), | ||
handleStatus())); | ||
} | ||
|
||
public List<Identity> getUserIdentities(User user) { | ||
checkHasId(user); | ||
return getUserIdentities(user.getId()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
package org.zendesk.client.v2.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.io.Serializable; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class UserProfile implements SearchResultEntity, Serializable { | ||
|
||
private Map<String, Object> attributes; | ||
private Date createdAt; | ||
private String id; | ||
private List<Identifier> identifiers; | ||
private String name; | ||
private String source; | ||
private String type; | ||
private Date updatedAt; | ||
private String userId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks odd to use a |
||
|
||
public UserProfile( | ||
Map<String, Object> attributes, | ||
List<Identifier> identifiers, | ||
String name, | ||
String source, | ||
String type) { | ||
this( | ||
attributes, | ||
Date.from(Instant.now()), | ||
null, | ||
identifiers, | ||
name, | ||
source, | ||
type, | ||
Date.from(Instant.now()), | ||
null); | ||
} | ||
|
||
public UserProfile( | ||
Map<String, Object> attributes, | ||
List<Identifier> identifiers, | ||
String name, | ||
String source, | ||
String type, | ||
String userId) { | ||
this( | ||
attributes, | ||
Date.from(Instant.now()), | ||
null, | ||
identifiers, | ||
name, | ||
source, | ||
type, | ||
Date.from(Instant.now()), | ||
userId); | ||
} | ||
|
||
public UserProfile( | ||
Map<String, Object> attributes, | ||
Date createdAt, | ||
String id, | ||
List<Identifier> identifiers, | ||
String name, | ||
String source, | ||
String type, | ||
Date updatedAt, | ||
String userId) { | ||
|
||
this.attributes = attributes; | ||
this.createdAt = createdAt; | ||
this.id = id; | ||
this.identifiers = identifiers; | ||
this.name = name; | ||
this.source = source; | ||
this.type = type; | ||
this.updatedAt = updatedAt; | ||
this.userId = userId; | ||
} | ||
|
||
public UserProfile() {} | ||
|
||
public static class Identifier { | ||
|
||
private String type; | ||
private String value; | ||
|
||
public Identifier() {} | ||
|
||
public Identifier(String type, String value) { | ||
|
||
this.type = type; | ||
this.value = value; | ||
} | ||
|
||
public String getType() { | ||
|
||
return type; | ||
} | ||
|
||
public String getValue() { | ||
|
||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
|
||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Identifier that = (Identifier) o; | ||
return Objects.equals(type, that.type) && Objects.equals(value, that.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
|
||
return Objects.hash(type, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
return "Identifier{" + "type='" + type + '\'' + ", value='" + value + '\'' + '}'; | ||
} | ||
} | ||
|
||
public Map<String, Object> getAttributes() { | ||
|
||
return attributes; | ||
} | ||
|
||
@JsonProperty("created_at") | ||
public Date getCreatedAt() { | ||
|
||
return createdAt; | ||
} | ||
|
||
public String getId() { | ||
|
||
return id; | ||
} | ||
|
||
public List<Identifier> getIdentifiers() { | ||
|
||
return identifiers; | ||
} | ||
|
||
public String getName() { | ||
|
||
return name; | ||
} | ||
|
||
public String getSource() { | ||
|
||
return source; | ||
} | ||
|
||
public String getType() { | ||
|
||
return type; | ||
} | ||
|
||
@JsonProperty("updated_at") | ||
public Date getUpdatedAt() { | ||
|
||
return updatedAt; | ||
} | ||
|
||
@JsonProperty("user_id") | ||
public String getUserId() { | ||
|
||
return userId; | ||
} | ||
|
||
public void addAttribute(String key, Object value) { | ||
this.attributes.put(key, Objects.requireNonNull(value)); | ||
} | ||
|
||
public void setAttributes(Map<String, Object> attributes) { | ||
|
||
this.attributes = attributes; | ||
} | ||
|
||
public void addIdentifier(Identifier identifier) { | ||
this.identifiers.add(identifier); | ||
} | ||
|
||
public void setIdentifiers(List<Identifier> identifiers) { | ||
|
||
this.identifiers = identifiers; | ||
} | ||
|
||
public void setName(String name) { | ||
|
||
this.name = name; | ||
} | ||
|
||
public void setType(String type) { | ||
|
||
this.type = type; | ||
} | ||
|
||
public void setSource(String source) { | ||
|
||
this.source = source; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
|
||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
UserProfile that = (UserProfile) o; | ||
return Objects.equals(attributes, that.attributes) | ||
&& Objects.equals(createdAt, that.createdAt) | ||
&& Objects.equals(id, that.id) | ||
&& Objects.equals(identifiers, that.identifiers) | ||
&& Objects.equals(name, that.name) | ||
&& Objects.equals(source, that.source) | ||
&& Objects.equals(type, that.type) | ||
&& Objects.equals(updatedAt, that.updatedAt) | ||
&& Objects.equals(userId, that.userId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
|
||
return Objects.hash( | ||
attributes, createdAt, id, identifiers, name, source, type, updatedAt, userId); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
return "UserProfile{" | ||
+ "attributes=" | ||
+ attributes | ||
+ ", created_at=" | ||
+ createdAt | ||
+ ", id='" | ||
+ id | ||
+ '\'' | ||
+ ", identifiers=" | ||
+ identifiers | ||
+ ", name='" | ||
+ name | ||
+ '\'' | ||
+ ", source='" | ||
+ source | ||
+ '\'' | ||
+ ", type='" | ||
+ type | ||
+ '\'' | ||
+ ", updated_at=" | ||
+ updatedAt | ||
+ ", user_id='" | ||
+ userId | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose of this method?