Skip to content

Commit

Permalink
Hide httpx from the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Nov 15, 2023
2 parents 9fcb437 + 32f8d1e commit 2da2ba8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/brreg/enhetsregisteret/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@


class Client:
client: httpx.Client
_client: httpx.Client

def __new__(cls) -> Client:
self = super().__new__(cls)
def __init__(self) -> None:
self.open()
return self

def __enter__(self) -> Client:
return self
Expand All @@ -31,12 +29,12 @@ def __exit__(
self.close()

def open(self) -> None:
self.client = httpx.Client(
self._client = httpx.Client(
base_url="https://data.brreg.no/enhetsregisteret/api",
)

def close(self) -> None:
self.client.close()
self._client.close()

def get_enhet(self, organisasjonsnummer: str) -> Optional[Enhet]:
"""Get :class:`Enhet` given an organization number.
Expand All @@ -49,7 +47,7 @@ def get_enhet(self, organisasjonsnummer: str) -> Optional[Enhet]:
"""
res: Optional[httpx.Response] = None
try:
res = self.client.get(f"/enheter/{organisasjonsnummer}")
res = self._client.get(f"/enheter/{organisasjonsnummer}")
if res.status_code in (404, 410):
return None
res.raise_for_status()
Expand Down

0 comments on commit 2da2ba8

Please sign in to comment.