zillow-rapidapi-client 0.1.3__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- zillow_rapidapi_client/__init__.py +18 -0
- zillow_rapidapi_client/_hooks/__init__.py +5 -0
- zillow_rapidapi_client/_hooks/registration.py +13 -0
- zillow_rapidapi_client/_hooks/sdkhooks.py +76 -0
- zillow_rapidapi_client/_hooks/types.py +106 -0
- zillow_rapidapi_client/_version.py +15 -0
- zillow_rapidapi_client/basesdk.py +358 -0
- zillow_rapidapi_client/httpclient.py +134 -0
- zillow_rapidapi_client/models/__init__.py +40 -0
- zillow_rapidapi_client/models/apierror.py +22 -0
- zillow_rapidapi_client/models/property.py +163 -0
- zillow_rapidapi_client/models/propertyextendedsearchop.py +106 -0
- zillow_rapidapi_client/models/propertysearchresponse.py +32 -0
- zillow_rapidapi_client/properties.py +221 -0
- zillow_rapidapi_client/py.typed +1 -0
- zillow_rapidapi_client/sdk.py +114 -0
- zillow_rapidapi_client/sdkconfiguration.py +52 -0
- zillow_rapidapi_client/types/__init__.py +21 -0
- zillow_rapidapi_client/types/basemodel.py +39 -0
- zillow_rapidapi_client/utils/__init__.py +99 -0
- zillow_rapidapi_client/utils/annotations.py +55 -0
- zillow_rapidapi_client/utils/enums.py +34 -0
- zillow_rapidapi_client/utils/eventstreaming.py +238 -0
- zillow_rapidapi_client/utils/forms.py +202 -0
- zillow_rapidapi_client/utils/headers.py +136 -0
- zillow_rapidapi_client/utils/logger.py +27 -0
- zillow_rapidapi_client/utils/metadata.py +118 -0
- zillow_rapidapi_client/utils/queryparams.py +205 -0
- zillow_rapidapi_client/utils/requestbodies.py +66 -0
- zillow_rapidapi_client/utils/retries.py +217 -0
- zillow_rapidapi_client/utils/security.py +174 -0
- zillow_rapidapi_client/utils/serializers.py +215 -0
- zillow_rapidapi_client/utils/url.py +155 -0
- zillow_rapidapi_client/utils/values.py +137 -0
- zillow_rapidapi_client-0.1.3.dist-info/METADATA +419 -0
- zillow_rapidapi_client-0.1.3.dist-info/RECORD +37 -0
- zillow_rapidapi_client-0.1.3.dist-info/WHEEL +4 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
from ._version import (
|
4
|
+
__title__,
|
5
|
+
__version__,
|
6
|
+
__openapi_doc_version__,
|
7
|
+
__gen_version__,
|
8
|
+
__user_agent__,
|
9
|
+
)
|
10
|
+
from .sdk import *
|
11
|
+
from .sdkconfiguration import *
|
12
|
+
from .models import *
|
13
|
+
|
14
|
+
|
15
|
+
VERSION: str = __version__
|
16
|
+
OPENAPI_DOC_VERSION = __openapi_doc_version__
|
17
|
+
SPEAKEASY_GENERATOR_VERSION = __gen_version__
|
18
|
+
USER_AGENT = __user_agent__
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from .types import Hooks
|
2
|
+
|
3
|
+
|
4
|
+
# This file is only ever generated once on the first generation and then is free to be modified.
|
5
|
+
# Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
|
6
|
+
# in this file or in separate files in the hooks folder.
|
7
|
+
|
8
|
+
|
9
|
+
def init_hooks(hooks: Hooks):
|
10
|
+
# pylint: disable=unused-argument
|
11
|
+
"""Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
|
12
|
+
with an instance of a hook that implements that specific Hook interface
|
13
|
+
Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
|
@@ -0,0 +1,76 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
import httpx
|
4
|
+
from .types import (
|
5
|
+
SDKInitHook,
|
6
|
+
BeforeRequestContext,
|
7
|
+
BeforeRequestHook,
|
8
|
+
AfterSuccessContext,
|
9
|
+
AfterSuccessHook,
|
10
|
+
AfterErrorContext,
|
11
|
+
AfterErrorHook,
|
12
|
+
Hooks,
|
13
|
+
)
|
14
|
+
from .registration import init_hooks
|
15
|
+
from typing import List, Optional, Tuple
|
16
|
+
from zillow_rapidapi_client.httpclient import HttpClient
|
17
|
+
|
18
|
+
|
19
|
+
class SDKHooks(Hooks):
|
20
|
+
def __init__(self) -> None:
|
21
|
+
self.sdk_init_hooks: List[SDKInitHook] = []
|
22
|
+
self.before_request_hooks: List[BeforeRequestHook] = []
|
23
|
+
self.after_success_hooks: List[AfterSuccessHook] = []
|
24
|
+
self.after_error_hooks: List[AfterErrorHook] = []
|
25
|
+
init_hooks(self)
|
26
|
+
|
27
|
+
def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
|
28
|
+
self.sdk_init_hooks.append(hook)
|
29
|
+
|
30
|
+
def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
|
31
|
+
self.before_request_hooks.append(hook)
|
32
|
+
|
33
|
+
def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
|
34
|
+
self.after_success_hooks.append(hook)
|
35
|
+
|
36
|
+
def register_after_error_hook(self, hook: AfterErrorHook) -> None:
|
37
|
+
self.after_error_hooks.append(hook)
|
38
|
+
|
39
|
+
def sdk_init(self, base_url: str, client: HttpClient) -> Tuple[str, HttpClient]:
|
40
|
+
for hook in self.sdk_init_hooks:
|
41
|
+
base_url, client = hook.sdk_init(base_url, client)
|
42
|
+
return base_url, client
|
43
|
+
|
44
|
+
def before_request(
|
45
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
46
|
+
) -> httpx.Request:
|
47
|
+
for hook in self.before_request_hooks:
|
48
|
+
out = hook.before_request(hook_ctx, request)
|
49
|
+
if isinstance(out, Exception):
|
50
|
+
raise out
|
51
|
+
request = out
|
52
|
+
|
53
|
+
return request
|
54
|
+
|
55
|
+
def after_success(
|
56
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
57
|
+
) -> httpx.Response:
|
58
|
+
for hook in self.after_success_hooks:
|
59
|
+
out = hook.after_success(hook_ctx, response)
|
60
|
+
if isinstance(out, Exception):
|
61
|
+
raise out
|
62
|
+
response = out
|
63
|
+
return response
|
64
|
+
|
65
|
+
def after_error(
|
66
|
+
self,
|
67
|
+
hook_ctx: AfterErrorContext,
|
68
|
+
response: Optional[httpx.Response],
|
69
|
+
error: Optional[Exception],
|
70
|
+
) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
|
71
|
+
for hook in self.after_error_hooks:
|
72
|
+
result = hook.after_error(hook_ctx, response, error)
|
73
|
+
if isinstance(result, Exception):
|
74
|
+
raise result
|
75
|
+
response, error = result
|
76
|
+
return response, error
|
@@ -0,0 +1,106 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
from abc import ABC, abstractmethod
|
4
|
+
import httpx
|
5
|
+
from typing import Any, Callable, List, Optional, Tuple, Union
|
6
|
+
from zillow_rapidapi_client.httpclient import HttpClient
|
7
|
+
|
8
|
+
|
9
|
+
class HookContext:
|
10
|
+
base_url: str
|
11
|
+
operation_id: str
|
12
|
+
oauth2_scopes: Optional[List[str]] = None
|
13
|
+
security_source: Optional[Union[Any, Callable[[], Any]]] = None
|
14
|
+
|
15
|
+
def __init__(
|
16
|
+
self,
|
17
|
+
base_url: str,
|
18
|
+
operation_id: str,
|
19
|
+
oauth2_scopes: Optional[List[str]],
|
20
|
+
security_source: Optional[Union[Any, Callable[[], Any]]],
|
21
|
+
):
|
22
|
+
self.base_url = base_url
|
23
|
+
self.operation_id = operation_id
|
24
|
+
self.oauth2_scopes = oauth2_scopes
|
25
|
+
self.security_source = security_source
|
26
|
+
|
27
|
+
|
28
|
+
class BeforeRequestContext(HookContext):
|
29
|
+
def __init__(self, hook_ctx: HookContext):
|
30
|
+
super().__init__(
|
31
|
+
hook_ctx.base_url,
|
32
|
+
hook_ctx.operation_id,
|
33
|
+
hook_ctx.oauth2_scopes,
|
34
|
+
hook_ctx.security_source,
|
35
|
+
)
|
36
|
+
|
37
|
+
|
38
|
+
class AfterSuccessContext(HookContext):
|
39
|
+
def __init__(self, hook_ctx: HookContext):
|
40
|
+
super().__init__(
|
41
|
+
hook_ctx.base_url,
|
42
|
+
hook_ctx.operation_id,
|
43
|
+
hook_ctx.oauth2_scopes,
|
44
|
+
hook_ctx.security_source,
|
45
|
+
)
|
46
|
+
|
47
|
+
|
48
|
+
class AfterErrorContext(HookContext):
|
49
|
+
def __init__(self, hook_ctx: HookContext):
|
50
|
+
super().__init__(
|
51
|
+
hook_ctx.base_url,
|
52
|
+
hook_ctx.operation_id,
|
53
|
+
hook_ctx.oauth2_scopes,
|
54
|
+
hook_ctx.security_source,
|
55
|
+
)
|
56
|
+
|
57
|
+
|
58
|
+
class SDKInitHook(ABC):
|
59
|
+
@abstractmethod
|
60
|
+
def sdk_init(self, base_url: str, client: HttpClient) -> Tuple[str, HttpClient]:
|
61
|
+
pass
|
62
|
+
|
63
|
+
|
64
|
+
class BeforeRequestHook(ABC):
|
65
|
+
@abstractmethod
|
66
|
+
def before_request(
|
67
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
68
|
+
) -> Union[httpx.Request, Exception]:
|
69
|
+
pass
|
70
|
+
|
71
|
+
|
72
|
+
class AfterSuccessHook(ABC):
|
73
|
+
@abstractmethod
|
74
|
+
def after_success(
|
75
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
76
|
+
) -> Union[httpx.Response, Exception]:
|
77
|
+
pass
|
78
|
+
|
79
|
+
|
80
|
+
class AfterErrorHook(ABC):
|
81
|
+
@abstractmethod
|
82
|
+
def after_error(
|
83
|
+
self,
|
84
|
+
hook_ctx: AfterErrorContext,
|
85
|
+
response: Optional[httpx.Response],
|
86
|
+
error: Optional[Exception],
|
87
|
+
) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
88
|
+
pass
|
89
|
+
|
90
|
+
|
91
|
+
class Hooks(ABC):
|
92
|
+
@abstractmethod
|
93
|
+
def register_sdk_init_hook(self, hook: SDKInitHook):
|
94
|
+
pass
|
95
|
+
|
96
|
+
@abstractmethod
|
97
|
+
def register_before_request_hook(self, hook: BeforeRequestHook):
|
98
|
+
pass
|
99
|
+
|
100
|
+
@abstractmethod
|
101
|
+
def register_after_success_hook(self, hook: AfterSuccessHook):
|
102
|
+
pass
|
103
|
+
|
104
|
+
@abstractmethod
|
105
|
+
def register_after_error_hook(self, hook: AfterErrorHook):
|
106
|
+
pass
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
import importlib.metadata
|
4
|
+
|
5
|
+
__title__: str = "zillow-rapidapi-client"
|
6
|
+
__version__: str = "0.1.3"
|
7
|
+
__openapi_doc_version__: str = "1.0.0"
|
8
|
+
__gen_version__: str = "2.522.1"
|
9
|
+
__user_agent__: str = "speakeasy-sdk/python 0.1.3 2.522.1 1.0.0 zillow-rapidapi-client"
|
10
|
+
|
11
|
+
try:
|
12
|
+
if __package__ is not None:
|
13
|
+
__version__ = importlib.metadata.version(__package__)
|
14
|
+
except importlib.metadata.PackageNotFoundError:
|
15
|
+
pass
|
@@ -0,0 +1,358 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
from .sdkconfiguration import SDKConfiguration
|
4
|
+
import httpx
|
5
|
+
from typing import Callable, List, Mapping, Optional, Tuple
|
6
|
+
from urllib.parse import parse_qs, urlparse
|
7
|
+
from zillow_rapidapi_client import models, utils
|
8
|
+
from zillow_rapidapi_client._hooks import (
|
9
|
+
AfterErrorContext,
|
10
|
+
AfterSuccessContext,
|
11
|
+
BeforeRequestContext,
|
12
|
+
)
|
13
|
+
from zillow_rapidapi_client.utils import (
|
14
|
+
RetryConfig,
|
15
|
+
SerializedRequestBody,
|
16
|
+
get_body_content,
|
17
|
+
)
|
18
|
+
|
19
|
+
|
20
|
+
class BaseSDK:
|
21
|
+
sdk_configuration: SDKConfiguration
|
22
|
+
|
23
|
+
def __init__(self, sdk_config: SDKConfiguration) -> None:
|
24
|
+
self.sdk_configuration = sdk_config
|
25
|
+
|
26
|
+
def _get_url(self, base_url, url_variables):
|
27
|
+
sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
|
28
|
+
|
29
|
+
if base_url is None:
|
30
|
+
base_url = sdk_url
|
31
|
+
|
32
|
+
if url_variables is None:
|
33
|
+
url_variables = sdk_variables
|
34
|
+
|
35
|
+
return utils.template_url(base_url, url_variables)
|
36
|
+
|
37
|
+
def _build_request_async(
|
38
|
+
self,
|
39
|
+
method,
|
40
|
+
path,
|
41
|
+
base_url,
|
42
|
+
url_variables,
|
43
|
+
request,
|
44
|
+
request_body_required,
|
45
|
+
request_has_path_params,
|
46
|
+
request_has_query_params,
|
47
|
+
user_agent_header,
|
48
|
+
accept_header_value,
|
49
|
+
_globals=None,
|
50
|
+
security=None,
|
51
|
+
timeout_ms: Optional[int] = None,
|
52
|
+
get_serialized_body: Optional[
|
53
|
+
Callable[[], Optional[SerializedRequestBody]]
|
54
|
+
] = None,
|
55
|
+
url_override: Optional[str] = None,
|
56
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
57
|
+
) -> httpx.Request:
|
58
|
+
client = self.sdk_configuration.async_client
|
59
|
+
return self._build_request_with_client(
|
60
|
+
client,
|
61
|
+
method,
|
62
|
+
path,
|
63
|
+
base_url,
|
64
|
+
url_variables,
|
65
|
+
request,
|
66
|
+
request_body_required,
|
67
|
+
request_has_path_params,
|
68
|
+
request_has_query_params,
|
69
|
+
user_agent_header,
|
70
|
+
accept_header_value,
|
71
|
+
_globals,
|
72
|
+
security,
|
73
|
+
timeout_ms,
|
74
|
+
get_serialized_body,
|
75
|
+
url_override,
|
76
|
+
http_headers,
|
77
|
+
)
|
78
|
+
|
79
|
+
def _build_request(
|
80
|
+
self,
|
81
|
+
method,
|
82
|
+
path,
|
83
|
+
base_url,
|
84
|
+
url_variables,
|
85
|
+
request,
|
86
|
+
request_body_required,
|
87
|
+
request_has_path_params,
|
88
|
+
request_has_query_params,
|
89
|
+
user_agent_header,
|
90
|
+
accept_header_value,
|
91
|
+
_globals=None,
|
92
|
+
security=None,
|
93
|
+
timeout_ms: Optional[int] = None,
|
94
|
+
get_serialized_body: Optional[
|
95
|
+
Callable[[], Optional[SerializedRequestBody]]
|
96
|
+
] = None,
|
97
|
+
url_override: Optional[str] = None,
|
98
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
99
|
+
) -> httpx.Request:
|
100
|
+
client = self.sdk_configuration.client
|
101
|
+
return self._build_request_with_client(
|
102
|
+
client,
|
103
|
+
method,
|
104
|
+
path,
|
105
|
+
base_url,
|
106
|
+
url_variables,
|
107
|
+
request,
|
108
|
+
request_body_required,
|
109
|
+
request_has_path_params,
|
110
|
+
request_has_query_params,
|
111
|
+
user_agent_header,
|
112
|
+
accept_header_value,
|
113
|
+
_globals,
|
114
|
+
security,
|
115
|
+
timeout_ms,
|
116
|
+
get_serialized_body,
|
117
|
+
url_override,
|
118
|
+
http_headers,
|
119
|
+
)
|
120
|
+
|
121
|
+
def _build_request_with_client(
|
122
|
+
self,
|
123
|
+
client,
|
124
|
+
method,
|
125
|
+
path,
|
126
|
+
base_url,
|
127
|
+
url_variables,
|
128
|
+
request,
|
129
|
+
request_body_required,
|
130
|
+
request_has_path_params,
|
131
|
+
request_has_query_params,
|
132
|
+
user_agent_header,
|
133
|
+
accept_header_value,
|
134
|
+
_globals=None,
|
135
|
+
security=None,
|
136
|
+
timeout_ms: Optional[int] = None,
|
137
|
+
get_serialized_body: Optional[
|
138
|
+
Callable[[], Optional[SerializedRequestBody]]
|
139
|
+
] = None,
|
140
|
+
url_override: Optional[str] = None,
|
141
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
142
|
+
) -> httpx.Request:
|
143
|
+
query_params = {}
|
144
|
+
|
145
|
+
url = url_override
|
146
|
+
if url is None:
|
147
|
+
url = utils.generate_url(
|
148
|
+
self._get_url(base_url, url_variables),
|
149
|
+
path,
|
150
|
+
request if request_has_path_params else None,
|
151
|
+
_globals if request_has_path_params else None,
|
152
|
+
)
|
153
|
+
|
154
|
+
query_params = utils.get_query_params(
|
155
|
+
request if request_has_query_params else None,
|
156
|
+
_globals if request_has_query_params else None,
|
157
|
+
)
|
158
|
+
else:
|
159
|
+
# Pick up the query parameter from the override so they can be
|
160
|
+
# preserved when building the request later on (necessary as of
|
161
|
+
# httpx 0.28).
|
162
|
+
parsed_override = urlparse(str(url_override))
|
163
|
+
query_params = parse_qs(parsed_override.query, keep_blank_values=True)
|
164
|
+
|
165
|
+
headers = utils.get_headers(request, _globals)
|
166
|
+
headers["Accept"] = accept_header_value
|
167
|
+
headers[user_agent_header] = self.sdk_configuration.user_agent
|
168
|
+
|
169
|
+
if security is not None:
|
170
|
+
if callable(security):
|
171
|
+
security = security()
|
172
|
+
|
173
|
+
if security is not None:
|
174
|
+
security_headers, security_query_params = utils.get_security(security)
|
175
|
+
headers = {**headers, **security_headers}
|
176
|
+
query_params = {**query_params, **security_query_params}
|
177
|
+
|
178
|
+
serialized_request_body = SerializedRequestBody()
|
179
|
+
if get_serialized_body is not None:
|
180
|
+
rb = get_serialized_body()
|
181
|
+
if request_body_required and rb is None:
|
182
|
+
raise ValueError("request body is required")
|
183
|
+
|
184
|
+
if rb is not None:
|
185
|
+
serialized_request_body = rb
|
186
|
+
|
187
|
+
if (
|
188
|
+
serialized_request_body.media_type is not None
|
189
|
+
and serialized_request_body.media_type
|
190
|
+
not in (
|
191
|
+
"multipart/form-data",
|
192
|
+
"multipart/mixed",
|
193
|
+
)
|
194
|
+
):
|
195
|
+
headers["content-type"] = serialized_request_body.media_type
|
196
|
+
|
197
|
+
if http_headers is not None:
|
198
|
+
for header, value in http_headers.items():
|
199
|
+
headers[header] = value
|
200
|
+
|
201
|
+
timeout = timeout_ms / 1000 if timeout_ms is not None else None
|
202
|
+
|
203
|
+
return client.build_request(
|
204
|
+
method,
|
205
|
+
url,
|
206
|
+
params=query_params,
|
207
|
+
content=serialized_request_body.content,
|
208
|
+
data=serialized_request_body.data,
|
209
|
+
files=serialized_request_body.files,
|
210
|
+
headers=headers,
|
211
|
+
timeout=timeout,
|
212
|
+
)
|
213
|
+
|
214
|
+
def do_request(
|
215
|
+
self,
|
216
|
+
hook_ctx,
|
217
|
+
request,
|
218
|
+
error_status_codes,
|
219
|
+
stream=False,
|
220
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
221
|
+
) -> httpx.Response:
|
222
|
+
client = self.sdk_configuration.client
|
223
|
+
logger = self.sdk_configuration.debug_logger
|
224
|
+
|
225
|
+
def do():
|
226
|
+
http_res = None
|
227
|
+
try:
|
228
|
+
req = self.sdk_configuration.get_hooks().before_request(
|
229
|
+
BeforeRequestContext(hook_ctx), request
|
230
|
+
)
|
231
|
+
logger.debug(
|
232
|
+
"Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
233
|
+
req.method,
|
234
|
+
req.url,
|
235
|
+
req.headers,
|
236
|
+
get_body_content(req),
|
237
|
+
)
|
238
|
+
http_res = client.send(req, stream=stream)
|
239
|
+
except Exception as e:
|
240
|
+
_, e = self.sdk_configuration.get_hooks().after_error(
|
241
|
+
AfterErrorContext(hook_ctx), None, e
|
242
|
+
)
|
243
|
+
if e is not None:
|
244
|
+
logger.debug("Request Exception", exc_info=True)
|
245
|
+
raise e
|
246
|
+
|
247
|
+
if http_res is None:
|
248
|
+
logger.debug("Raising no response SDK error")
|
249
|
+
raise models.APIError("No response received")
|
250
|
+
|
251
|
+
logger.debug(
|
252
|
+
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
253
|
+
http_res.status_code,
|
254
|
+
http_res.url,
|
255
|
+
http_res.headers,
|
256
|
+
"<streaming response>" if stream else http_res.text,
|
257
|
+
)
|
258
|
+
|
259
|
+
if utils.match_status_codes(error_status_codes, http_res.status_code):
|
260
|
+
result, err = self.sdk_configuration.get_hooks().after_error(
|
261
|
+
AfterErrorContext(hook_ctx), http_res, None
|
262
|
+
)
|
263
|
+
if err is not None:
|
264
|
+
logger.debug("Request Exception", exc_info=True)
|
265
|
+
raise err
|
266
|
+
if result is not None:
|
267
|
+
http_res = result
|
268
|
+
else:
|
269
|
+
logger.debug("Raising unexpected SDK error")
|
270
|
+
raise models.APIError("Unexpected error occurred")
|
271
|
+
|
272
|
+
return http_res
|
273
|
+
|
274
|
+
if retry_config is not None:
|
275
|
+
http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
|
276
|
+
else:
|
277
|
+
http_res = do()
|
278
|
+
|
279
|
+
if not utils.match_status_codes(error_status_codes, http_res.status_code):
|
280
|
+
http_res = self.sdk_configuration.get_hooks().after_success(
|
281
|
+
AfterSuccessContext(hook_ctx), http_res
|
282
|
+
)
|
283
|
+
|
284
|
+
return http_res
|
285
|
+
|
286
|
+
async def do_request_async(
|
287
|
+
self,
|
288
|
+
hook_ctx,
|
289
|
+
request,
|
290
|
+
error_status_codes,
|
291
|
+
stream=False,
|
292
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
293
|
+
) -> httpx.Response:
|
294
|
+
client = self.sdk_configuration.async_client
|
295
|
+
logger = self.sdk_configuration.debug_logger
|
296
|
+
|
297
|
+
async def do():
|
298
|
+
http_res = None
|
299
|
+
try:
|
300
|
+
req = self.sdk_configuration.get_hooks().before_request(
|
301
|
+
BeforeRequestContext(hook_ctx), request
|
302
|
+
)
|
303
|
+
logger.debug(
|
304
|
+
"Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
305
|
+
req.method,
|
306
|
+
req.url,
|
307
|
+
req.headers,
|
308
|
+
get_body_content(req),
|
309
|
+
)
|
310
|
+
http_res = await client.send(req, stream=stream)
|
311
|
+
except Exception as e:
|
312
|
+
_, e = self.sdk_configuration.get_hooks().after_error(
|
313
|
+
AfterErrorContext(hook_ctx), None, e
|
314
|
+
)
|
315
|
+
if e is not None:
|
316
|
+
logger.debug("Request Exception", exc_info=True)
|
317
|
+
raise e
|
318
|
+
|
319
|
+
if http_res is None:
|
320
|
+
logger.debug("Raising no response SDK error")
|
321
|
+
raise models.APIError("No response received")
|
322
|
+
|
323
|
+
logger.debug(
|
324
|
+
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
325
|
+
http_res.status_code,
|
326
|
+
http_res.url,
|
327
|
+
http_res.headers,
|
328
|
+
"<streaming response>" if stream else http_res.text,
|
329
|
+
)
|
330
|
+
|
331
|
+
if utils.match_status_codes(error_status_codes, http_res.status_code):
|
332
|
+
result, err = self.sdk_configuration.get_hooks().after_error(
|
333
|
+
AfterErrorContext(hook_ctx), http_res, None
|
334
|
+
)
|
335
|
+
if err is not None:
|
336
|
+
logger.debug("Request Exception", exc_info=True)
|
337
|
+
raise err
|
338
|
+
if result is not None:
|
339
|
+
http_res = result
|
340
|
+
else:
|
341
|
+
logger.debug("Raising unexpected SDK error")
|
342
|
+
raise models.APIError("Unexpected error occurred")
|
343
|
+
|
344
|
+
return http_res
|
345
|
+
|
346
|
+
if retry_config is not None:
|
347
|
+
http_res = await utils.retry_async(
|
348
|
+
do, utils.Retries(retry_config[0], retry_config[1])
|
349
|
+
)
|
350
|
+
else:
|
351
|
+
http_res = await do()
|
352
|
+
|
353
|
+
if not utils.match_status_codes(error_status_codes, http_res.status_code):
|
354
|
+
http_res = self.sdk_configuration.get_hooks().after_success(
|
355
|
+
AfterSuccessContext(hook_ctx), http_res
|
356
|
+
)
|
357
|
+
|
358
|
+
return http_res
|