Skip to content

Commit c310651

Browse files
committed
Added methods for task related activity.
1 parent 8ddc56b commit c310651

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/main/java/com/aaroncoplan/todoist/Todoist.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,20 +382,44 @@ public void deleteComment(long id) {
382382

383383
public List<Activity> getActivityForTask(long id) {
384384
try {
385-
HttpResponse<String> response = Unirest.post(URL_BASE + "/activity/get")
386-
.header("Content-Type", "application/json")
387-
.body(new ActivityRequest(30, 0, Arrays.asList("item:", "note:added"), id))
388-
.asString();
389-
if(response.getStatus() != HTTP_OK) {
390-
throw new Exception("HTTP STATUS " + response.getStatus());
391-
}
385+
int limit = 30;
386+
int offset = 0;
387+
int count;
388+
389+
do {
390+
System.out.println(JsonAdapters.writeActivityRequest(new ActivityRequest(limit, offset, Arrays.asList("item:", "note:added"), id, true, true)));
391+
HttpResponse<String> response = Unirest.post("https://todoist.com/API/v8/activity/get")
392+
.header("Content-Type", "application/json")
393+
.body(JsonAdapters.writeActivityRequest(new ActivityRequest(limit, offset, Arrays.asList("item:", "note:added"), id, true, true)))
394+
/*.header("content-type", "application/x-www-form-urlencoded")
395+
.queryString("limit", limit)
396+
.queryString("offset", offset)
397+
.queryString("object_event_types", "[\"item:\", \"note:added\"]")
398+
.queryString("parent_item_id", id)
399+
.queryString("include_parent_object", true)
400+
.queryString("annotate_notes", true)*/
401+
.asString();
402+
if (response.getStatus() != HTTP_OK) {
403+
System.out.println(response.getBody());
404+
throw new Exception("HTTP STATUS " + response.getStatus());
405+
}
406+
System.out.println(response.getBody());
407+
ActivityResponse activityResponse = JsonAdapters.extractActivityResponse(response.getBody());
408+
count = activityResponse.count;
409+
410+
activityResponse.events.forEach(System.out::println);
411+
412+
offset += limit;
413+
} while(offset < count);
414+
415+
return null;
392416
} catch (Exception e) {
393417
e.printStackTrace();
394418
return null;
395419
}
396420
}
397421

398422
public List<Activity> getActivityForTask(long id, ActivityType... types) {
399-
423+
return null;
400424
}
401425
}

src/main/java/com/aaroncoplan/todoist/helpers/ActivityRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ public class ActivityRequest {
1010
public final int offset;
1111
@Json(name = "object_event_types") public final List<String> activityTypes;
1212
@Json(name = "parent_item_id") public final long parentItemId;
13+
@Json(name = "include_parent_object") public final boolean includeParentObject;
14+
@Json(name = "annotate_notes") public final boolean annotateNotes;
1315

14-
public ActivityRequest(int limit, int offset, List<String> activityTypes, long parentItemId) {
16+
public ActivityRequest(int limit, int offset, List<String> activityTypes, long parentItemId, boolean includeParentObject, boolean annotateNotes) {
1517
this.limit = limit;
1618
this.offset = offset;
1719
this.activityTypes = activityTypes;
1820
this.parentItemId = parentItemId;
21+
this.includeParentObject = includeParentObject;
22+
this.annotateNotes = annotateNotes;
1923
}
2024
}

0 commit comments

Comments
 (0)