Completed
Pull Request — master (#344)
by James
02:01
created

GetConversations   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %
Metric Value
dl 0
loc 42
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 17 4
A filter_conversation() 0 8 1
1
from lib.actions import BaseAction
2
3
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(self.filter_conversation, conversations)
36
        return filtered_conversations
37
38
    @staticmethod
39
    def filter_conversation(conversation):
40
        filtered_channel = GetConversations.CHANNEL[conversation["category"]["channel"]]
41
        filtered_status = GetConversations.STATUS[conversation["status"]]
42
        conversation["channel_name"] = filtered_channel
43
        conversation["status_name"] = filtered_status
44
45
        return conversation
46