gamesheet_sdk.admin.shared

Admin-specific shared utilities.

Functions

build_invitation_code_lookup(body)

Build invitation code lookup from JSON:API included resources.

extract_relationship_id(item, relationship_name)

Safely extract ID from JSON:API relationship.

get_invitation_code_from_relationship(item, ...)

Extract invitation code from team's invitation relationship.

parse_jsonapi_resource(item[, relationship_map])

Parse a JSON:API resource into a flat dictionary.

gamesheet_sdk.admin.shared.build_invitation_code_lookup(body)[source]

Build invitation code lookup from JSON:API included resources.

Parses the included section of a JSON:API response to extract invitation codes keyed by invitation ID.

Parameters:

body (dict[str, Any]) – The JSON:API response body containing included resources.

Returns:

Dictionary mapping invitation IDs to invitation codes.

Return type:

dict[str, str]

gamesheet_sdk.admin.shared.extract_relationship_id(item, relationship_name, default='')[source]

Safely extract ID from JSON:API relationship.

JSON:API relationships follow the structure:

{
    "relationships": {
        "parent": {
            "data": {"id": "123", "type": "associations"}
        }
    }
}
Parameters:
  • item (dict[str, Any]) – The JSON:API resource object.

  • relationship_name (str) – Name of the relationship to extract.

  • default (str) – Default value if relationship not found.

Returns:

The relationship ID or default value.

Return type:

str

gamesheet_sdk.admin.shared.get_invitation_code_from_relationship(item, invitation_codes)[source]

Extract invitation code from team’s invitation relationship.

The invitations relationship can be either a single object or an array of objects.

Parameters:
  • item (dict[str, Any]) – The JSON:API team resource object.

  • invitation_codes (dict[str, str]) – Lookup dictionary from invitation IDs to codes.

Returns:

The invitation code if found, otherwise None.

Return type:

str | None

gamesheet_sdk.admin.shared.parse_jsonapi_resource(item, relationship_map=None)[source]

Parse a JSON:API resource into a flat dictionary.

Flattens a JSON:API resource object into a simple dict by merging the id, attributes, and optionally extracting relationship IDs.

JSON:API structure:

{
    "id": "123",
    "type": "leagues",
    "attributes": {"title": "NHL", ...},
    "relationships": {"association": {"data": {"id": "456"}}}
}

Result:

{"id": "123", "title": "NHL", "association_id": "456"}
Parameters:
  • item (dict[str, Any]) – JSON:API resource object.

  • relationship_map (dict[str, str] | None) – Maps relationship names to attribute keys. Example: {"association": "association_id"}.

Returns:

Flattened dict with id + attributes + relationship IDs.

Return type:

dict[str, Any]