diff --git a/README.md b/README.md index 37c5f70..9dba286 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ client = FlareApiClient( ) sources = client.get( - "https://api.flare.io/leaksdb/v2/sources", + "/leaksdb/v2/sources", ).json() ``` diff --git a/flareio/api_client.py b/flareio/api_client.py index a6ec673..acd9483 100644 --- a/flareio/api_client.py +++ b/flareio/api_client.py @@ -3,6 +3,7 @@ from datetime import datetime from datetime import timedelta from flareio.exceptions import TokenError +from urllib.parse import urljoin from urllib.parse import urlparse import typing as t @@ -67,6 +68,8 @@ def _request( json: t.Optional[t.Dict[str, t.Any]] = None, headers: t.Optional[t.Dict[str, t.Any]] = None, ) -> requests.Response: + url = urljoin("https://api.flare.io", url) + if not urlparse(url).netloc == "api.flare.io": raise Exception( "Please only use the client to access the api.flare.io domain." diff --git a/tests/test_api_client.py b/tests/test_api_client.py index 5d5ee1e..a432dde 100644 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -166,6 +166,17 @@ def test_wrapped_methods() -> None: assert mocker.last_request.headers["Authorization"] == "Bearer test-token-hello" +def test_get_path_only() -> None: + client = _get_test_client(authenticated=True) + with requests_mock.Mocker() as mocker: + mocker.register_uri( + "GET", + "https://api.flare.io/hello/test", + status_code=200, + ) + client.get("/hello/test") + assert mocker.last_request.url == "https://api.flare.io/hello/test" + def test_scroll() -> None: api_client = _get_test_client()