Skip to content

Commit 67a3f37

Browse files
thewheatchoran
authored andcommitted
Add support for retrieving conversation tags (#156)
1 parent 992ead3 commit 67a3f37

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

intercom-java/src/main/java/io/intercom/api/Conversation.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ private static boolean isAdminQuery(Map<String, String> params) {
199199
@JsonProperty("conversation_parts")
200200
private ConversationPartCollection conversationPartCollection;
201201

202+
@JsonProperty("tags")
203+
private TagCollection tagCollection;
204+
202205
@JsonProperty("open")
203206
private boolean open;
204207

@@ -272,6 +275,14 @@ public ConversationPartCollection getConversationPartCollection() {
272275
return conversationPartCollection;
273276
}
274277

278+
public TagCollection getTagCollection() {
279+
if (tagCollection == null) {
280+
tagCollection = find(this.getId()).getTagCollection();
281+
}
282+
283+
return tagCollection;
284+
}
285+
275286
public boolean getOpen() {
276287
return open;
277288
}
@@ -296,6 +307,8 @@ public boolean equals(Object o) {
296307
return false;
297308
if (conversationPartCollection != null ? !conversationPartCollection.equals(that.conversationPartCollection) : that.conversationPartCollection != null)
298309
return false;
310+
if (tagCollection != null ? !tagCollection.equals(that.tagCollection) : that.tagCollection != null)
311+
return false;
299312
if (id != null ? !id.equals(that.id) : that.id != null) return false;
300313
if (links != null ? !links.equals(that.links) : that.links != null) return false;
301314
if (!type.equals(that.type)) return false;
@@ -315,6 +328,7 @@ public int hashCode() {
315328
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
316329
result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32));
317330
result = 31 * result + (conversationPartCollection != null ? conversationPartCollection.hashCode() : 0);
331+
result = 31 * result + (tagCollection != null ? tagCollection.hashCode() : 0);
318332
result = 31 * result + (open ? 1 : 0);
319333
result = 31 * result + (read ? 1 : 0);
320334
result = 31 * result + (links != null ? links.hashCode() : 0);
@@ -332,6 +346,7 @@ public String toString() {
332346
", createdAt=" + createdAt +
333347
", updatedAt=" + updatedAt +
334348
", conversationPartCollection=" + conversationPartCollection +
349+
", tagCollection=" + tagCollection +
335350
", open=" + open +
336351
", read=" + read +
337352
", links=" + links +

intercom-java/src/test/java/io/intercom/api/ConversationTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,51 @@ public void testGetEmptyConversationsPartFromConversationCollection() throws IOE
155155
Conversation.find(conversation.getId());
156156
}
157157

158+
@Test
159+
public void testGetTagsFromConversation() throws IOException {
160+
PowerMockito.mockStatic(Conversation.class);
161+
162+
String json = load("conversation.json");
163+
final Conversation conversation = objectMapper.readValue(json, Conversation.class);
164+
assertEquals(2, conversation.getTagCollection().getPage().size());
165+
166+
PowerMockito.verifyStatic(Mockito.never());
167+
Conversation.find(conversation.getId());
168+
}
169+
170+
@Test
171+
public void testGetTagFromTagCollection() throws IOException {
172+
PowerMockito.mockStatic(Conversation.class);
173+
174+
String conversationsJson = load("conversations.json");
175+
final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class);
176+
final Conversation conversation = conversationCollection.getPage().get(0);
177+
178+
String conversationJson = load("conversation.json");
179+
final Conversation conversationWithTags = objectMapper.readValue(conversationJson, Conversation.class);
180+
Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags);
181+
assertEquals(2, conversation.getTagCollection().getPage().size());
182+
183+
PowerMockito.verifyStatic(Mockito.times(1));
184+
Conversation.find(conversation.getId());
185+
}
186+
187+
@Test
188+
public void testGetEmptyTagFromTagCollection() throws IOException {
189+
PowerMockito.mockStatic(Conversation.class);
190+
191+
String conversationsJson = load("conversations.json");
192+
final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class);
193+
final Conversation conversation = conversationCollection.getPage().get(0);
194+
195+
String conversationJson = load("conversation_no_tags.json");
196+
final Conversation conversationWithTags= objectMapper.readValue(conversationJson, Conversation.class);
197+
Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags);
198+
assertEquals(0, conversation.getConversationPartCollection().getPage().size());
199+
200+
PowerMockito.verifyStatic(Mockito.times(1));
201+
Conversation.find(conversation.getId());
202+
}
158203
private Map<String, String> buildRequestParameters(String html) {
159204
Map<String, String> params2 = Maps.newHashMap();
160205
params2.put("type", "admin");

intercom-java/src/test/resources/conversation.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@
6565
"read": false,
6666
"tags": {
6767
"type": "tag.list",
68-
"tags": []
68+
"tags": [
69+
{
70+
"type": "tag",
71+
"id": "123",
72+
"name": "Tag 1"
73+
},
74+
{
75+
"type": "tag",
76+
"id": "456",
77+
"name": "Tag 2"
78+
}
79+
]
6980
}
7081
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"type": "conversation",
3+
"id": "5143511111",
4+
"created_at": 1466703132,
5+
"updated_at": 1468236397,
6+
"conversation_message": {
7+
"type": "conversation_message",
8+
"id": "33954111",
9+
"subject": "",
10+
"body": "<p>test</p>",
11+
"author": {
12+
"type": "lead",
13+
"id": "576c1a139d0baad1010011111"
14+
},
15+
"attachments": [],
16+
"url": null
17+
},
18+
"user": {
19+
"type": "user",
20+
"id": "576c1a139d0baad1010001111"
21+
},
22+
"assignee": {
23+
"type": "admin",
24+
"id": "358111"
25+
},
26+
"conversation_parts": {
27+
"type": "conversation_part.list",
28+
"conversation_parts": [],
29+
"total_count": 0
30+
},
31+
"open": true,
32+
"read": false,
33+
"tags": {
34+
"type": "tag.list",
35+
"tags": []
36+
}
37+
}

0 commit comments

Comments
 (0)