|
20 | 20 | import org.zendesk.client.v2.model.Comment;
|
21 | 21 | import org.zendesk.client.v2.model.Field;
|
22 | 22 | import org.zendesk.client.v2.model.Identity;
|
| 23 | +import org.zendesk.client.v2.model.Organization; |
23 | 24 | import org.zendesk.client.v2.model.Ticket;
|
24 | 25 | import org.zendesk.client.v2.model.User;
|
25 | 26 |
|
@@ -503,6 +504,7 @@ public org.zendesk.client.v2.model.Request createRequest(org.zendesk.client.v2.m
|
503 | 504 | JSON, json(Collections.singletonMap("request", request))),
|
504 | 505 | handle(org.zendesk.client.v2.model.Request.class, "request")));
|
505 | 506 | }
|
| 507 | + |
506 | 508 | public org.zendesk.client.v2.model.Request updateRequest(org.zendesk.client.v2.model.Request request) {
|
507 | 509 | checkHasId(request);
|
508 | 510 | return complete(submit(req("PUT", tmpl("/requests/{id}.json").set("id", request.getId()),
|
@@ -537,6 +539,65 @@ public Comment getRequestComment(int requestId, int commentId) {
|
537 | 539 | handle(Comment.class, "comment")));
|
538 | 540 | }
|
539 | 541 |
|
| 542 | + public Iterable<Organization> getOrganizations() { |
| 543 | + return new PagedIterable<Organization>(cnst("/organizations.json"), |
| 544 | + handleList(Organization.class, "organizations")); |
| 545 | + } |
| 546 | + |
| 547 | + public Iterable<Organization> getAutoCompleteOrganizations(String name) { |
| 548 | + if (name == null || name.length() < 2) { |
| 549 | + throw new IllegalArgumentException("Name must be at least 2 characters long"); |
| 550 | + } |
| 551 | + return new PagedIterable<Organization>(tmpl("/organizations/autocomplete.json{?name}").set("name", name), |
| 552 | + handleList(Organization.class, "organizations")); |
| 553 | + } |
| 554 | + |
| 555 | + // TODO getOrganizationRelatedInformation |
| 556 | + |
| 557 | + public Organization getOrganization(int id) { |
| 558 | + return complete(submit(req("GET", tmpl("/organizations/{id}.json").set("id", id)), |
| 559 | + handle(Organization.class, "organization"))); |
| 560 | + } |
| 561 | + |
| 562 | + public Organization createOrganization(Organization organization) { |
| 563 | + return complete(submit(req("POST", cnst("/organizations.json"), JSON, json( |
| 564 | + Collections.singletonMap("organization", organization))), handle(Organization.class, "organization"))); |
| 565 | + } |
| 566 | + |
| 567 | + public List<Organization> createOrganizations(Organization... organizations) { |
| 568 | + return createOrganizations(Arrays.asList(organizations)); |
| 569 | + } |
| 570 | + |
| 571 | + public List<Organization> createOrganizations(List<Organization> organizations) { |
| 572 | + return complete(submit(req("POST", cnst("/organizations/create_many.json"), JSON, json( |
| 573 | + Collections.singletonMap("organizations", organizations))), handleList(Organization.class, "results"))); |
| 574 | + } |
| 575 | + |
| 576 | + public Organization updateOrganization(Organization organization) { |
| 577 | + checkHasId(organization); |
| 578 | + return complete(submit(req("PUT", tmpl("/organizations/{id}.json").set("id", organization.getId()), JSON, json( |
| 579 | + Collections.singletonMap("organization", organization))), handle(Organization.class, "organization"))); |
| 580 | + } |
| 581 | + |
| 582 | + public void deleteOrganization(Organization organization) { |
| 583 | + checkHasId(organization); |
| 584 | + deleteOrganization(organization.getId()); |
| 585 | + } |
| 586 | + |
| 587 | + public void deleteOrganization(int id) { |
| 588 | + complete(submit(req("DELETE", tmpl("/organizations/{id}.json").set("id", id)), handleStatus())); |
| 589 | + } |
| 590 | + |
| 591 | + public Iterable<Organization> lookupOrganizationsByExternalId(String externalId) { |
| 592 | + if (externalId == null || externalId.length() < 2) { |
| 593 | + throw new IllegalArgumentException("Name must be at least 2 characters long"); |
| 594 | + } |
| 595 | + return new PagedIterable<Organization>(tmpl("/organizations/search.json{?external_id}").set("external_id", externalId), |
| 596 | + handleList(Organization.class, "organizations")); |
| 597 | + } |
| 598 | + |
| 599 | + |
| 600 | + |
540 | 601 | //////////////////////////////////////////////////////////////////////
|
541 | 602 | // Helper methods
|
542 | 603 | //////////////////////////////////////////////////////////////////////
|
@@ -752,6 +813,12 @@ private static void checkHasId(Identity identity) {
|
752 | 813 | }
|
753 | 814 | }
|
754 | 815 |
|
| 816 | + private static void checkHasId(Organization organization) { |
| 817 | + if (organization.getId() == null) { |
| 818 | + throw new IllegalArgumentException("Organization requires id"); |
| 819 | + } |
| 820 | + } |
| 821 | + |
755 | 822 | private static void checkHasToken(Attachment.Upload upload) {
|
756 | 823 | if (upload.getToken() == null) {
|
757 | 824 | throw new IllegalArgumentException("Upload requires token");
|
|
0 commit comments