|
18 | 18 | import org.zendesk.client.v2.model.Attachment;
|
19 | 19 | import org.zendesk.client.v2.model.Audit;
|
20 | 20 | import org.zendesk.client.v2.model.Field;
|
| 21 | +import org.zendesk.client.v2.model.Identity; |
21 | 22 | import org.zendesk.client.v2.model.Ticket;
|
22 | 23 | import org.zendesk.client.v2.model.User;
|
23 | 24 |
|
@@ -362,13 +363,106 @@ public void resetUserPassword(int id, String password) {
|
362 | 363 |
|
363 | 364 | public void changeUserPassword(User user, String oldPassword, String newPassword) {
|
364 | 365 | checkHasId(user);
|
365 |
| - Map<String,String> req = new HashMap<String,String>(); |
| 366 | + Map<String, String> req = new HashMap<String, String>(); |
366 | 367 | req.put("previous_password", oldPassword);
|
367 | 368 | req.put("password", newPassword);
|
368 | 369 | complete(submit(req("PUT", tmpl("/users/{id}/password.json").set("id", user.getId()), JSON,
|
369 | 370 | json(req)), handleStatus()));
|
370 | 371 | }
|
371 | 372 |
|
| 373 | + public List<Identity> getUserIdentities(User user) { |
| 374 | + checkHasId(user); |
| 375 | + return getUserIdentities(user.getId()); |
| 376 | + } |
| 377 | + |
| 378 | + public List<Identity> getUserIdentities(int userId) { |
| 379 | + return complete(submit(req("GET", tmpl("/users/{id}/identities.json").set("id", userId)), |
| 380 | + handleList(Identity.class, "identities"))); |
| 381 | + } |
| 382 | + |
| 383 | + public Identity getUserIdentity(User user, Identity identity) { |
| 384 | + checkHasId(identity); |
| 385 | + return getUserIdentity(user, identity.getId()); |
| 386 | + } |
| 387 | + |
| 388 | + public Identity getUserIdentity(User user, int identityId) { |
| 389 | + checkHasId(user); |
| 390 | + return getUserIdentity(user.getId(), identityId); |
| 391 | + } |
| 392 | + |
| 393 | + public Identity getUserIdentity(int userId, int identityId) { |
| 394 | + return complete(submit(req("GET", tmpl("/users/{userId}/identities/{identityId}.json").set("userId", userId) |
| 395 | + .set("identityId", identityId)), handle( |
| 396 | + Identity.class, "identity"))); |
| 397 | + } |
| 398 | + |
| 399 | + public List<Identity> setUserPrimaryIdentity(User user, Identity identity) { |
| 400 | + checkHasId(identity); |
| 401 | + return setUserPrimaryIdentity(user, identity.getId()); |
| 402 | + } |
| 403 | + |
| 404 | + public List<Identity> setUserPrimaryIdentity(User user, int identityId) { |
| 405 | + checkHasId(user); |
| 406 | + return setUserPrimaryIdentity(user.getId(), identityId); |
| 407 | + } |
| 408 | + |
| 409 | + public List<Identity> setUserPrimaryIdentity(int userId, int identityId) { |
| 410 | + return complete(submit(req("PUT", |
| 411 | + tmpl("/users/{userId}/identities/{identityId}/make_primary").set("userId", userId) |
| 412 | + .set("identityId", identityId)), |
| 413 | + handleList(Identity.class, "identities"))); |
| 414 | + } |
| 415 | + |
| 416 | + public Identity verifyUserIdentity(User user, Identity identity) { |
| 417 | + checkHasId(identity); |
| 418 | + return verifyUserIdentity(user, identity.getId()); |
| 419 | + } |
| 420 | + |
| 421 | + public Identity verifyUserIdentity(User user, int identityId) { |
| 422 | + checkHasId(user); |
| 423 | + return verifyUserIdentity(user.getId(), identityId); |
| 424 | + } |
| 425 | + |
| 426 | + public Identity verifyUserIdentity(int userId, int identityId) { |
| 427 | + return complete(submit(req("PUT", tmpl("/users/{userId}/identities/{identityId}/verify") |
| 428 | + .set("userId",userId) |
| 429 | + .set("identityId", identityId)), handle(Identity.class, "identity"))); |
| 430 | + } |
| 431 | + |
| 432 | + public Identity requestVerifyUserIdentity(User user, Identity identity) { |
| 433 | + checkHasId(identity); |
| 434 | + return requestVerifyUserIdentity(user, identity.getId()); |
| 435 | + } |
| 436 | + |
| 437 | + public Identity requestVerifyUserIdentity(User user, int identityId) { |
| 438 | + checkHasId(user); |
| 439 | + return requestVerifyUserIdentity(user.getId(), identityId); |
| 440 | + } |
| 441 | + |
| 442 | + public Identity requestVerifyUserIdentity(int userId, int identityId) { |
| 443 | + return complete(submit(req("PUT", tmpl("/users/{userId}/identities/{identityId}/request_verification") |
| 444 | + .set("userId",userId) |
| 445 | + .set("identityId", identityId)), handle(Identity.class, "identity"))); |
| 446 | + } |
| 447 | + |
| 448 | + public void deleteUserIdentity(User user, Identity identity) { |
| 449 | + checkHasId(identity); |
| 450 | + deleteUserIdentity(user, identity.getId()); |
| 451 | + } |
| 452 | + |
| 453 | + public void deleteUserIdentity(User user, int identityId) { |
| 454 | + checkHasId(user); |
| 455 | + deleteUserIdentity(user.getId(), identityId); |
| 456 | + } |
| 457 | + |
| 458 | + public void deleteUserIdentity(int userId, int identityId) { |
| 459 | + complete(submit(req("DELETE", tmpl("/users/{userId}/identities/{identityId}.json") |
| 460 | + .set("userId", userId) |
| 461 | + .set("identityId", identityId) |
| 462 | + ), handleStatus())); |
| 463 | + } |
| 464 | + |
| 465 | + |
372 | 466 | //////////////////////////////////////////////////////////////////////
|
373 | 467 | // Helper methods
|
374 | 468 | //////////////////////////////////////////////////////////////////////
|
@@ -566,6 +660,12 @@ private static void checkHasId(User user) {
|
566 | 660 | }
|
567 | 661 | }
|
568 | 662 |
|
| 663 | + private static void checkHasId(Identity identity) { |
| 664 | + if (identity.getId() == null) { |
| 665 | + throw new IllegalArgumentException("Identity requires id"); |
| 666 | + } |
| 667 | + } |
| 668 | + |
569 | 669 | private static void checkHasToken(Attachment.Upload upload) {
|
570 | 670 | if (upload.getToken() == null) {
|
571 | 671 | throw new IllegalArgumentException("Upload requires token");
|
|
0 commit comments