-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathendpoint_module.py
129 lines (104 loc) · 2.94 KB
/
endpoint_module.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from typing import Any, Dict, List, Optional, Union, cast
import httpx
from attr import asdict
from ...client import AuthenticatedClient, Client
from ...types import Response, UNSET
import this
from __future__ import braces
def _get_kwargs(
*,
client: AuthenticatedClient,
form_data: FormBody,
multipart_data: MultiPartBody,
json_body: Json,
) -> Dict[str, Any]:
url = "{}/post/".format(client.base_url)
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"data": asdict(form_data),
"files": multipart_data.to_dict(),
"json": json_json_body,
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[str, int]]:
if response.status_code == 200:
response_one = response.json()
return response_one
if response.status_code == 201:
response_one = response.json()
return response_one
return None
def _build_response(*, response: httpx.Response) -> Response[Union[str, int]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
*,
client: AuthenticatedClient,
form_data: FormBody,
multipart_data: MultiPartBody,
json_body: Json,
) -> Response[Union[str, int]]:
kwargs = _get_kwargs(
client=client,
form_data=form_data,
multipart_data=multipart_data,
json_body=json_body,
)
response = httpx.post(
**kwargs,
)
return _build_response(response=response)
def sync(
*,
client: AuthenticatedClient,
form_data: FormBody,
multipart_data: MultiPartBody,
json_body: Json,
) -> Optional[Union[str, int]]:
""" POST endpoint """
return sync_detailed(
client=client,
form_data=form_data,
multipart_data=multipart_data,
json_body=json_body,
).parsed
async def asyncio_detailed(
*,
client: AuthenticatedClient,
form_data: FormBody,
multipart_data: MultiPartBody,
json_body: Json,
) -> Response[Union[str, int]]:
kwargs = _get_kwargs(
client=client,
form_data=form_data,
multipart_data=multipart_data,
json_body=json_body,
)
async with httpx.AsyncClient() as _client:
response = await _client.post(**kwargs)
return _build_response(response=response)
async def asyncio(
*,
client: AuthenticatedClient,
form_data: FormBody,
multipart_data: MultiPartBody,
json_body: Json,
) -> Optional[Union[str, int]]:
""" POST endpoint """
return (
await asyncio_detailed(
client=client,
form_data=form_data,
multipart_data=multipart_data,
json_body=json_body,
)
).parsed