-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPetController.py
More file actions
80 lines (78 loc) · 3.58 KB
/
Copy pathPetController.py
File metadata and controls
80 lines (78 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import httpx
from ..models.Pet import Pet
from ..models.ApiResponse import ApiResponse
class PetController:
def __init__(self, base_url: str) -> None:
self._base_url = base_url
async def putPet(self, body: Pet, **kwargs) -> Pet:
async with httpx.AsyncClient() as client:
response = await client.put(
f"{self._base_url}/pet",
json=body.model_dump() if hasattr(body, 'model_dump') else body,
**kwargs,
)
response.raise_for_status()
return response.json()
async def postPet(self, body: Pet, **kwargs) -> Pet:
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self._base_url}/pet",
json=body.model_dump() if hasattr(body, 'model_dump') else body,
**kwargs,
)
response.raise_for_status()
return response.json()
async def getFindByStatus(self, q_status: str | None = None, **kwargs) -> list[Pet]:
async with httpx.AsyncClient() as client:
response = await client.get(
f"{self._base_url}/pet/findByStatus",
params={k: v for k, v in {"status": q_status}.items() if v is not None},
**kwargs,
)
response.raise_for_status()
return response.json()
async def getFindByTags(self, q_tags: list[str] | None = None, **kwargs) -> list[Pet]:
async with httpx.AsyncClient() as client:
response = await client.get(
f"{self._base_url}/pet/findByTags",
params={k: v for k, v in {"tags": q_tags}.items() if v is not None},
**kwargs,
)
response.raise_for_status()
return response.json()
async def getPetId(self, p_pet_id: int | None, **kwargs) -> Pet:
async with httpx.AsyncClient() as client:
response = await client.get(
f"{self._base_url}/pet/{p_pet_id}",
**kwargs,
)
response.raise_for_status()
return response.json()
async def postPetId(self, p_pet_id: int | None, q_name: str | None = None, q_status: str | None = None, **kwargs) -> Pet:
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self._base_url}/pet/{p_pet_id}",
params={k: v for k, v in {"name": q_name, "status": q_status}.items() if v is not None},
**kwargs,
)
response.raise_for_status()
return response.json()
async def deletePetId(self, p_pet_id: int | None, h_apikey: str | None, **kwargs) -> dict:
async with httpx.AsyncClient() as client:
response = await client.delete(
f"{self._base_url}/pet/{p_pet_id}",
headers={'api_key': h_apikey},
**kwargs,
)
response.raise_for_status()
return response.json()
async def postPetIdUploadImage(self, body: str | None, p_pet_id: int | None, q_additional_metadata: str | None = None, **kwargs) -> ApiResponse:
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self._base_url}/pet/{p_pet_id}/uploadImage",
json=body.model_dump() if hasattr(body, 'model_dump') else body,
params={k: v for k, v in {"additionalMetadata": q_additional_metadata}.items() if v is not None},
**kwargs,
)
response.raise_for_status()
return response.json()