Skip to content

Commit 17d8e5b

Browse files
committed
Add support for the export API to search tickets
1 parent 44ec477 commit 17d8e5b

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,13 @@ public Iterable<Ticket> getTicketsFromSearch(String searchTerm) {
558558
handleList(Ticket.class, "results"));
559559
}
560560

561+
public Iterable<Ticket> getTicketFromSearchWithExport(String searchTerm) {
562+
return new PagedIterable<>(
563+
tmpl(cbp("/search/export", true).toString() + "&filter[type]=ticket&query={query}")
564+
.set("query", searchTerm + " type:ticket"),
565+
handleList(Ticket.class, "results"));
566+
}
567+
561568
public Iterable<Article> getArticleFromSearch(String searchTerm) {
562569
return new PagedIterable<>(
563570
tmpl("/help_center/articles/search.json{?query}").set("query", searchTerm),
@@ -3862,11 +3869,16 @@ private TemplateUri tmpl(String template) {
38623869
}
38633870

38643871
private TemplateUri cbp(String path) {
3872+
return cbp(path, false);
3873+
}
3874+
3875+
private TemplateUri cbp(String path, boolean noDomain) {
38653876
Objects.requireNonNull(path, "Path cannot be null");
38663877
if (path.indexOf('?') != -1) {
38673878
throw new IllegalArgumentException("Path cannot contain a query string");
38683879
}
3869-
return new TemplateUri(url + path + "?page[size]={pageSize}").set("pageSize", cbpPageSize);
3880+
return new TemplateUri((noDomain ? "" : url) + path + "?page[size]={pageSize}")
3881+
.set("pageSize", cbpPageSize);
38703882
}
38713883

38723884
private Uri cnst(String template) {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,36 @@ public void getTicketsFromSearch() throws Exception {
27982798
}
27992799
}
28002800

2801+
@Test
2802+
public void getTicketFromSearchWithExport() throws Exception {
2803+
createClientWithTokenOrPassword();
2804+
2805+
Ticket t = newTestTicket();
2806+
t.setRequester(new Ticket.Requester("a name", "email+alias@acme.org"));
2807+
Ticket ticket = null;
2808+
try {
2809+
ticket = instance.createTicket(t);
2810+
// according to the doc, it takes about 1 minute for the ticket to be indexed
2811+
// running several time, it seems that the actual value is around 30-40s
2812+
Awaitility.with()
2813+
.pollDelay(20, SECONDS)
2814+
.and()
2815+
.pollInterval(10, SECONDS)
2816+
.await()
2817+
.timeout(90, SECONDS)
2818+
.until(
2819+
() -> {
2820+
Iterable<Ticket> tickets =
2821+
instance.getTicketFromSearchWithExport("requester:email+alias@acme.org");
2822+
return StreamSupport.stream(tickets.spliterator(), false).findAny().isPresent();
2823+
});
2824+
} finally {
2825+
if (ticket != null) {
2826+
instance.deleteTicket(ticket.getId());
2827+
}
2828+
}
2829+
}
2830+
28012831
@Test
28022832
public void getUnresolvedViewReturnsANewlyCreatedTicket() throws Exception {
28032833
createClientWithTokenOrPassword();

0 commit comments

Comments
 (0)