Skip to content

Commit 42fb254

Browse files
authored
Merge pull request cloudbees-oss#132 from solarmosaic/update-identity
Fixes cloudbees-oss#130 and cloudbees-oss#131.
2 parents f3623c8 + 21e9940 commit 42fb254

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/main/java/org/zendesk/client/v2/Zendesk.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,18 @@ public Identity requestVerifyUserIdentity(long userId, long identityId) {
808808
.set("identityId", identityId), JSON, null), handle(Identity.class, "identity")));
809809
}
810810

811+
public Identity updateUserIdentity(long userId, Identity identity) {
812+
checkHasId(identity);
813+
return complete(submit(req("PUT", tmpl("/users/{userId}/identities/{identityId}.json")
814+
.set("userId", userId)
815+
.set("identityId", identity.getId()), JSON, null), handle(Identity.class, "identity")));
816+
}
817+
818+
public Identity updateUserIdentity(User user, Identity identity) {
819+
checkHasId(user);
820+
return updateUserIdentity(user.getId(), identity);
821+
}
822+
811823
public void deleteUserIdentity(User user, Identity identity) {
812824
checkHasId(identity);
813825
deleteUserIdentity(user, identity.getId());
@@ -825,14 +837,14 @@ public void deleteUserIdentity(long userId, long identityId) {
825837
), handleStatus()));
826838
}
827839

828-
public void createUserIdentity(long userId, Identity identity) {
829-
complete(submit(req("POST", tmpl("/users/{userId}/identities.json").set("userId", userId), JSON, json(
830-
Collections.singletonMap("identity", identity))), handle(Identity.class, "identity")));
840+
public Identity createUserIdentity(long userId, Identity identity) {
841+
return complete(submit(req("POST", tmpl("/users/{userId}/identities.json").set("userId", userId), JSON,
842+
json(Collections.singletonMap("identity", identity))), handle(Identity.class, "identity")));
831843
}
832844

833-
public void createUserIdentity(User user, Identity identity) {
834-
complete(submit(req("POST", tmpl("/users/{userId}/identities.json").set("userId", user.getId()), JSON, json(
835-
Collections.singletonMap("identity", identity))), handle(Identity.class, "identity")));
845+
public Identity createUserIdentity(User user, Identity identity) {
846+
return complete(submit(req("POST", tmpl("/users/{userId}/identities.json").set("userId", user.getId()), JSON,
847+
json(Collections.singletonMap("identity", identity))), handle(Identity.class, "identity")));
836848
}
837849

838850
public Iterable<org.zendesk.client.v2.model.Request> getRequests() {

src/test/java/org/zendesk/client/v2/RealSmokeTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,27 @@ public void lookupUserIdentities() throws Exception {
348348
}
349349
}
350350

351+
@Test
352+
public void updateUserIdentity() throws Exception {
353+
createClientWithTokenOrPassword();
354+
User user = instance.getCurrentUser();
355+
356+
Identity identity = new Identity();
357+
identity.setUserId(user.getId());
358+
identity.setType("email");
359+
identity.setValue("[email protected]");
360+
361+
Identity createdIdentity = instance.createUserIdentity(user, identity);
362+
assertThat(createdIdentity.getValue(), is("[email protected]"));
363+
364+
createdIdentity.setValue("[email protected]");
365+
Identity updatedIdentity = instance.updateUserIdentity(user, createdIdentity);
366+
367+
assertThat(updatedIdentity.getValue(), is("[email protected]"));
368+
369+
instance.deleteUserIdentity(user, identity);
370+
}
371+
351372
@Test
352373
public void getUserRequests() throws Exception {
353374
createClientWithTokenOrPassword();

0 commit comments

Comments
 (0)