Skip to content

Commit fcffda4

Browse files
committed
Added ability to include attachments in comments.
1 parent 3e6a09a commit fcffda4

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package com.aaroncoplan.todoist;
22

3-
import com.aaroncoplan.todoist.helpers.CommentRequest;
4-
import com.aaroncoplan.todoist.helpers.LabelRequest;
5-
import com.aaroncoplan.todoist.helpers.ProjectRequest;
6-
import com.aaroncoplan.todoist.helpers.TaskRequest;
7-
import com.aaroncoplan.todoist.model.Comment;
8-
import com.aaroncoplan.todoist.model.Label;
9-
import com.aaroncoplan.todoist.model.Project;
10-
import com.aaroncoplan.todoist.model.Task;
3+
import com.aaroncoplan.todoist.helpers.*;
4+
import com.aaroncoplan.todoist.model.*;
115
import com.mashape.unirest.http.HttpResponse;
126
import com.mashape.unirest.http.Unirest;
137

@@ -315,11 +309,11 @@ public List<Comment> getAllCommentsForTask(long id) {
315309
}
316310
}
317311

318-
private Comment createNewComment(Long taskId, Long projectId, String content) {
312+
private Comment createNewComment(Long taskId, Long projectId, String content, AttachmentRequest attachmentRequest) {
319313
try {
320314
HttpResponse<String> response = Unirest.post(URL_BASE + "/comments")
321315
.header("Content-Type", "application/json")
322-
.body(JsonAdapters.writeCommentRequest(new CommentRequest(taskId, projectId, content, null)))
316+
.body(JsonAdapters.writeCommentRequest(new CommentRequest(taskId, projectId, content, attachmentRequest)))
323317
.asString();
324318
if(response.getStatus() != HTTP_OK) {
325319
throw new Exception("HTTP STATUS " + response.getStatus());
@@ -332,10 +326,18 @@ private Comment createNewComment(Long taskId, Long projectId, String content) {
332326
}
333327

334328
public Comment createNewCommentForTask(long id, String content) {
335-
return createNewComment(id, null, content);
329+
return createNewComment(id, null, content, null);
330+
}
331+
332+
public Comment createNewCommentForTask(long id, String content, AttachmentRequest attachmentRequest) {
333+
return createNewComment(id, null, content, attachmentRequest);
336334
}
337335

338336
public Comment createNewCommentForProject(long id, String content) {
339-
return createNewComment(null, id, content);
337+
return createNewComment(null, id, content, null);
338+
}
339+
340+
public Comment createNewCommentForProject(long id, String content, AttachmentRequest attachmentRequest) {
341+
return createNewComment(null, id, content, attachmentRequest);
340342
}
341343
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public class CommentRequest {
77
@Json(name = "task_id") public final Long taskId;
88
@Json(name = "project_id") public final Long projectId;
99
public final String content;
10-
public final AttachmentRequest attachmentRequest;
10+
public final AttachmentRequest attachment;
1111

12-
public CommentRequest(Long taskId, Long projectId, String content, AttachmentRequest attachmentRequest) {
12+
public CommentRequest(Long taskId, Long projectId, String content, AttachmentRequest attachment) {
1313
this.taskId = taskId;
1414
this.projectId = projectId;
1515
this.content = content;
16-
this.attachmentRequest = attachmentRequest;
16+
this.attachment = attachment;
1717
}
1818
}

0 commit comments

Comments
 (0)