Passed
Branch test (567fee)
by Alexis
01:21
created

replies.Replies.create()   B

Complexity

Conditions 7

Size

Total Lines 30
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 25
nop 10
dl 0
loc 30
rs 7.8799
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
from base import *
2
3
# =======================================================
4
# Replies
5
# =======================================================
6
class Replies(Resource):
7
    def fetch(self,
8
              ticket_id: int):
9
        return self._get("/tickets/{ticket_id}/replies".format(ticket_id=ticket_id))
10
11
    def create(self,
12
               ticket_id:          int,
13
               content:            str,
14
               cc:                 str  = None,
15
               bcc:                str  = None,
16
               attachment_ids:     str  = None,
17
               on_behalf_of_id:    str  = None,
18
               on_behalf_of_email: str  = None,
19
               notify_requester:   str  = False,
20
               content_as_html:    bool = False):
21
        reply = {
22
            "content": {
23
                "html" if content_as_html else "text": content,
24
            },
25
            "notify_requester": notify_requester
26
        }
27
28
        if cc is not None:
29
            reply["cc"] = cc
30
        if bcc is not None:
31
            reply["bcc"] = bcc
32
        if attachment_ids is not None:
33
            reply["content"]["attachment_ids"] = attachment_ids
34
35
        if on_behalf_of_id is not None:
36
            reply["on_behalf_of"] = {"id": on_behalf_of_id}
37
        elif on_behalf_of_email is not None:
38
            reply["on_behalf_of"] = {"email": on_behalf_of_email}
39
40
        return self._post("/tickets/{ticket_id}/replies".format(ticket_id=ticket_id), data={"reply": reply})
41
42
    def get(self,
43
            ticket_id: int,
44
            reply_id:  int):
45
        return self._get("/tickets/{ticket_id}/replies/{reply_id}".format(ticket_id=ticket_id, reply_id=reply_id))
46
47