Skip to content

Commit

Permalink
feat: add factory functions for constructing response and json dioptr…
Browse files Browse the repository at this point in the history
…a clients
  • Loading branch information
jkglasbrenner committed Sep 3, 2024
1 parent b2db51e commit ee874d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/dioptra/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
#
# ACCESS THE FULL CC BY 4.0 LICENSE HERE:
# https://creativecommons.org/licenses/by/4.0/legalcode
from .client import DioptraClient, connect_dioptra_client
from .client import (
DioptraClient,
connect_json_dioptra_client,
connect_response_dioptra_client,
)

__all__ = ["connect_dioptra_client", "DioptraClient"]
__all__ = [
"connect_response_dioptra_client",
"connect_json_dioptra_client",
"DioptraClient",
]
12 changes: 10 additions & 2 deletions src/dioptra/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
# ACCESS THE FULL CC BY 4.0 LICENSE HERE:
# https://creativecommons.org/licenses/by/4.0/legalcode
from typing import Generic, TypeVar
from typing import Any, Generic, TypeVar

import structlog
from structlog.stdlib import BoundLogger
Expand Down Expand Up @@ -97,9 +97,17 @@ def close(self) -> None:
self._session.close()


def connect_dioptra_client(address: str) -> DioptraClient[DioptraResponseProtocol]:
def connect_response_dioptra_client(
address: str,
) -> DioptraClient[DioptraResponseProtocol]:
from .sessions import DioptraRequestsSession

return DioptraClient[DioptraResponseProtocol](
session=DioptraRequestsSession(address)
)


def connect_json_dioptra_client(address: str) -> DioptraClient[dict[str, Any]]:
from .sessions import DioptraRequestsSessionJson

return DioptraClient[dict[str, Any]](session=DioptraRequestsSessionJson(address))

0 comments on commit ee874d9

Please sign in to comment.