diff --git a/intercom-java/src/main/java/io/intercom/api/Attachment.java b/intercom-java/src/main/java/io/intercom/api/Attachment.java new file mode 100644 index 00000000..86af659a --- /dev/null +++ b/intercom-java/src/main/java/io/intercom/api/Attachment.java @@ -0,0 +1,100 @@ +package io.intercom.api; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@SuppressWarnings("UnusedDeclaration") +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_DEFAULT) +public class Attachment extends TypedData { + + @JsonProperty("type") + private final String type = "upload"; + @JsonProperty("name") + private String name; + @JsonProperty("url") + private String url; + @JsonProperty("content_type") + private String contentType; + @JsonProperty("filesize") + private long filesize; + @JsonProperty("width") + private long width; + @JsonProperty("height") + private long height; + + public Attachment() { + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } + + public String getUrl() { + return url; + } + + public String getContentType() { + return contentType; + } + + public long getFilesize() { + return filesize; + } + + public long getWidth() { + return width; + } + + public long getHeight() { + return height; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Attachment attachment = (Attachment) o; + + if (name != null ? !name.equals(attachment.name) : attachment.name != null) return false; + if (url != null ? !url.equals(attachment.url) : attachment.url != null) return false; + if (contentType != null ? !contentType.equals(attachment.contentType) : attachment.contentType != null) return false; + if (filesize != attachment.filesize) return false; + if (height != attachment.height) return false; + if (width != attachment.width) return false; + + return true; + } + + @Override + public int hashCode() { + int result = type.hashCode(); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (url != null ? url.hashCode() : 0); + result = 31 * result + (contentType != null ? contentType.hashCode() : 0); + result = 31 * result + (int) (filesize ^ (filesize >>> 32)); + result = 31 * result + (int) (height ^ (height>>> 32)); + result = 31 * result + (int) (width ^ (width>>> 32)); + return result; + } + + @Override + public String toString() { + return "Avatar{" + + "type='" + type + '\'' + + ", name='" + name + '\'' + + ", url='" + url + '\'' + + ", content_type'=" + contentType + '\'' + + ", filesize=" + filesize + + ", height=" + height + + ", widht=" + width + + "} " + super.toString(); + } +} diff --git a/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java b/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java index 328a7b3b..54c909b4 100644 --- a/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java +++ b/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + @SuppressWarnings("UnusedDeclaration") @JsonIgnoreProperties(ignoreUnknown = true) public class ConversationMessage extends TypedData { @@ -11,6 +13,9 @@ public class ConversationMessage extends TypedData { @JsonProperty("type") private final String type = "conversation_message"; + @JsonProperty + private String id; + @JsonProperty private String subject; @@ -20,6 +25,12 @@ public class ConversationMessage extends TypedData { @JsonProperty private Author author; + @JsonProperty + private String url; + + @JsonProperty("attachments") + private List attachments; + public ConversationMessage() { } @@ -27,6 +38,10 @@ public String getType() { return type; } + public String getId() { + return id; + } + public String getSubject() { return subject; } @@ -39,11 +54,23 @@ public Author getAuthor() { return author; } + public String getUrl() { + return url; + } + + public List getAttachments() { + return attachments; + } + @Override public int hashCode() { int result = subject != null ? subject.hashCode() : 0; result = 31 * result + (body != null ? body.hashCode() : 0); result = 31 * result + (author != null ? author.hashCode() : 0); + result = 31 * result + (id != null ? id.hashCode() : 0); + result = 31 * result + (url != null ? url.hashCode() : 0); + result = 31 * result + (attachments != null ? attachments.hashCode() : 0); + return result; } @@ -58,6 +85,9 @@ public boolean equals(Object o) { if (body != null ? !body.equals(that.body) : that.body != null) return false; //noinspection RedundantIfStatement if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false; + if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (url != null ? !url.equals(that.url) : that.url != null) return false; + if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false; return true; } @@ -66,9 +96,12 @@ public boolean equals(Object o) { public String toString() { return "ConversationMessage{" + "type='" + type + '\'' + + ", id='" + id + '\'' + ", subject='" + subject + '\'' + ", body='" + body + '\'' + ", author=" + author + + ", url=" + url + + ", attachments=" + attachments + "} " + super.toString(); } } diff --git a/intercom-java/src/test/java/io/intercom/api/ConversationTest.java b/intercom-java/src/test/java/io/intercom/api/ConversationTest.java index 78e9ad6a..6b6403bc 100644 --- a/intercom-java/src/test/java/io/intercom/api/ConversationTest.java +++ b/intercom-java/src/test/java/io/intercom/api/ConversationTest.java @@ -109,6 +109,68 @@ public void testDisplayAs() { } } + @Test + public void testGetConversationMessageDetailsFromConversation() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + final ConversationMessage conversationMessage = conversation.getConversationMessage(); + + assertEquals("33954111", conversationMessage.getId()); + assertEquals("

test

", conversationMessage.getBody()); + assertEquals("Email subject", conversationMessage.getSubject()); + assertEquals("https://intercom.com/", conversationMessage.getUrl()); + + assertEquals("lead", conversationMessage.getAuthor().getType()); + assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); + + assertEquals(2, conversationMessage.getAttachments().size()); + + final Attachment firstAttachment = conversationMessage.getAttachments().get(0); + final Attachment lastAttachment = conversationMessage.getAttachments().get(1); + assertEquals("upload", firstAttachment.getType()); + assertEquals("123.csv", firstAttachment.getName()); + assertEquals("https://downloads.intercomcdn.com/123.csv", firstAttachment.getUrl()); + assertEquals("text/csv", firstAttachment.getContentType()); + assertEquals(147, firstAttachment.getFilesize()); + assertEquals(0, firstAttachment.getWidth()); + assertEquals(0, firstAttachment.getHeight()); + + assertEquals("upload", lastAttachment.getType()); + assertEquals("abc.txt", lastAttachment.getName()); + assertEquals("https://downloads.intercomcdn.com/txt", lastAttachment.getUrl()); + assertEquals("text/csv", lastAttachment.getContentType()); + assertEquals(100, lastAttachment.getFilesize()); + assertEquals(1, lastAttachment.getWidth()); + assertEquals(2, lastAttachment.getHeight()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetConversationMessageDetailsFromConversationNoAttachments() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation_no_attachments.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + final ConversationMessage conversationMessage = conversation.getConversationMessage(); + + assertEquals("33954111", conversationMessage.getId()); + assertEquals("

test

", conversationMessage.getBody()); + assertEquals("Email subject", conversationMessage.getSubject()); + assertEquals("https://intercom.com/", conversationMessage.getUrl()); + + assertEquals("lead", conversationMessage.getAuthor().getType()); + assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); + + assertEquals(0, conversationMessage.getAttachments().size()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + @Test public void testGetConversationsPartFromConversation() throws IOException { PowerMockito.mockStatic(Conversation.class); @@ -207,4 +269,4 @@ private Map buildRequestParameters(String html) { params2.put("display_as", html); return params2; } -} \ No newline at end of file +} diff --git a/intercom-java/src/test/resources/conversation.json b/intercom-java/src/test/resources/conversation.json index 94e879c4..03ef074e 100644 --- a/intercom-java/src/test/resources/conversation.json +++ b/intercom-java/src/test/resources/conversation.json @@ -7,14 +7,30 @@ "conversation_message": { "type": "conversation_message", "id": "33954111", - "subject": "", + "subject": "Email subject", "body": "

test

", "author": { "type": "lead", "id": "576c1a139d0baad1010011111" }, - "attachments": [], - "url": null + "attachments": [{ + "type": "upload", + "name": "123.csv", + "url": "https://downloads.intercomcdn.com/123.csv", + "content_type": "text/csv", + "filesize": 147, + "width": null, + "height": null + },{ + "type": "upload", + "name": "abc.txt", + "url": "https://downloads.intercomcdn.com/txt", + "content_type": "text/csv", + "filesize": 100, + "width": 1, + "height": 2 + }], + "url": "https://intercom.com/" }, "user": { "type": "user", diff --git a/intercom-java/src/test/resources/conversation_no_attachments.json b/intercom-java/src/test/resources/conversation_no_attachments.json new file mode 100644 index 00000000..1881bd7e --- /dev/null +++ b/intercom-java/src/test/resources/conversation_no_attachments.json @@ -0,0 +1,82 @@ +{ + "type": "conversation", + "id": "5143511111", + "created_at": 1466703132, + "updated_at": 1468236397, + "waiting_since": 1468236397, + "conversation_message": { + "type": "conversation_message", + "id": "33954111", + "subject": "Email subject", + "body": "

test

", + "author": { + "type": "lead", + "id": "576c1a139d0baad1010011111" + }, + "attachments": [], + "url": "https://intercom.com/" + }, + "user": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "assignee": { + "type": "admin", + "id": "358111" + }, + "conversation_parts": { + "type": "conversation_part.list", + "conversation_parts": [ + { + "type": "conversation_part", + "id": "142533411", + "part_type": "comment", + "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", + "created_at": 1468031160, + "updated_at": 1468031160, + "notified_at": 1468031160, + "assigned_to": null, + "author": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "attachments": [], + "external_id": null + }, + { + "type": "conversation_part", + "id": "142533511", + "part_type": "comment", + "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", + "created_at": 1468031171, + "updated_at": 1468031171, + "notified_at": 1468031171, + "assigned_to": null, + "author": { + "type": "admin", + "id": "358111" + }, + "attachments": [], + "external_id": null + } + ], + "total_count": 2 + }, + "open": true, + "read": false, + "tags": { + "type": "tag.list", + "tags": [ + { + "type": "tag", + "id": "123", + "name": "Tag 1" + }, + { + "type": "tag", + "id": "456", + "name": "Tag 2" + } + ] + } +}