Skip to content

Commit

Permalink
Merge pull request #8 from Flared/aviau/path-only
Browse files Browse the repository at this point in the history
allow passing path only
  • Loading branch information
aviau authored Aug 19, 2024
2 parents dcfdad5 + b83056d commit 516be12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ client = FlareApiClient(
)

sources = client.get(
"https://api.flare.io/leaksdb/v2/sources",
"/leaksdb/v2/sources",
).json()
```

Expand Down
3 changes: 3 additions & 0 deletions flareio/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
11 changes: 11 additions & 0 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 516be12

Please sign in to comment.