Skip to content

Commit 7476293

Browse files
authored
docs: update README with usage examples for AuthenticatedClient and GeotekniskUnders (#13)
1 parent cff30e1 commit 7476293

File tree

1 file changed

+22
-44
lines changed

1 file changed

+22
-44
lines changed

nadag-innmelding-python-client/README.md

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,40 @@ A client library for accessing Nadag innmelding API
55
First, create a client:
66

77
```python
8-
from nadag_innmelding_python_client import Client
9-
10-
client = Client(base_url="https://api.example.com")
11-
```
8+
from nadag_innmelding_python_client import AuthenticatedClient
129

13-
If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
10+
secret_token = nadag_authenticate() # This you need to implement this yourself
1411

15-
```python
16-
from nadag_innmelding_python_client import AuthenticatedClient
12+
client = AuthenticatedClient(
13+
base_url="https://test.ngu.no/api/",
14+
token=secret_token,
15+
)
1716

18-
client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
1917
```
2018

2119
Now call your endpoint and use your models:
2220

2321
```python
24-
from nadag_innmelding_python_client.models import MyDataModel
25-
from nadag_innmelding_python_client.api.my_tag import get_my_data_model
22+
from nadag_innmelding_python_client.api.default import get_nadag_innmelding_v_1_geoteknisk_unders as get_geoteknisk_unders
23+
from nadag_innmelding_python_client.models import GeotekniskUnders
2624
from nadag_innmelding_python_client.types import Response
2725

2826
with client as client:
29-
my_data: MyDataModel = get_my_data_model.sync(client=client)
30-
# or if you need more info (e.g. status_code)
31-
response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
32-
```
33-
34-
Or do the same thing with an async version:
35-
36-
```python
37-
from nadag_innmelding_python_client.models import MyDataModel
38-
from nadag_innmelding_python_client.api.my_tag import get_my_data_model
39-
from nadag_innmelding_python_client.types import Response
27+
response: Response[GeotekniskUnders] = get_geoteknisk_unders.sync_detailed(
28+
client=client,
29+
ekstern_id=str(project_id),
30+
ekstern_navnerom="Your Namespace",
31+
)
32+
33+
match response.status_code:
34+
case HTTPStatus.OK:
35+
geoteknisk_unders: GeotekniskUnders = response.parsed
36+
case HTTPStatus.NOT_FOUND:
37+
# Create a new project in NADAG
38+
case _:
39+
# Handle other status codes
40+
raise Exception(f"Got unexpected status code {response.status_code} for project ")
4041

41-
async with client as client:
42-
my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
43-
response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
44-
```
45-
46-
By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
47-
48-
```python
49-
client = AuthenticatedClient(
50-
base_url="https://internal_api.example.com",
51-
token="SuperSecretToken",
52-
verify_ssl="/path/to/certificate_bundle.pem",
53-
)
54-
```
55-
56-
You can also disable certificate validation altogether, but beware that **this is a security risk**.
57-
58-
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
6442
```
6543

6644
Things to know:

0 commit comments

Comments
 (0)