Skip to content

Commit

Permalink
Merge pull request #33 from upstash/base-url-fix
Browse files Browse the repository at this point in the history
Add Optional base_url Parameter to Clients
  • Loading branch information
yunusemreozdemir authored Dec 24, 2024
1 parent cabb431 commit 9efb145
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
7 changes: 6 additions & 1 deletion qstash/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ def __init__(
token: str,
*,
retry: Optional[Union[Literal[False], RetryConfig]] = None,
base_url: Optional[str] = None,
) -> None:
"""
:param token: The authorization token from the Upstash console.
:param retry: Configures how the client should retry requests.
"""
http = AsyncHttpClient(token, retry)
http = AsyncHttpClient(
token,
retry,
base_url,
)
self.message = AsyncMessageApi(http)
"""Message api."""

Expand Down
7 changes: 5 additions & 2 deletions qstash/asyncio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(
self,
token: str,
retry: Optional[Union[Literal[False], RetryConfig]],
base_url: Optional[str] = None,
) -> None:
self._token = f"Bearer {token}"

Expand All @@ -33,6 +34,8 @@ def __init__(
timeout=DEFAULT_TIMEOUT,
)

self._base_url = base_url.rstrip("/") if base_url else BASE_URL

async def request(
self,
*,
Expand All @@ -45,7 +48,7 @@ async def request(
base_url: Optional[str] = None,
token: Optional[str] = None,
) -> Any:
base_url = base_url or BASE_URL
base_url = base_url or self._base_url
token = token or self._token

url = base_url + path
Expand Down Expand Up @@ -91,7 +94,7 @@ async def stream(
base_url: Optional[str] = None,
token: Optional[str] = None,
) -> httpx.Response:
base_url = base_url or BASE_URL
base_url = base_url or self._base_url
token = token or self._token

url = base_url + path
Expand Down
7 changes: 6 additions & 1 deletion qstash/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ def __init__(
token: str,
*,
retry: Optional[Union[Literal[False], RetryConfig]] = None,
base_url: Optional[str] = None,
) -> None:
"""
:param token: The authorization token from the Upstash console.
:param retry: Configures how the client should retry requests.
"""
http = HttpClient(token, retry)
http = HttpClient(
token,
retry,
base_url,
)
self.message = MessageApi(http)
"""Message api."""

Expand Down
7 changes: 5 additions & 2 deletions qstash/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(
self,
token: str,
retry: Optional[Union[Literal[False], RetryConfig]],
base_url: Optional[str] = None,
) -> None:
self._token = f"Bearer {token}"

Expand All @@ -116,6 +117,8 @@ def __init__(
timeout=DEFAULT_TIMEOUT,
)

self._base_url = base_url.rstrip("/") if base_url else BASE_URL

def request(
self,
*,
Expand All @@ -128,7 +131,7 @@ def request(
base_url: Optional[str] = None,
token: Optional[str] = None,
) -> Any:
base_url = base_url or BASE_URL
base_url = base_url or self._base_url
token = token or self._token

url = base_url + path
Expand Down Expand Up @@ -174,7 +177,7 @@ def stream(
base_url: Optional[str] = None,
token: Optional[str] = None,
) -> httpx.Response:
base_url = base_url or BASE_URL
base_url = base_url or self._base_url
token = token or self._token

url = base_url + path
Expand Down

0 comments on commit 9efb145

Please sign in to comment.