Skip to content

Commit d66200c

Browse files
committed
Merge pull request cloudbees-oss#68 from matthewtckr/incremental
Incremental Export Users and Organizations
2 parents 443ae84 + 5a31d58 commit d66200c

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Here is the status of the various API components:
3434

3535
* [Tickets](http://developer.zendesk.com/documentation/rest_api/tickets.html)
3636
* [Ticket Audits](http://developer.zendesk.com/documentation/rest_api/ticket_audits.html)
37-
* [Incremental Export](https://developer.zendesk.com/rest_api/docs/core/incremental_export) - Partial (ticket only)
37+
* [Incremental Export](https://developer.zendesk.com/rest_api/docs/core/incremental_export) - Partial (tickets, users, organizations only)
3838
* [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)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,12 @@ public Iterable<User> getUsersByRole(String role, String... roles) {
595595
return new PagedIterable<User>(cnst(uriBuilder.toString()), handleList(User.class, "users"));
596596
}
597597

598+
public Iterable<User> getUsersIncrementally(Date startTime) {
599+
return new PagedIterable<User>(
600+
tmpl("/incremental/users.json{?start_time}").set("start_time", msToSeconds(startTime.getTime())),
601+
handleIncrementalList(User.class, "users"));
602+
}
603+
598604
public Iterable<User> getGroupUsers(long id) {
599605
return new PagedIterable<User>(tmpl("/groups/{id}/users.json").set("id", id), handleList(User.class, "users"));
600606
}
@@ -888,6 +894,12 @@ public Iterable<Organization> getOrganizations() {
888894
handleList(Organization.class, "organizations"));
889895
}
890896

897+
public Iterable<Organization> getOrganizationsIncrementally(Date startTime) {
898+
return new PagedIterable<Organization>(
899+
tmpl("/incremental/users.json{?start_time}").set("start_time", msToSeconds(startTime.getTime())),
900+
handleIncrementalList(Organization.class, "users"));
901+
}
902+
891903
public Iterable<OrganizationField> getOrganizationFields() {
892904
//The organization_fields api doesn't seem to support paging
893905
return complete(submit(req("GET", cnst("/organization_fields.json")),

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.Arrays;
2525
import java.util.Collections;
26+
import java.util.Date;
2627
import java.util.List;
2728
import java.util.HashMap;
2829
import java.util.Properties;
@@ -157,6 +158,7 @@ public void getTargets() throws Exception {
157158
}
158159

159160
@Test
161+
@Ignore("Needs test data setup correctly")
160162
public void getTicketsPagesRequests() throws Exception {
161163
createClientWithTokenOrPassword();
162164
int count = 0;
@@ -195,6 +197,18 @@ public void getTicketsById() throws Exception {
195197
assertThat(count, is(16L));
196198
}
197199

200+
@Test
201+
public void getTicketsIncrementally() throws Exception {
202+
createClientWithTokenOrPassword();
203+
int count = 0;
204+
for (Ticket t : instance.getTicketsIncrementally(new Date(0L))) {
205+
assertThat(t.getId(), notNullValue());
206+
if (++count > 10) {
207+
break;
208+
}
209+
}
210+
}
211+
198212
@Test
199213
public void getTicketAudits() throws Exception {
200214
createClientWithTokenOrPassword();
@@ -347,6 +361,30 @@ public void getUserRequests() throws Exception {
347361
}
348362
}
349363

364+
@Test
365+
public void getUsers() throws Exception {
366+
createClientWithTokenOrPassword();
367+
int count = 0;
368+
for (User u : instance.getUsers()) {
369+
assertThat(u.getName(), notNullValue());
370+
if (++count > 10) {
371+
break;
372+
}
373+
}
374+
}
375+
376+
@Test
377+
public void getUsersIncrementally() throws Exception {
378+
createClientWithTokenOrPassword();
379+
int count = 0;
380+
for (User u : instance.getUsersIncrementally(new Date(0L))) {
381+
assertThat(u.getName(), notNullValue());
382+
if (++count > 10) {
383+
break;
384+
}
385+
}
386+
}
387+
350388
@Test
351389
public void getOrganizations() throws Exception {
352390
createClientWithTokenOrPassword();
@@ -359,6 +397,18 @@ public void getOrganizations() throws Exception {
359397
}
360398
}
361399

400+
@Test
401+
public void getOrganizationsIncrementally() throws Exception {
402+
createClientWithTokenOrPassword();
403+
int count = 0;
404+
for (Organization t : instance.getOrganizationsIncrementally(new Date(0L))) {
405+
assertThat(t.getName(), notNullValue());
406+
if (++count > 10) {
407+
break;
408+
}
409+
}
410+
}
411+
362412
@Test
363413
public void createOrganization() throws Exception {
364414
createClientWithTokenOrPassword();

0 commit comments

Comments
 (0)