Skip to content

Commit 41503af

Browse files
authored
Use yarl for URL building (#29)
1 parent b0af6eb commit 41503af

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

pythonkuma/decorator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def decorator(func):
2323
async def wrapper(*args, **kwargs):
2424
"""Wrapper"""
2525
client: UptimeKuma = args[0]
26-
url = f"{client._base_url}{api_path}"
27-
LOGGER.debug("Requesting %s", url)
26+
url = client._base_url / api_path
27+
LOGGER.debug("Requesting %s", url.human_repr())
2828
try:
2929
request = await client._session.request(
3030
method=method,

pythonkuma/uptimekuma.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Uptime Kuma client."""
22

33
from aiohttp import ClientSession
4+
from yarl import URL
45

56
from .decorator import api_request
67
from .models import UptimeKumaApiResponse
@@ -9,14 +10,14 @@
910
class UptimeKuma:
1011
"""This class is used to get information from Uptime Kuma."""
1112

12-
def __init__(self, session: ClientSession, base_url: str, username: str, password: str) -> None:
13+
def __init__(self, session: ClientSession, base_url: URL | str, username: str, password: str) -> None:
1314
"""Initialize"""
1415
self.monitors = []
15-
self._base_url = base_url
16+
self._base_url = base_url if isinstance(base_url, URL) else URL(base_url)
1617
self._username = username
1718
self._password = password
1819
self._session: ClientSession = session
1920

20-
@api_request("/metrics")
21+
@api_request("metrics")
2122
async def async_get_monitors(self, **kwargs) -> UptimeKumaApiResponse:
2223
"""Get monitors from API."""

0 commit comments

Comments
 (0)