Skip to content

Commit 84b0e73

Browse files
authored
Async client implementation (#17)
* Async client implementation
1 parent 9360097 commit 84b0e73

File tree

11 files changed

+453
-119
lines changed

11 files changed

+453
-119
lines changed

noxfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def mypy(session: Session) -> None:
150150
"""Type-check using mypy."""
151151
args = session.posargs or ["src", "tests", "docs/conf.py"]
152152
session.install(".")
153-
session.install("mypy", "pytest", "respx")
153+
session.install("mypy", "pytest", "respx", "pytest-asyncio")
154154
session.run("mypy", *args)
155155
if not session.posargs:
156156
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
@@ -160,7 +160,7 @@ def mypy(session: Session) -> None:
160160
def tests(session: Session) -> None:
161161
"""Run the test suite."""
162162
session.install(".")
163-
session.install("coverage[toml]", "pytest", "pygments", "respx")
163+
session.install("coverage[toml]", "pytest", "pygments", "respx", "pytest-asyncio")
164164
try:
165165
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
166166
finally:
@@ -185,7 +185,7 @@ def coverage(session: Session) -> None:
185185
def typeguard(session: Session) -> None:
186186
"""Runtime type checking using Typeguard."""
187187
session.install(".")
188-
session.install("pytest", "typeguard", "pygments", "respx")
188+
session.install("pytest", "typeguard", "pygments", "respx", "pytest-asyncio")
189189
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
190190

191191

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typeguard = ">=2.13.3"
4949
xdoctest = { extras = ["colors"], version = ">=0.15.10" }
5050
myst-parser = { version = ">=0.16.1" }
5151
respx = ">=0.20.1"
52+
pytest-asyncio = "^0.21.0"
5253

5354
[tool.poetry.scripts]
5455
kikinzage = "kikinzage.__main__:main"

src/kikinzage/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from kikinzage.client import DefaultClient
1212
from kikinzage.client import RequestFixtures
13+
from kikinzage.models import Formaat
1314

1415

1516
@click.group()
@@ -50,7 +51,7 @@ def postcode(ctx: Context, postcode: str, huisnummer: str) -> None:
5051
kik.eigendomsinformatie_postcode_get(
5152
postcode=postcode,
5253
huisnummer=huisnummer,
53-
formaat="json",
54+
formaat=Formaat.JSON,
5455
klantreferentie="onbekend",
5556
)
5657

src/kikinzage/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from typing import Dict
33

44
from .asyncio import AsyncClient # noqa
5-
from .base import BaseClient # noqa
5+
from .base import KikinzageBaseClient # noqa
66
from .default import DefaultClient # noqa
77

88

9-
__all__ = ["BaseClient", "DefaultClient", "AsyncClient"]
9+
__all__ = ["KikinzageBaseClient", "DefaultClient", "AsyncClient"]
1010

1111
RequestFixtures = Dict[str, Dict[str, Dict[str, Any]]]

src/kikinzage/client/asyncio.py

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,91 @@
1-
from kikinzage.client.base import BaseClient
1+
from typing import Any
2+
from typing import Literal
3+
from typing import Optional
4+
from typing import Type
5+
from typing import Union
26

7+
import httpx
8+
from httpx import USE_CLIENT_DEFAULT
9+
from httpx._client import UseClientDefault
310

4-
class AsyncClient(BaseClient):
11+
from .. import models
12+
from ..models import Formaat
13+
from ..models import ResponseType
14+
from .base import KikinzageBaseClient
15+
16+
17+
FormaatDefault: Literal["FormaatFormaatDefault"] = "FormaatFormaatDefault"
18+
Klantreferentie: Literal["Klantreferentie"] = "Klantreferentie"
19+
20+
21+
class AsyncClient(KikinzageBaseClient):
522
"""Client for async requests"""
23+
24+
client: httpx.AsyncClient
25+
26+
def __init__(
27+
self,
28+
username: str,
29+
password: str,
30+
base_url: str = "https://service10.kadaster.nl/kik-inzage-eto/v6/",
31+
formaat: Formaat = Formaat.JSON,
32+
klantreferentie: Optional[str] = None,
33+
gebruikeridentificatie: Optional[str] = None,
34+
hyperlinkopproduct: Optional[bool] = None,
35+
inkoopnummer: Optional[str] = None,
36+
referentienummer: Optional[str] = None,
37+
**httpx_kwargs: Any,
38+
) -> None:
39+
super().__init__(
40+
username=username,
41+
password=password,
42+
base_url=base_url,
43+
formaat=formaat,
44+
klantreferentie=klantreferentie,
45+
gebruikeridentificatie=gebruikeridentificatie,
46+
hyperlinkopproduct=hyperlinkopproduct,
47+
inkoopnummer=inkoopnummer,
48+
referentienummer=referentienummer,
49+
)
50+
51+
httpx_kwargs.setdefault("base_url", base_url)
52+
httpx_kwargs.setdefault("auth", (self.username, self.password))
53+
54+
self.client = self.create_client(**httpx_kwargs)
55+
56+
def create_client(self, **httpx_kwargs: Any) -> httpx.AsyncClient:
57+
return httpx.AsyncClient(**httpx_kwargs)
58+
59+
async def eigendomsinformatie_kadastraalobjectidentificatie_get(
60+
self,
61+
kadastraalobjectidentificatie: str,
62+
formaat: Union[Formaat, UseClientDefault] = USE_CLIENT_DEFAULT,
63+
klantreferentie: Union[str, UseClientDefault] = USE_CLIENT_DEFAULT,
64+
gebruikeridentificatie: Optional[str] = None,
65+
hyperlinkopproduct: Optional[bool] = None,
66+
inkoopnummer: Optional[str] = None,
67+
referentienummer: Optional[str] = None,
68+
) -> models.Eigendomsinformatie:
69+
"""GET /eigendomsinformatie/kadastraalobjectidentificatie/{kadastraalobjectidentificatie}"""
70+
71+
request = self.request_eigendomsinformatie_kadastraalobjectidentificatie(
72+
kadastraalobjectidentificatie=kadastraalobjectidentificatie,
73+
formaat=formaat,
74+
klantreferentie=klantreferentie,
75+
gebruikeridentificatie=gebruikeridentificatie,
76+
hyperlinkopproduct=hyperlinkopproduct,
77+
inkoopnummer=inkoopnummer,
78+
referentienummer=referentienummer,
79+
)
80+
81+
return await self.send(request, models.Eigendomsinformatie)
82+
83+
async def send(
84+
self,
85+
request: httpx.Request,
86+
model: Type[ResponseType],
87+
status_code_success: int = 200,
88+
) -> ResponseType:
89+
response = await self.client.send(request)
90+
91+
return self.process_response(response, model, status_code_success)

0 commit comments

Comments
 (0)