Skip to content

codingame_tools.client.service.services.survey

survey

Async Survey service endpoint.

CgSurveyServiceHelper

CgSurveyServiceHelper(service)

Bases: CgServiceHelper['CgSurveyService']

Helper methods for CgSurveyService. Currently empty.

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

CgSurveyService

CgSurveyService(client)

Bases: CgService

Async Survey service endpoint.

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

find_survey async

find_survey(codingamer_id=None, limit=2)

Find a survey to potentially show a codingamer.

UNVERIFIED: every account tested (including a couple of different real accounts) returned a bare null, so the real response shape (CgSurvey) is an empty placeholder pending a real example. limit's purpose is unconfirmed too--assumed (per the observed default value of 2) to cap the number of surveys returned, but this couldn't be verified empirically since no non-null response was ever observed.

Uses service_request (untyped JsonData) rather than service_request_to_dict, since the latter would reject the (apparently common) null response as an error.

Parameters:

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

    The codingamer to find a survey for. If not provided, defaults to the logged-in codingamer's ID.

  • limit (int, default: 2 ) –

    Assumed maximum number of results; unconfirmed. Defaults to 2 (the only value observed in practice).

Returns:

  • CgSurvey | None

    A CgSurvey object, or None if no survey is currently applicable.

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/survey.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
71
72
73
74
75
async def find_survey(
            self,
            codingamer_id: int | None = None,
            limit: int = 2,
        ) -> CgSurvey | None:
    """Find a survey to potentially show a codingamer.

       UNVERIFIED: every account tested (including a couple of different real accounts)
       returned a bare `null`, so the real response shape (`CgSurvey`) is an empty
       placeholder pending a real example. `limit`'s purpose is unconfirmed too--assumed
       (per the observed default value of 2) to cap the number of surveys returned, but this
       couldn't be verified empirically since no non-null response was ever observed.

       Uses `service_request` (untyped `JsonData`) rather than `service_request_to_dict`,
       since the latter would reject the (apparently common) `null` response as an error.

    Args:
        codingamer_id: The codingamer to find a survey for. If not provided, defaults to
                       the logged-in codingamer's ID.
        limit:         Assumed maximum number of results; unconfirmed. Defaults to 2 (the
                       only value observed in practice).

    Returns:
        A CgSurvey object, or None if no survey is currently applicable.

    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_survey = await self.service_request("findSurvey", [codingamer_id, limit])
    if raw_survey is None:
        return None
    if not isinstance(raw_survey, dict):
        raise CgClientHttpError(
                f"Invalid response type: expected a JSON dictionary or null, got {type(raw_survey).__name__}",
                content=raw_survey,
            )
    return CgSurvey.from_dict(raw_survey)