From 4913bf478d562f7011e93ecf3c7e0bfc1bd2401e Mon Sep 17 00:00:00 2001 From: Ivan Glebov Date: Thu, 12 Feb 2026 13:29:30 +0300 Subject: [PATCH] Add API Version Choice --- kuma/rest/__init__.py | 7 +++++-- kuma/rest/_base.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/kuma/rest/__init__.py b/kuma/rest/__init__.py index 7663b4a..51cbadb 100644 --- a/kuma/rest/__init__.py +++ b/kuma/rest/__init__.py @@ -1,4 +1,5 @@ -from typing import Union +import logging +from typing import Union, Optional from kuma.rest._base import KumaRestAPIBase from kuma.rest.active_lists import KumaRestAPIActiveLists @@ -47,8 +48,10 @@ def __init__( token: str, verify: Union[bool, str], timeout: int = KumaRestAPIBase.DEFAULT_TIMEOUT, + logger: Optional[logging.Logger] = None, + version: str = "", ): - super().__init__(url, token, verify, timeout) + super().__init__(url, token, verify, timeout, logger, version) self._modules = {} def _get_module(self, name: str): diff --git a/kuma/rest/_base.py b/kuma/rest/_base.py index 2d71664..6e4308c 100644 --- a/kuma/rest/_base.py +++ b/kuma/rest/_base.py @@ -34,15 +34,17 @@ def __init__( verify: Union[bool, str] = False, timeout: int = DEFAULT_TIMEOUT, logger: Optional[logging.Logger] = None, + version: str = "", ): """Initialize the API client. Args: - url: Base server URL (e.g., "kumacore.local" or "https://kumacore.local:7223") - token: Bearer token for authentication + url: Base server URL (e.g., "kumacore.local" or "https://kumacore.local:7223"). + token: Bearer token for authentication. verify: SSL certificate verification. Set False to disable warnings. - timeout: Request timeout in seconds (default: 30) - logger: Custom logger instance (optional) + timeout: Request timeout in seconds (default: 30). + logger: Custom logger instance (optional). + version: Version of KUMA API. Raises: ValueError: If URL is malformed @@ -52,6 +54,7 @@ def __init__( self.timeout = timeout self.logger = logger or self._create_default_logger() + self.v = version or _api_version self._configure_url(url) self._configure_session(token) @@ -126,7 +129,7 @@ def _make_request( """ Unified request method with error handling and logging. """ - url = f"{self.url}/api/{_api_version}/{endpoint.lstrip('/')}" + url = f"{self.url}/api/{self.v}/{endpoint.lstrip('/')}" headers = {**self.session.headers, **(headers or {})} self.logger.debug(f"Request: {method} {url}")