|
1 | 1 | # -*- coding: utf-8 -*-
|
| 2 | +"""Service module for Conversations.""" |
2 | 3 |
|
3 | 4 | from intercom import conversation
|
4 | 5 | from intercom import utils
|
5 | 6 | from intercom.api_operations.find import Find
|
6 | 7 | from intercom.api_operations.find_all import FindAll
|
7 |
| -from intercom.api_operations.save import Save |
8 | 8 | from intercom.api_operations.load import Load
|
| 9 | +from intercom.api_operations.save import Save |
9 | 10 | from intercom.service.base_service import BaseService
|
10 | 11 |
|
11 | 12 |
|
12 | 13 | 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) |
13 | 20 |
|
14 | 21 | @property
|
15 | 22 | def collection_class(self):
|
| 23 | + """Return the class of the collection.""" |
16 | 24 | return conversation.Conversation
|
17 | 25 |
|
| 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 | + |
18 | 30 | def reply(self, **reply_data):
|
| 31 | + """Reply to a message.""" |
19 | 32 | return self.__reply(reply_data)
|
20 | 33 |
|
21 | 34 | def assign(self, **reply_data):
|
| 35 | + """Assign a conversation to a user.""" |
22 | 36 | reply_data['type'] = 'admin'
|
23 | 37 | reply_data['message_type'] = 'assignment'
|
24 | 38 | return self.__reply(reply_data)
|
25 | 39 |
|
26 | 40 | def open(self, **reply_data):
|
| 41 | + """Mark a conversation as open.""" |
27 | 42 | reply_data['type'] = 'admin'
|
28 | 43 | reply_data['message_type'] = 'open'
|
29 | 44 | return self.__reply(reply_data)
|
30 | 45 |
|
31 | 46 | def close(self, **reply_data):
|
| 47 | + """Mark a conversation as closed.""" |
32 | 48 | reply_data['type'] = 'admin'
|
33 | 49 | reply_data['message_type'] = 'close'
|
34 | 50 | return self.__reply(reply_data)
|
35 | 51 |
|
| 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 | + |
36 | 58 | def __reply(self, reply_data):
|
| 59 | + """Send requests to the resource handler.""" |
37 | 60 | _id = reply_data.pop('id')
|
38 |
| - collection = utils.resource_class_to_collection_name(self.collection_class) # noqa |
39 |
| - url = "/%s/%s/reply" % (collection, _id) |
40 | 61 | reply_data['conversation_id'] = _id
|
41 |
| - response = self.client.post(url, reply_data) |
| 62 | + response = self.client.post(self.resource_url(_id), reply_data) |
42 | 63 | 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