Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7015d8

Browse files
authored
Merge pull request #136 from jkeyes/review-conversation
Add support for conversations.mark_read.
2 parents 42cf583 + 373d8c2 commit a7015d8

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

intercom/conversation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
2+
"""Collection module for Conversations."""
33
from intercom.traits.api_resource import Resource
44

55

66
class Conversation(Resource):
7-
pass
7+
"""Collection class for Converations."""

intercom/service/conversation.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,63 @@
11
# -*- coding: utf-8 -*-
2+
"""Service module for Conversations."""
23

34
from intercom import conversation
45
from intercom import utils
56
from intercom.api_operations.find import Find
67
from intercom.api_operations.find_all import FindAll
7-
from intercom.api_operations.save import Save
88
from intercom.api_operations.load import Load
9+
from intercom.api_operations.save import Save
910
from intercom.service.base_service import BaseService
1011

1112

1213
class Conversation(BaseService, Find, FindAll, Save, Load):
14+
"""Service class for Conversations."""
15+
16+
@property
17+
def collection(self):
18+
"""Return the name of the collection."""
19+
return utils.resource_class_to_collection_name(self.collection_class)
1320

1421
@property
1522
def collection_class(self):
23+
"""Return the class of the collection."""
1624
return conversation.Conversation
1725

26+
def resource_url(self, _id):
27+
"""Return the URL for the specified resource in this collection."""
28+
return "/%s/%s/reply" % (self.collection, _id)
29+
1830
def reply(self, **reply_data):
31+
"""Reply to a message."""
1932
return self.__reply(reply_data)
2033

2134
def assign(self, **reply_data):
35+
"""Assign a conversation to a user."""
2236
reply_data['type'] = 'admin'
2337
reply_data['message_type'] = 'assignment'
2438
return self.__reply(reply_data)
2539

2640
def open(self, **reply_data):
41+
"""Mark a conversation as open."""
2742
reply_data['type'] = 'admin'
2843
reply_data['message_type'] = 'open'
2944
return self.__reply(reply_data)
3045

3146
def close(self, **reply_data):
47+
"""Mark a conversation as closed."""
3248
reply_data['type'] = 'admin'
3349
reply_data['message_type'] = 'close'
3450
return self.__reply(reply_data)
3551

52+
def mark_read(self, _id):
53+
"""Mark a conversation as read."""
54+
data = {'read': True}
55+
response = self.client.put(self.resource_url(_id), data)
56+
return self.collection_class().from_response(response)
57+
3658
def __reply(self, reply_data):
59+
"""Send requests to the resource handler."""
3760
_id = reply_data.pop('id')
38-
collection = utils.resource_class_to_collection_name(self.collection_class) # noqa
39-
url = "/%s/%s/reply" % (collection, _id)
4061
reply_data['conversation_id'] = _id
41-
response = self.client.post(url, reply_data)
62+
response = self.client.post(self.resource_url(_id), reply_data)
4263
return self.collection_class().from_response(response)
43-
44-
45-
# def mark_read(id)
46-
# @client.put("/conversations/#{id}", read: true)
47-
# end

0 commit comments

Comments
 (0)