Skip to content

Commit

Permalink
Support user-provided httpx.Client objects
Browse files Browse the repository at this point in the history
This gives users more control over HTTP client behavior, allowing them
to configure additional things like request logging by providing their
own Client objects.
  • Loading branch information
jparise committed Jan 27, 2024
1 parent 9b05719 commit 16e4f15
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.12.0 - Unreleased
### Added
- All clients now support a user-provided [`httpx.Client`](https://www.python-httpx.org/api/#client)
objects.

## 0.11.0 - 2024-01-22
### Added
- `VBMLClient` provides a client interface to Vestaboard's [VBML (Vestaboard
Expand Down
2 changes: 1 addition & 1 deletion src/vesta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"VBMLClient",
)

__version__ = "0.11.0"
__version__ = "0.12.0-dev"
35 changes: 19 additions & 16 deletions src/vesta/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ def __init__(
api_key: str,
api_secret: str,
*,
http_client: Optional[httpx.Client] = None,
base_url: str = "https://platform.vestaboard.com",
headers: Optional[Mapping[str, str]] = None,
):
self.http = httpx.Client(
headers={
"X-Vestaboard-Api-Key": api_key,
"X-Vestaboard-Api-Secret": api_secret,
},
base_url=base_url,
)
self.http = http_client or httpx.Client()
self.http.base_url = httpx.URL(base_url)
self.http.headers["X-Vestaboard-Api-Key"] = api_key
self.http.headers["X-Vestaboard-Api-Secret"] = api_secret
if headers:
self.http.headers.update(headers)

Expand Down Expand Up @@ -139,9 +137,11 @@ def __init__(
self,
local_api_key: Optional[str] = None,
*,
http_client: Optional[httpx.Client] = None,
base_url: str = "http://vestaboard.local:7000",
):
self.http = httpx.Client(base_url=base_url)
self.http = http_client or httpx.Client()
self.http.base_url = httpx.URL(base_url)
if local_api_key is not None:
self.api_key = local_api_key

Expand Down Expand Up @@ -232,13 +232,14 @@ class ReadWriteClient:
def __init__(
self,
read_write_key: str,
*,
http_client: Optional[httpx.Client] = None,
base_url: str = "https://rw.vestaboard.com/",
headers: Optional[Mapping[str, str]] = None,
):
self.http = httpx.Client(
headers={"X-Vestaboard-Read-Write-Key": read_write_key},
base_url=base_url,
)
self.http = http_client or httpx.Client()
self.http.base_url = httpx.URL(base_url)
self.http.headers["X-Vestaboard-Read-Write-Key"] = read_write_key
if headers:
self.http.headers.update(headers)

Expand Down Expand Up @@ -293,13 +294,15 @@ class VBMLClient:

def __init__(
self,
*,
http_client: Optional[httpx.Client] = None,
base_url: str = "https://vbml.vestaboard.com/",
headers: Optional[Mapping[str, str]] = None,
):
self.http = httpx.Client(
headers=headers,
base_url=base_url,
)
self.http = http_client or httpx.Client()
self.http.base_url = httpx.URL(base_url)
if headers:
self.http.headers.update(headers)

def __repr__(self):
return f"{type(self).__name__}(base_url={self.http.base_url!r})"
Expand Down

0 comments on commit 16e4f15

Please sign in to comment.