Skip to content

codingame_tools.client.service.services.clash_of_code

clash_of_code

Async ClashOfCode service endpoint.

CgClashOfCodeServiceHelper

CgClashOfCodeServiceHelper(service)

Bases: CgServiceHelper['CgClashOfCodeService']

Helper methods for CgClashOfCodeService. Currently empty.

Source code in codingame_tools/client/service/cg_service.py
124
125
def __init__(self, service: TService) -> None:
    self.service = service

CgClashOfCodeService

CgClashOfCodeService(client)

Bases: CgService

Async ClashOfCode service endpoint.

Source code in codingame_tools/client/service/services/clash_of_code.py
24
25
26
def __init__(self, client: CgClient) -> None:
    super().__init__(client, "ClashOfCode")
    self.helper = CgClashOfCodeServiceHelper(self)

get_clash_rank_by_codingamer_id async

get_clash_rank_by_codingamer_id(codingamer_id=None)

Get a codingamer's global Clash of Code ranking.

Returns None if the codingamer has never played Clash of Code--the server responds with a genuine (not an error) JSON null in that case, rather than 404 or an empty dict. This uses service_request (untyped JsonData) rather than service_request_to_dict, since the latter would reject a null response as an error--there would be no way to distinguish "no rank" from an actual failure.

Parameters:

  • codingamer_id (int | None, default: None ) –

    The codingamer's numeric ID. If not provided, defaults to the logged-in codingamer's ID.

Returns:

  • CgClashRank | None

    A CgClashRank object, or None if the codingamer has never played Clash of Code.

Raises:

  • CgAuthenticationError

    If the session is not authenticated and cannot implicitly login, or if codingamer_id is not provided and no codingamer ID can be resolved from the session's credentials.

  • CgClientHttpError

    If a transport error occurs, if the response content could not be decoded at all, if the status code is not 2xx, or if the decoded content is neither a dict nor null.

Source code in codingame_tools/client/service/services/clash_of_code.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
async def get_clash_rank_by_codingamer_id(
            self,
            codingamer_id: int | None = None,
        ) -> CgClashRank | None:
    """Get a codingamer's global Clash of Code ranking.

       Returns None if the codingamer has never played Clash of Code--the server responds
       with a genuine (not an error) JSON `null` in that case, rather than 404 or an empty
       dict. This uses `service_request` (untyped `JsonData`) rather than
       `service_request_to_dict`, since the latter would reject a `null` response as an
       error--there would be no way to distinguish "no rank" from an actual failure.

    Args:
        codingamer_id: The codingamer's numeric ID. If not provided, defaults to the
                       logged-in codingamer's ID.

    Returns:
        A CgClashRank object, or None if the codingamer has never played Clash of Code.

    Raises:
        CgAuthenticationError:
            If the session is not authenticated and cannot implicitly login, or if
            `codingamer_id` is not provided and no codingamer ID can be resolved from the
            session's credentials.
        CgClientHttpError:
            If a transport error occurs, if the response content could not be decoded at all,
            if the status code is not 2xx, or if the decoded content is neither a dict nor null.
    """
    if codingamer_id is None:
        await self.require_authenticate()
        codingamer_id = self.client.codingamer_id
        if codingamer_id is None:
            raise CgAuthenticationError()
    raw_rank = await self.service_request(
            "getClashRankByCodinGamerId", [codingamer_id])
    if raw_rank is None:
        return None
    if not isinstance(raw_rank, dict):
        raise CgClientHttpError(
                f"Invalid response type: expected a JSON dictionary or null, got {type(raw_rank).__name__}",
                content=raw_rank,
            )
    return CgClashRank.from_dict(raw_rank)

find_clash_by_handle async

find_clash_by_handle(handle)

Find a Clash of Code session by its handle.

handle must be a clash-instance handle (e.g. a CgClashSlot.clash_handle from FeaturedEvent/findClashSlots)--confirmed empirically, neither a codingamer's public handle nor the parent CgFeaturedEvent.handle are accepted here (both rejected with a 422).

Parameters:

  • handle (str) –

    The opaque clash-instance handle string.

Returns:

Raises:

  • CgAuthenticationError

    If the session is not authenticated and cannot implicitly login.

  • CgClientHttpError

    If a transport error occurs, if the response content could not be decoded at all, if the status code is not 2xx, or if the decoded content is not a dict.

Source code in codingame_tools/client/service/services/clash_of_code.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
async def find_clash_by_handle(
            self,
            handle: str,
        ) -> CgClash:
    """Find a Clash of Code session by its handle.

       `handle` must be a clash-instance handle (e.g. a `CgClashSlot.clash_handle` from
       FeaturedEvent/findClashSlots)--confirmed empirically, neither a codingamer's public
       handle nor the parent `CgFeaturedEvent.handle` are accepted here (both rejected with
       a 422).

    Args:
        handle: The opaque clash-instance handle string.

    Returns:
        A CgClash object.

    Raises:
        CgAuthenticationError:
            If the session is not authenticated and cannot implicitly login.
        CgClientHttpError:
            If a transport error occurs, if the response content could not be decoded at all,
            if the status code is not 2xx, or if the decoded content is not a dict.
    """
    raw_clash = await self.service_request_to_dict("findClashByHandle", [handle])
    return CgClash.from_dict(raw_clash)