| Total Complexity | 5 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| 1 | from lib.actions import BaseAction |
||
| 4 | class GetConversations(BaseAction): |
||
| 5 | CHANNEL = { |
||
| 6 | 1: 'email', |
||
| 7 | 2: 'twitter', |
||
| 8 | 3: 'facebook', |
||
| 9 | 6: 'chat', |
||
| 10 | } |
||
| 11 | |||
| 12 | STATUS = { |
||
| 13 | 0: 'unresolved', |
||
| 14 | 1: 'pending', |
||
| 15 | 2: 'resolved', |
||
| 16 | 3: 'spam', |
||
| 17 | 4: 'archived', |
||
| 18 | } |
||
| 19 | |||
| 20 | def run(self, filter_issues='open', sort='create_at', email=None, tag=None, data=None): |
||
| 21 | params = { |
||
| 22 | 'filter': filter_issues, |
||
| 23 | 'sort': sort, |
||
| 24 | } |
||
| 25 | if email: |
||
| 26 | params['email'] = email |
||
| 27 | if tag: |
||
| 28 | params['tag'] = tag |
||
| 29 | if data: |
||
| 30 | params['data'] = data |
||
| 31 | |||
| 32 | response = self._api_get('/conversations', params=params) |
||
| 33 | conversations = response['conversations'] |
||
| 34 | |||
| 35 | filtered_conversations = map(filter_conversation, conversations) |
||
| 36 | return filtered_conversations |
||
| 37 | |||
| 38 | @staticmethod |
||
| 39 | def filter_conversation(conversation): |
||
| 40 | filtered_channel = GetConversation.CHANNEL[conversation["channel"]] |
||
| 41 | filtered_status = GetConversation.STATUS[conversation["status"]] |
||
| 42 | conversation["channel_name"] = filtered_channel |
||
| 43 | conversation["status_name"] = filtered_status |
||
| 44 | |||
| 45 | return conversation |
||
| 46 |