Passed
Push — main ( 8785b1...fdb7a5 )
by Alexis
01:04
created

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