utils
utils
¶
Utility functions for cocapi
clean_tag
¶
clean_tag(tag: str) -> str
Remove # prefix from clan/player tags if present
Source code in cocapi/utils.py
9 10 11 | |
build_url
¶
build_url(
base_url: str,
endpoint: str,
params: dict[str, Any] | None = None,
) -> str
Build a complete URL with parameters
Source code in cocapi/utils.py
14 15 16 17 18 19 20 21 22 23 24 | |
validate_params
¶
validate_params(
params: dict[str, Any] | None,
valid_params: tuple[str, ...],
) -> bool
Validate that all parameters are in the allowed list
Source code in cocapi/utils.py
27 28 29 30 31 32 33 | |
get_cache_key
¶
get_cache_key(
url: str, params: dict[str, Any] | None = None
) -> str
Generate a cache key from URL and parameters
Source code in cocapi/utils.py
36 37 38 39 40 41 42 | |
is_successful_response
¶
is_successful_response(status_code: int) -> bool
Check if HTTP status code indicates success
Source code in cocapi/utils.py
45 46 47 | |
should_retry_error
¶
should_retry_error(status_code: int) -> bool
Determine if an HTTP error should be retried
Source code in cocapi/utils.py
50 51 52 | |
extract_items
¶
extract_items(result: Any) -> list[Any]
Extract items list from a paginated API response (dict or Pydantic model).
Source code in cocapi/utils.py
55 56 57 58 59 | |
extract_after_cursor
¶
extract_after_cursor(result: Any) -> str | None
Extract the 'after' cursor from a paginated API response (dict or Pydantic model).
Source code in cocapi/utils.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
format_endpoint_for_metrics
¶
format_endpoint_for_metrics(endpoint: str) -> str
Format endpoint path for metrics tracking (remove dynamic parts)
Source code in cocapi/utils.py
82 83 84 85 86 87 88 89 90 91 | |