diff --git a/pythonkuma/decorator.py b/pythonkuma/decorator.py index 3c4a59e..5066df8 100644 --- a/pythonkuma/decorator.py +++ b/pythonkuma/decorator.py @@ -23,8 +23,8 @@ def decorator(func): async def wrapper(*args, **kwargs): """Wrapper""" client: UptimeKuma = args[0] - url = f"{client._base_url}{api_path}" - LOGGER.debug("Requesting %s", url) + url = client._base_url / api_path + LOGGER.debug("Requesting %s", url.human_repr()) try: request = await client._session.request( method=method, diff --git a/pythonkuma/uptimekuma.py b/pythonkuma/uptimekuma.py index 3d60407..4d0dd2f 100644 --- a/pythonkuma/uptimekuma.py +++ b/pythonkuma/uptimekuma.py @@ -1,6 +1,7 @@ """Uptime Kuma client.""" from aiohttp import ClientSession +from yarl import URL from .decorator import api_request from .models import UptimeKumaApiResponse @@ -9,14 +10,14 @@ class UptimeKuma: """This class is used to get information from Uptime Kuma.""" - def __init__(self, session: ClientSession, base_url: str, username: str, password: str) -> None: + def __init__(self, session: ClientSession, base_url: URL | str, username: str, password: str) -> None: """Initialize""" self.monitors = [] - self._base_url = base_url + self._base_url = base_url if isinstance(base_url, URL) else URL(base_url) self._username = username self._password = password self._session: ClientSession = session - @api_request("/metrics") + @api_request("metrics") async def async_get_monitors(self, **kwargs) -> UptimeKumaApiResponse: """Get monitors from API."""