Passed
Pull Request — main (#329)
by
unknown
03:11
created

pincer._config.GatewayConfig.make_uri()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from dataclasses import dataclass
5
from typing import Optional
6
7
8
@dataclass(repr=False)
9
class GatewayConfig:
10
    """This file is to make maintaining the library and its gateway
11
    configuration easier.
12
    """
13
    MAX_RETRIES: int = 5
14
    version: int = 9
15
    encoding: str = "json"
16
    compression: Optional[str] = "zlib-stream"
17
18
    @classmethod
19
    def make_uri(cls, uri) -> str:
20
        """
21
        Returns
22
        -------
23
        :class:`str`:
24
            The GatewayConfig's uri.
25
        """
26
        return (
27
            f"{uri}"
28
            f"?v={cls.version}"
29
            f"&encoding={cls.encoding}"
30
        ) + f"&compress={cls.compression}" * cls.compressed()
31
32
    @classmethod
33
    def compressed(cls) -> bool:
34
        """
35
        Returns
36
        -------
37
        :class:`bool`:
38
            Whether the Gateway should compress payloads or not.
39
        """
40
        return cls.compression in ["zlib-stream", "zlib-payload"]
41