Source code for gamesheet_sdk.admin.games.completed
# Copyright (c) 2026 bdperkin
# SPDX-License-Identifier: MIT
"""Completed game operations."""
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING, Any
from gamesheet_sdk.common.constants import (
API_SEASONS_GAMES,
DEFAULT_BASE_URL,
SCORESHEET_SERVICE_BASE_URL,
SCORESHEET_SERVICE_GAME,
)
from gamesheet_sdk.common.shared import handle_response
if TYPE_CHECKING:
from gamesheet_sdk.common.session import Session
[docs]
def get_completed_game(
session: Session,
season_id: str,
game_id: str,
) -> dict[str, Any]:
"""Get a completed game with full details (JSON:API format).
Returns the full JSON:API response including rosters, goals, shots, penalties, and all related data. The
supplied :class:`Session` must already carry a bearer token (e.g. via :meth:`Session.set_bearer_token`);
the call is otherwise unauthenticated and will 401.
Args:
session (Session): An authenticated :class:`Session`.
season_id (str): The parent season identifier.
game_id (str): The game identifier to retrieve.
Returns:
dict[str, Any]: The full game data as a dictionary (JSON:API format with data/included/relationships).
"""
url = f"{DEFAULT_BASE_URL}{API_SEASONS_GAMES.format(season_id=season_id, game_id=game_id)}"
params = {"include": "players,coaches,referees,teams,season,association,league"}
response = session.get(url, params=params)
handle_response(response, url, "GET completed game")
body: dict[str, Any] = response.json()
return body
[docs]
def download_completed_game_pdf(
session: Session,
game_id: str,
output_path: str,
) -> None:
"""Download the PDF scoresheet for a completed game.
The supplied :class:`Session` must already carry a bearer token (e.g. via
:meth:`Session.set_bearer_token`); the call is otherwise unauthenticated and will 401.
Args:
session (Session): An authenticated :class:`Session`.
game_id (str): The game identifier.
output_path (str): File path where the PDF will be saved.
"""
url = f"{SCORESHEET_SERVICE_BASE_URL}{SCORESHEET_SERVICE_GAME.format(game_id=game_id)}"
response = session.get(url)
handle_response(response, url, "GET scoresheet PDF")
Path(output_path).write_bytes(response.content)