Skip to content

Commit 3acb489

Browse files
committed
Add support for groups
1 parent c40cc31 commit 3acb489

File tree

4 files changed

+157
-11
lines changed

4 files changed

+157
-11
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ Status
3232

3333
Here is the status of the various API components:
3434

35-
* [Tickets](http://developer.zendesk.com/documentation/rest_api/tickets.html) - DONE
36-
* [Ticket Audits](http://developer.zendesk.com/documentation/rest_api/ticket_audits.html) - DONE
35+
* [Tickets](http://developer.zendesk.com/documentation/rest_api/tickets.html)
36+
* [Ticket Audits](http://developer.zendesk.com/documentation/rest_api/ticket_audits.html)
3737
* [Incremental Tickets](http://developer.zendesk.com/documentation/rest_api/ticket_export.html)
38-
* [Ticket Fields](http://developer.zendesk.com/documentation/rest_api/ticket_fields.html) - DONE
38+
* [Ticket Fields](http://developer.zendesk.com/documentation/rest_api/ticket_fields.html)
3939
* [Ticket Import](http://developer.zendesk.com/documentation/rest_api/ticket_import.html)
4040
* [Ticket Metrics](http://developer.zendesk.com/documentation/rest_api/ticket_metrics.html)
4141
* [Views](http://developer.zendesk.com/documentation/rest_api/views.html)
42-
* [Users](http://developer.zendesk.com/documentation/rest_api/users.html) - DONE
43-
* [Requests](http://developer.zendesk.com/documentation/rest_api/requests.html) - DONE
44-
* [User Identities](http://developer.zendesk.com/documentation/rest_api/user_identities.html) - DONE
45-
* [Groups](http://developer.zendesk.com/documentation/rest_api/groups.html)
42+
* [Users](http://developer.zendesk.com/documentation/rest_api/users.html)
43+
* [Requests](http://developer.zendesk.com/documentation/rest_api/requests.html)
44+
* [User Identities](http://developer.zendesk.com/documentation/rest_api/user_identities.html)
45+
* [Groups](http://developer.zendesk.com/documentation/rest_api/groups.html)
4646
* [Group Membership](http://developer.zendesk.com/documentation/rest_api/group_memberships.html)
4747
* [Custom Agent Roles](http://developer.zendesk.com/documentation/rest_api/custom_roles.html)
48-
* [Organizations](http://developer.zendesk.com/documentation/rest_api/organizations.html) - DONE (except for related info)
48+
* [Organizations](http://developer.zendesk.com/documentation/rest_api/organizations.html) *except for related info*
4949
* [Search](http://developer.zendesk.com/documentation/rest_api/search.html)
5050
* [Tags](http://developer.zendesk.com/documentation/rest_api/tags.html)
5151
* [Forums](http://developer.zendesk.com/documentation/rest_api/forums.html)
@@ -57,14 +57,14 @@ Here is the status of the various API components:
5757
* [Topic Votes](http://developer.zendesk.com/documentation/rest_api/topic_votes.html)
5858
* [Account Settings](http://developer.zendesk.com/documentation/rest_api/account_settings.html)
5959
* [Activity Stream](http://developer.zendesk.com/documentation/rest_api/activity_stream.html)
60-
* [Attachments](http://developer.zendesk.com/documentation/rest_api/attachments.html) - DONE
60+
* [Attachments](http://developer.zendesk.com/documentation/rest_api/attachments.html)
6161
* [Autocompletion](http://developer.zendesk.com/documentation/rest_api/autocomplete.html)
6262
* [Automations](http://developer.zendesk.com/documentation/rest_api/automations.html)
6363
* [Job Statuses](http://developer.zendesk.com/documentation/rest_api/job_statuses.html)
6464
* [Locales](http://developer.zendesk.com/documentation/rest_api/locales.html)
6565
* [Macros](http://developer.zendesk.com/documentation/rest_api/macros.html)
6666
* [Restrictions and Responsibilities](http://developer.zendesk.com/documentation/rest_api/restrictions.html)
67-
* [Satisfaction Ratings](http://developer.zendesk.com/documentation/rest_api/satisfaction_ratings.html) - DONE
67+
* [Satisfaction Ratings](http://developer.zendesk.com/documentation/rest_api/satisfaction_ratings.html)
6868
* [Sharing Agreements](http://developer.zendesk.com/documentation/rest_api/sharing_agreements.html)
6969
* [Suspended Tickets](http://developer.zendesk.com/documentation/rest_api/suspended_tickets.html)
70-
* [Triggers](http://developer.zendesk.com/documentation/rest_api/triggers.html)
70+
* [Triggers](http://developer.zendesk.com/documentation/rest_api/triggers.html)

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.zendesk.client.v2.model.Audit;
2020
import org.zendesk.client.v2.model.Comment;
2121
import org.zendesk.client.v2.model.Field;
22+
import org.zendesk.client.v2.model.Group;
2223
import org.zendesk.client.v2.model.Identity;
2324
import org.zendesk.client.v2.model.Organization;
2425
import org.zendesk.client.v2.model.Ticket;
@@ -596,7 +597,49 @@ public Iterable<Organization> lookupOrganizationsByExternalId(String externalId)
596597
handleList(Organization.class, "organizations"));
597598
}
598599

600+
public Iterable<Group> getGroups() {
601+
return new PagedIterable<Group>(cnst("/groups.json"),
602+
handleList(Group.class, "groups"));
603+
}
604+
605+
public Iterable<Group> getAssignableGroups() {
606+
return new PagedIterable<Group>(cnst("/groups/assignable.json"),
607+
handleList(Group.class, "groups"));
608+
}
609+
610+
public Group getGroup(int id) {
611+
return complete(submit(req("GET", tmpl("/groups/{id}.json").set("id", id)),
612+
handle(Group.class, "group")));
613+
}
599614

615+
public Group createGroup(Group group) {
616+
return complete(submit(req("POST", cnst("/groups.json"), JSON, json(
617+
Collections.singletonMap("group", group))), handle(Group.class, "group")));
618+
}
619+
620+
public List<Group> createGroups(Group... groups) {
621+
return createGroups(Arrays.asList(groups));
622+
}
623+
624+
public List<Group> createGroups(List<Group> groups) {
625+
return complete(submit(req("POST", cnst("/groups/create_many.json"), JSON, json(
626+
Collections.singletonMap("groups", groups))), handleList(Group.class, "results")));
627+
}
628+
629+
public Group updateGroup(Group group) {
630+
checkHasId(group);
631+
return complete(submit(req("PUT", tmpl("/groups/{id}.json").set("id", group.getId()), JSON, json(
632+
Collections.singletonMap("group", group))), handle(Group.class, "group")));
633+
}
634+
635+
public void deleteGroup(Group group) {
636+
checkHasId(group);
637+
deleteGroup(group.getId());
638+
}
639+
640+
public void deleteGroup(int id) {
641+
complete(submit(req("DELETE", tmpl("/groups/{id}.json").set("id", id)), handleStatus()));
642+
}
600643

601644
//////////////////////////////////////////////////////////////////////
602645
// Helper methods
@@ -819,6 +862,12 @@ private static void checkHasId(Organization organization) {
819862
}
820863
}
821864

865+
private static void checkHasId(Group group) {
866+
if (group.getId() == null) {
867+
throw new IllegalArgumentException("Group requires id");
868+
}
869+
}
870+
822871
private static void checkHasToken(Attachment.Upload upload) {
823872
if (upload.getToken() == null) {
824873
throw new IllegalArgumentException("Upload requires token");
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.Date;
6+
7+
/**
8+
* @author stephenc
9+
* @since 22/04/2013 16:27
10+
*/
11+
public class Group {
12+
private Integer id;
13+
private String url;
14+
private String name;
15+
private Boolean deleted;
16+
private Date createdAt;
17+
private Date updatedAt;
18+
19+
public Group() {
20+
}
21+
22+
public Integer getId() {
23+
return id;
24+
}
25+
26+
public void setId(Integer id) {
27+
this.id = id;
28+
}
29+
30+
public String getUrl() {
31+
return url;
32+
}
33+
34+
public void setUrl(String url) {
35+
this.url = url;
36+
}
37+
38+
public String getName() {
39+
return name;
40+
}
41+
42+
public void setName(String name) {
43+
this.name = name;
44+
}
45+
46+
public Boolean getDeleted() {
47+
return deleted;
48+
}
49+
50+
public void setDeleted(Boolean deleted) {
51+
this.deleted = deleted;
52+
}
53+
54+
@JsonProperty("created_at")
55+
public Date getCreatedAt() {
56+
return createdAt;
57+
}
58+
59+
public void setCreatedAt(Date createdAt) {
60+
this.createdAt = createdAt;
61+
}
62+
63+
@JsonProperty("deleted_at")
64+
public Date getUpdatedAt() {
65+
return updatedAt;
66+
}
67+
68+
public void setUpdatedAt(Date updatedAt) {
69+
this.updatedAt = updatedAt;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
final StringBuilder sb = new StringBuilder("Group{");
75+
sb.append("id=").append(id);
76+
sb.append(", url='").append(url).append('\'');
77+
sb.append(", name='").append(name).append('\'');
78+
sb.append(", deleted=").append(deleted);
79+
sb.append(", createdAt=").append(createdAt);
80+
sb.append(", updatedAt=").append(updatedAt);
81+
sb.append('}');
82+
return sb.toString();
83+
}
84+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.zendesk.client.v2.model.Audit;
88
import org.zendesk.client.v2.model.Comment;
99
import org.zendesk.client.v2.model.Field;
10+
import org.zendesk.client.v2.model.Group;
1011
import org.zendesk.client.v2.model.Identity;
1112
import org.zendesk.client.v2.model.Organization;
1213
import org.zendesk.client.v2.model.Request;
@@ -232,4 +233,16 @@ public void getOrganizations() throws Exception {
232233
}
233234
}
234235

236+
@Test
237+
public void getGroups() throws Exception {
238+
createClientWithToken();
239+
int count = 0;
240+
for (Group t : instance.getGroups()) {
241+
assertThat(t.getName(), notNullValue());
242+
if (++count > 10) {
243+
break;
244+
}
245+
}
246+
}
247+
235248
}

0 commit comments

Comments
 (0)