Skip to content

Commit 0eeb252

Browse files
authored
Merge pull request #485 from cloudbees-oss/count
[feature] New methods get*TicketsCount*()
2 parents 17ed833 + ae80853 commit 0eeb252

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.zendesk.client.v2.model.Status;
4747
import org.zendesk.client.v2.model.SuspendedTicket;
4848
import org.zendesk.client.v2.model.Ticket;
49+
import org.zendesk.client.v2.model.TicketCount;
4950
import org.zendesk.client.v2.model.TicketForm;
5051
import org.zendesk.client.v2.model.TicketImport;
5152
import org.zendesk.client.v2.model.TicketPage;
@@ -286,6 +287,42 @@ public ListenableFuture<JobStatus> importTicketsAsync(List<TicketImport> ticketI
286287
Collections.singletonMap("tickets", ticketImports))), handleJobStatus());
287288
}
288289

290+
public TicketCount getTicketsCount(){
291+
return complete(
292+
submit(
293+
req("GET", cnst("/tickets/count.json")),
294+
handle(TicketCount.class, "count")
295+
)
296+
);
297+
}
298+
299+
public TicketCount getTicketsCountForOrganization(long id){
300+
return complete(
301+
submit(
302+
req("GET", tmpl("/organizations/{id}/tickets/count.json").set("id", id)),
303+
handle(TicketCount.class, "count")
304+
)
305+
);
306+
}
307+
308+
public TicketCount getCcdTicketsCountForUser(long id){
309+
return complete(
310+
submit(
311+
req("GET", tmpl("/users/{id}/tickets/ccd/count.json").set("id", id)),
312+
handle(TicketCount.class, "count")
313+
)
314+
);
315+
}
316+
317+
public TicketCount getAssignedTicketsCountForUser(long id){
318+
return complete(
319+
submit(
320+
req("GET", tmpl("/users/{id}/tickets/assigned/count.json").set("id", id)),
321+
handle(TicketCount.class, "count")
322+
)
323+
);
324+
}
325+
289326
public Ticket getTicket(long id) {
290327
return complete(submit(req("GET", tmpl("/tickets/{id}.json").set("id", id)), handle(Ticket.class,
291328
"ticket")));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.util.Date;
7+
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class TicketCount {
10+
11+
private Long value;
12+
private Date refreshedAt;
13+
14+
public Long getValue() {
15+
return value;
16+
}
17+
18+
public void setValue(Long value) {
19+
this.value = value;
20+
}
21+
22+
@JsonProperty("refreshed_at")
23+
public Date getRefreshedAt() {
24+
return refreshedAt;
25+
}
26+
27+
public void setRefreshedAt(Date refreshedAt) {
28+
this.refreshedAt = refreshedAt;
29+
}
30+
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.zendesk.client.v2.model.Status;
3636
import org.zendesk.client.v2.model.SuspendedTicket;
3737
import org.zendesk.client.v2.model.Ticket;
38+
import org.zendesk.client.v2.model.TicketCount;
3839
import org.zendesk.client.v2.model.TicketForm;
3940
import org.zendesk.client.v2.model.TicketImport;
4041
import org.zendesk.client.v2.model.Trigger;
@@ -104,6 +105,7 @@ public class RealSmokeTest {
104105

105106
// TODO: Find a better way to manage our test environment (this is the PUBLIC_FORM_ID of the cloudbees org)
106107
private static final long CLOUDBEES_ORGANIZATION_ID = 360507899132L;
108+
private static final long USER_ID = 381626101132L; // Pierre B
107109
private static final long PUBLIC_FORM_ID = 360000434032L;
108110
private static final Random RANDOM = new Random();
109111
private static final String TICKET_COMMENT1 = "Please ignore this ticket";
@@ -185,6 +187,42 @@ public void getBrands() throws Exception {
185187
}
186188
}
187189

190+
@Test
191+
public void getTicketsCount() throws Exception {
192+
createClientWithTokenOrPassword();
193+
TicketCount ticketCount = instance.getTicketsCount();
194+
assertThat(ticketCount, notNullValue());
195+
assertThat(ticketCount.getValue(), greaterThan(0L));
196+
assertThat(ticketCount.getRefreshedAt(), notNullValue());
197+
}
198+
199+
@Test
200+
public void getTicketsCountForOrganization() throws Exception {
201+
createClientWithTokenOrPassword();
202+
TicketCount ticketCount = instance.getTicketsCountForOrganization(CLOUDBEES_ORGANIZATION_ID);
203+
assertThat(ticketCount, notNullValue());
204+
assertThat(ticketCount.getValue(), greaterThan(0L));
205+
assertThat(ticketCount.getRefreshedAt(), notNullValue());
206+
}
207+
208+
@Test
209+
public void getCcdTicketsCountForUser() throws Exception {
210+
createClientWithTokenOrPassword();
211+
TicketCount ticketCount = instance.getCcdTicketsCountForUser(USER_ID);
212+
assertThat(ticketCount, notNullValue());
213+
assertThat(ticketCount.getValue(), greaterThan(0L));
214+
assertThat(ticketCount.getRefreshedAt(), notNullValue());
215+
}
216+
217+
@Test
218+
public void getAssignedTicketsCountForUser() throws Exception {
219+
createClientWithTokenOrPassword();
220+
TicketCount ticketCount = instance.getAssignedTicketsCountForUser(USER_ID);
221+
assertThat(ticketCount, notNullValue());
222+
assertThat(ticketCount.getValue(), greaterThan(0L));
223+
assertThat(ticketCount.getRefreshedAt(), notNullValue());
224+
}
225+
188226
@Test
189227
public void getTicket() throws Exception {
190228
createClientWithTokenOrPassword();

0 commit comments

Comments
 (0)