xdataapi 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xdataapi/__init__.py +8 -0
- xdataapi/api/__init__.py +1 -0
- xdataapi/api/account/__init__.py +1 -0
- xdataapi/api/account/get_me.py +144 -0
- xdataapi/api/billing/__init__.py +1 -0
- xdataapi/api/billing/create_checkout.py +206 -0
- xdataapi/api/billing/list_packs.py +144 -0
- xdataapi/api/tweets/__init__.py +1 -0
- xdataapi/api/tweets/get_quotes.py +241 -0
- xdataapi/api/tweets/get_replies.py +230 -0
- xdataapi/api/tweets/get_retweeters.py +245 -0
- xdataapi/api/tweets/get_thread.py +226 -0
- xdataapi/api/tweets/get_tweet.py +213 -0
- xdataapi/api/tweets/get_tweets.py +223 -0
- xdataapi/api/tweets/search_tweets.py +277 -0
- xdataapi/api/users/__init__.py +1 -0
- xdataapi/api/users/get_follower_ids.py +254 -0
- xdataapi/api/users/get_followers.py +254 -0
- xdataapi/api/users/get_following.py +246 -0
- xdataapi/api/users/get_user.py +213 -0
- xdataapi/api/users/get_user_tweets.py +241 -0
- xdataapi/api/users/get_users.py +231 -0
- xdataapi/client.py +268 -0
- xdataapi/errors.py +16 -0
- xdataapi/models/__init__.py +67 -0
- xdataapi/models/batch_error.py +79 -0
- xdataapi/models/batch_error_code.py +15 -0
- xdataapi/models/batch_meta.py +126 -0
- xdataapi/models/batch_meta_cache.py +11 -0
- xdataapi/models/create_checkout_body.py +63 -0
- xdataapi/models/create_checkout_body_pack.py +11 -0
- xdataapi/models/create_checkout_response_200.py +97 -0
- xdataapi/models/error.py +78 -0
- xdataapi/models/error_body.py +72 -0
- xdataapi/models/error_body_code.py +22 -0
- xdataapi/models/get_me_response_200.py +88 -0
- xdataapi/models/get_tweets_body.py +61 -0
- xdataapi/models/get_users_body.py +61 -0
- xdataapi/models/id_page.py +117 -0
- xdataapi/models/list_packs_response_200.py +105 -0
- xdataapi/models/list_packs_response_200_data_item.py +88 -0
- xdataapi/models/list_packs_response_200_rate_limits_item.py +70 -0
- xdataapi/models/media.py +96 -0
- xdataapi/models/media_type.py +10 -0
- xdataapi/models/meta.py +106 -0
- xdataapi/models/meta_cache.py +10 -0
- xdataapi/models/problem.py +131 -0
- xdataapi/models/search_tweets_product.py +12 -0
- xdataapi/models/tweet.py +310 -0
- xdataapi/models/tweet_batch.py +150 -0
- xdataapi/models/tweet_page.py +133 -0
- xdataapi/models/tweet_response.py +128 -0
- xdataapi/models/user.py +204 -0
- xdataapi/models/user_batch.py +150 -0
- xdataapi/models/user_page.py +133 -0
- xdataapi/models/user_response.py +128 -0
- xdataapi/py.typed +1 -0
- xdataapi/types.py +54 -0
- xdataapi-0.3.0.dist-info/METADATA +148 -0
- xdataapi-0.3.0.dist-info/RECORD +61 -0
- xdataapi-0.3.0.dist-info/WHEEL +4 -0
xdataapi/client.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import ssl
|
|
2
|
+
from typing import Any, Self
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
from attrs import define, evolve, field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@define
|
|
9
|
+
class Client:
|
|
10
|
+
"""A class for keeping track of data related to the API
|
|
11
|
+
|
|
12
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
13
|
+
|
|
14
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
15
|
+
|
|
16
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
17
|
+
|
|
18
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
19
|
+
|
|
20
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
21
|
+
httpx.TimeoutException if this is exceeded.
|
|
22
|
+
|
|
23
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
24
|
+
but can be set to False for testing purposes.
|
|
25
|
+
|
|
26
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
27
|
+
|
|
28
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Attributes:
|
|
32
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
33
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
34
|
+
argument to the constructor.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
38
|
+
_base_url: str = field(alias="base_url")
|
|
39
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
40
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
41
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
42
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
43
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
44
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
45
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
46
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
47
|
+
|
|
48
|
+
def with_headers(self, headers: dict[str, str]) -> "Client":
|
|
49
|
+
"""Get a new client matching this one with additional headers"""
|
|
50
|
+
if self._client is not None:
|
|
51
|
+
self._client.headers.update(headers)
|
|
52
|
+
if self._async_client is not None:
|
|
53
|
+
self._async_client.headers.update(headers)
|
|
54
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
55
|
+
|
|
56
|
+
def with_cookies(self, cookies: dict[str, str]) -> "Client":
|
|
57
|
+
"""Get a new client matching this one with additional cookies"""
|
|
58
|
+
if self._client is not None:
|
|
59
|
+
self._client.cookies.update(cookies)
|
|
60
|
+
if self._async_client is not None:
|
|
61
|
+
self._async_client.cookies.update(cookies)
|
|
62
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
63
|
+
|
|
64
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "Client":
|
|
65
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
66
|
+
if self._client is not None:
|
|
67
|
+
self._client.timeout = timeout
|
|
68
|
+
if self._async_client is not None:
|
|
69
|
+
self._async_client.timeout = timeout
|
|
70
|
+
return evolve(self, timeout=timeout)
|
|
71
|
+
|
|
72
|
+
def set_httpx_client(self, client: httpx.Client) -> Self:
|
|
73
|
+
"""Manually set the underlying httpx.Client
|
|
74
|
+
|
|
75
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
76
|
+
"""
|
|
77
|
+
self._client = client
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
81
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
82
|
+
if self._client is None:
|
|
83
|
+
self._client = httpx.Client(
|
|
84
|
+
base_url=self._base_url,
|
|
85
|
+
cookies=self._cookies,
|
|
86
|
+
headers=self._headers,
|
|
87
|
+
timeout=self._timeout,
|
|
88
|
+
verify=self._verify_ssl,
|
|
89
|
+
follow_redirects=self._follow_redirects,
|
|
90
|
+
**self._httpx_args,
|
|
91
|
+
)
|
|
92
|
+
return self._client
|
|
93
|
+
|
|
94
|
+
def __enter__(self) -> Self:
|
|
95
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
|
96
|
+
self.get_httpx_client().__enter__()
|
|
97
|
+
return self
|
|
98
|
+
|
|
99
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
|
100
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
101
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
102
|
+
|
|
103
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
|
|
104
|
+
"""Manually set the underlying httpx.AsyncClient
|
|
105
|
+
|
|
106
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
107
|
+
"""
|
|
108
|
+
self._async_client = async_client
|
|
109
|
+
return self
|
|
110
|
+
|
|
111
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
112
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
113
|
+
if self._async_client is None:
|
|
114
|
+
self._async_client = httpx.AsyncClient(
|
|
115
|
+
base_url=self._base_url,
|
|
116
|
+
cookies=self._cookies,
|
|
117
|
+
headers=self._headers,
|
|
118
|
+
timeout=self._timeout,
|
|
119
|
+
verify=self._verify_ssl,
|
|
120
|
+
follow_redirects=self._follow_redirects,
|
|
121
|
+
**self._httpx_args,
|
|
122
|
+
)
|
|
123
|
+
return self._async_client
|
|
124
|
+
|
|
125
|
+
async def __aenter__(self) -> Self:
|
|
126
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
127
|
+
await self.get_async_httpx_client().__aenter__()
|
|
128
|
+
return self
|
|
129
|
+
|
|
130
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
131
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
132
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@define
|
|
136
|
+
class AuthenticatedClient:
|
|
137
|
+
"""A Client which has been authenticated for use on secured endpoints
|
|
138
|
+
|
|
139
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
140
|
+
|
|
141
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
142
|
+
|
|
143
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
144
|
+
|
|
145
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
146
|
+
|
|
147
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
148
|
+
httpx.TimeoutException if this is exceeded.
|
|
149
|
+
|
|
150
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
151
|
+
but can be set to False for testing purposes.
|
|
152
|
+
|
|
153
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
154
|
+
|
|
155
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
Attributes:
|
|
159
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
160
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
161
|
+
argument to the constructor.
|
|
162
|
+
token: The token to use for authentication
|
|
163
|
+
prefix: The prefix to use for the Authorization header
|
|
164
|
+
auth_header_name: The name of the Authorization header
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
168
|
+
_base_url: str = field(alias="base_url")
|
|
169
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
170
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
171
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
172
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
173
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
174
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
175
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
176
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
177
|
+
|
|
178
|
+
token: str
|
|
179
|
+
prefix: str = "Bearer"
|
|
180
|
+
auth_header_name: str = "Authorization"
|
|
181
|
+
|
|
182
|
+
def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
|
|
183
|
+
"""Get a new client matching this one with additional headers"""
|
|
184
|
+
if self._client is not None:
|
|
185
|
+
self._client.headers.update(headers)
|
|
186
|
+
if self._async_client is not None:
|
|
187
|
+
self._async_client.headers.update(headers)
|
|
188
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
189
|
+
|
|
190
|
+
def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
|
|
191
|
+
"""Get a new client matching this one with additional cookies"""
|
|
192
|
+
if self._client is not None:
|
|
193
|
+
self._client.cookies.update(cookies)
|
|
194
|
+
if self._async_client is not None:
|
|
195
|
+
self._async_client.cookies.update(cookies)
|
|
196
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
197
|
+
|
|
198
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
|
|
199
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
200
|
+
if self._client is not None:
|
|
201
|
+
self._client.timeout = timeout
|
|
202
|
+
if self._async_client is not None:
|
|
203
|
+
self._async_client.timeout = timeout
|
|
204
|
+
return evolve(self, timeout=timeout)
|
|
205
|
+
|
|
206
|
+
def set_httpx_client(self, client: httpx.Client) -> Self:
|
|
207
|
+
"""Manually set the underlying httpx.Client
|
|
208
|
+
|
|
209
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
210
|
+
"""
|
|
211
|
+
self._client = client
|
|
212
|
+
return self
|
|
213
|
+
|
|
214
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
215
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
216
|
+
if self._client is None:
|
|
217
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
218
|
+
self._client = httpx.Client(
|
|
219
|
+
base_url=self._base_url,
|
|
220
|
+
cookies=self._cookies,
|
|
221
|
+
headers=self._headers,
|
|
222
|
+
timeout=self._timeout,
|
|
223
|
+
verify=self._verify_ssl,
|
|
224
|
+
follow_redirects=self._follow_redirects,
|
|
225
|
+
**self._httpx_args,
|
|
226
|
+
)
|
|
227
|
+
return self._client
|
|
228
|
+
|
|
229
|
+
def __enter__(self) -> Self:
|
|
230
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
|
231
|
+
self.get_httpx_client().__enter__()
|
|
232
|
+
return self
|
|
233
|
+
|
|
234
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
|
235
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
236
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
237
|
+
|
|
238
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
|
|
239
|
+
"""Manually set the underlying httpx.AsyncClient
|
|
240
|
+
|
|
241
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
242
|
+
"""
|
|
243
|
+
self._async_client = async_client
|
|
244
|
+
return self
|
|
245
|
+
|
|
246
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
247
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
248
|
+
if self._async_client is None:
|
|
249
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
250
|
+
self._async_client = httpx.AsyncClient(
|
|
251
|
+
base_url=self._base_url,
|
|
252
|
+
cookies=self._cookies,
|
|
253
|
+
headers=self._headers,
|
|
254
|
+
timeout=self._timeout,
|
|
255
|
+
verify=self._verify_ssl,
|
|
256
|
+
follow_redirects=self._follow_redirects,
|
|
257
|
+
**self._httpx_args,
|
|
258
|
+
)
|
|
259
|
+
return self._async_client
|
|
260
|
+
|
|
261
|
+
async def __aenter__(self) -> Self:
|
|
262
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
263
|
+
await self.get_async_httpx_client().__aenter__()
|
|
264
|
+
return self
|
|
265
|
+
|
|
266
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
267
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
268
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
xdataapi/errors.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Contains shared errors types that can be raised from API functions"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class UnexpectedStatus(Exception):
|
|
5
|
+
"""Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
|
|
6
|
+
|
|
7
|
+
def __init__(self, status_code: int, content: bytes):
|
|
8
|
+
self.status_code = status_code
|
|
9
|
+
self.content = content
|
|
10
|
+
|
|
11
|
+
super().__init__(
|
|
12
|
+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = ["UnexpectedStatus"]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Contains all the data models used in inputs/outputs"""
|
|
2
|
+
|
|
3
|
+
from .batch_error import BatchError
|
|
4
|
+
from .batch_error_code import BatchErrorCode
|
|
5
|
+
from .batch_meta import BatchMeta
|
|
6
|
+
from .batch_meta_cache import BatchMetaCache
|
|
7
|
+
from .create_checkout_body import CreateCheckoutBody
|
|
8
|
+
from .create_checkout_body_pack import CreateCheckoutBodyPack
|
|
9
|
+
from .create_checkout_response_200 import CreateCheckoutResponse200
|
|
10
|
+
from .error import Error
|
|
11
|
+
from .error_body import ErrorBody
|
|
12
|
+
from .error_body_code import ErrorBodyCode
|
|
13
|
+
from .get_me_response_200 import GetMeResponse200
|
|
14
|
+
from .get_tweets_body import GetTweetsBody
|
|
15
|
+
from .get_users_body import GetUsersBody
|
|
16
|
+
from .id_page import IdPage
|
|
17
|
+
from .list_packs_response_200 import ListPacksResponse200
|
|
18
|
+
from .list_packs_response_200_data_item import ListPacksResponse200DataItem
|
|
19
|
+
from .list_packs_response_200_rate_limits_item import ListPacksResponse200RateLimitsItem
|
|
20
|
+
from .media import Media
|
|
21
|
+
from .media_type import MediaType
|
|
22
|
+
from .meta import Meta
|
|
23
|
+
from .meta_cache import MetaCache
|
|
24
|
+
from .problem import Problem
|
|
25
|
+
from .search_tweets_product import SearchTweetsProduct
|
|
26
|
+
from .tweet import Tweet
|
|
27
|
+
from .tweet_batch import TweetBatch
|
|
28
|
+
from .tweet_page import TweetPage
|
|
29
|
+
from .tweet_response import TweetResponse
|
|
30
|
+
from .user import User
|
|
31
|
+
from .user_batch import UserBatch
|
|
32
|
+
from .user_page import UserPage
|
|
33
|
+
from .user_response import UserResponse
|
|
34
|
+
|
|
35
|
+
__all__ = (
|
|
36
|
+
"BatchError",
|
|
37
|
+
"BatchErrorCode",
|
|
38
|
+
"BatchMeta",
|
|
39
|
+
"BatchMetaCache",
|
|
40
|
+
"CreateCheckoutBody",
|
|
41
|
+
"CreateCheckoutBodyPack",
|
|
42
|
+
"CreateCheckoutResponse200",
|
|
43
|
+
"Error",
|
|
44
|
+
"ErrorBody",
|
|
45
|
+
"ErrorBodyCode",
|
|
46
|
+
"GetMeResponse200",
|
|
47
|
+
"GetTweetsBody",
|
|
48
|
+
"GetUsersBody",
|
|
49
|
+
"IdPage",
|
|
50
|
+
"ListPacksResponse200",
|
|
51
|
+
"ListPacksResponse200DataItem",
|
|
52
|
+
"ListPacksResponse200RateLimitsItem",
|
|
53
|
+
"Media",
|
|
54
|
+
"MediaType",
|
|
55
|
+
"Meta",
|
|
56
|
+
"MetaCache",
|
|
57
|
+
"Problem",
|
|
58
|
+
"SearchTweetsProduct",
|
|
59
|
+
"Tweet",
|
|
60
|
+
"TweetBatch",
|
|
61
|
+
"TweetPage",
|
|
62
|
+
"TweetResponse",
|
|
63
|
+
"User",
|
|
64
|
+
"UserBatch",
|
|
65
|
+
"UserPage",
|
|
66
|
+
"UserResponse",
|
|
67
|
+
)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import Any, TypeVar
|
|
5
|
+
|
|
6
|
+
from attrs import define as _attrs_define
|
|
7
|
+
from attrs import field as _attrs_field
|
|
8
|
+
|
|
9
|
+
from ..models.batch_error_code import BatchErrorCode
|
|
10
|
+
|
|
11
|
+
T = TypeVar("T", bound="BatchError")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@_attrs_define
|
|
15
|
+
class BatchError:
|
|
16
|
+
"""
|
|
17
|
+
Attributes:
|
|
18
|
+
input_ (str): The handle or id as sent.
|
|
19
|
+
code (BatchErrorCode):
|
|
20
|
+
message (str):
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
input_: str
|
|
24
|
+
code: BatchErrorCode
|
|
25
|
+
message: str
|
|
26
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
27
|
+
|
|
28
|
+
def to_dict(self) -> dict[str, Any]:
|
|
29
|
+
input_ = self.input_
|
|
30
|
+
|
|
31
|
+
code = self.code.value
|
|
32
|
+
|
|
33
|
+
message = self.message
|
|
34
|
+
|
|
35
|
+
field_dict: dict[str, Any] = {}
|
|
36
|
+
field_dict.update(self.additional_properties)
|
|
37
|
+
field_dict.update(
|
|
38
|
+
{
|
|
39
|
+
"input": input_,
|
|
40
|
+
"code": code,
|
|
41
|
+
"message": message,
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return field_dict
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
49
|
+
d = dict(src_dict)
|
|
50
|
+
input_ = d.pop("input")
|
|
51
|
+
|
|
52
|
+
code = BatchErrorCode(d.pop("code"))
|
|
53
|
+
|
|
54
|
+
message = d.pop("message")
|
|
55
|
+
|
|
56
|
+
batch_error = cls(
|
|
57
|
+
input_=input_,
|
|
58
|
+
code=code,
|
|
59
|
+
message=message,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
batch_error.additional_properties = d
|
|
63
|
+
return batch_error
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def additional_keys(self) -> list[str]:
|
|
67
|
+
return list(self.additional_properties.keys())
|
|
68
|
+
|
|
69
|
+
def __getitem__(self, key: str) -> Any:
|
|
70
|
+
return self.additional_properties[key]
|
|
71
|
+
|
|
72
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
73
|
+
self.additional_properties[key] = value
|
|
74
|
+
|
|
75
|
+
def __delitem__(self, key: str) -> None:
|
|
76
|
+
del self.additional_properties[key]
|
|
77
|
+
|
|
78
|
+
def __contains__(self, key: str) -> bool:
|
|
79
|
+
return key in self.additional_properties
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BatchErrorCode(StrEnum):
|
|
5
|
+
ACCESS_DENIED = "access_denied"
|
|
6
|
+
BAD_REQUEST = "bad_request"
|
|
7
|
+
NOT_FOUND = "not_found"
|
|
8
|
+
NO_ACCOUNT = "no_account"
|
|
9
|
+
NO_CREDITS = "no_credits"
|
|
10
|
+
REQUEST_REJECTED = "request_rejected"
|
|
11
|
+
UPSTREAM_ERROR = "upstream_error"
|
|
12
|
+
UPSTREAM_RATE_LIMITED = "upstream_rate_limited"
|
|
13
|
+
|
|
14
|
+
def __str__(self) -> str:
|
|
15
|
+
return str(self.value)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
from attrs import define as _attrs_define
|
|
8
|
+
from attrs import field as _attrs_field
|
|
9
|
+
|
|
10
|
+
from ..models.batch_meta_cache import BatchMetaCache
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ..models.batch_error import BatchError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
T = TypeVar("T", bound="BatchMeta")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@_attrs_define
|
|
20
|
+
class BatchMeta:
|
|
21
|
+
"""
|
|
22
|
+
Attributes:
|
|
23
|
+
errors (list[BatchError]): Inputs that returned nothing, with the reason. Never charged.
|
|
24
|
+
items (int): Objects returned.
|
|
25
|
+
credits_charged (float):
|
|
26
|
+
balance_remaining (float):
|
|
27
|
+
cache (BatchMetaCache):
|
|
28
|
+
cache_hits (int): Objects served from cache
|
|
29
|
+
request_id (UUID):
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
errors: list[BatchError]
|
|
33
|
+
items: int
|
|
34
|
+
credits_charged: float
|
|
35
|
+
balance_remaining: float
|
|
36
|
+
cache: BatchMetaCache
|
|
37
|
+
cache_hits: int
|
|
38
|
+
request_id: UUID
|
|
39
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
40
|
+
|
|
41
|
+
def to_dict(self) -> dict[str, Any]:
|
|
42
|
+
errors = []
|
|
43
|
+
for errors_item_data in self.errors:
|
|
44
|
+
errors_item = errors_item_data.to_dict()
|
|
45
|
+
errors.append(errors_item)
|
|
46
|
+
|
|
47
|
+
items = self.items
|
|
48
|
+
|
|
49
|
+
credits_charged = self.credits_charged
|
|
50
|
+
|
|
51
|
+
balance_remaining = self.balance_remaining
|
|
52
|
+
|
|
53
|
+
cache = self.cache.value
|
|
54
|
+
|
|
55
|
+
cache_hits = self.cache_hits
|
|
56
|
+
|
|
57
|
+
request_id = str(self.request_id)
|
|
58
|
+
|
|
59
|
+
field_dict: dict[str, Any] = {}
|
|
60
|
+
field_dict.update(self.additional_properties)
|
|
61
|
+
field_dict.update(
|
|
62
|
+
{
|
|
63
|
+
"errors": errors,
|
|
64
|
+
"items": items,
|
|
65
|
+
"credits_charged": credits_charged,
|
|
66
|
+
"balance_remaining": balance_remaining,
|
|
67
|
+
"cache": cache,
|
|
68
|
+
"cache_hits": cache_hits,
|
|
69
|
+
"request_id": request_id,
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
return field_dict
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
77
|
+
from ..models.batch_error import BatchError # noqa: PLC0415
|
|
78
|
+
|
|
79
|
+
d = dict(src_dict)
|
|
80
|
+
errors = []
|
|
81
|
+
_errors = d.pop("errors")
|
|
82
|
+
for errors_item_data in _errors:
|
|
83
|
+
errors_item = BatchError.from_dict(errors_item_data)
|
|
84
|
+
|
|
85
|
+
errors.append(errors_item)
|
|
86
|
+
|
|
87
|
+
items = d.pop("items")
|
|
88
|
+
|
|
89
|
+
credits_charged = d.pop("credits_charged")
|
|
90
|
+
|
|
91
|
+
balance_remaining = d.pop("balance_remaining")
|
|
92
|
+
|
|
93
|
+
cache = BatchMetaCache(d.pop("cache"))
|
|
94
|
+
|
|
95
|
+
cache_hits = d.pop("cache_hits")
|
|
96
|
+
|
|
97
|
+
request_id = UUID(d.pop("request_id"))
|
|
98
|
+
|
|
99
|
+
batch_meta = cls(
|
|
100
|
+
errors=errors,
|
|
101
|
+
items=items,
|
|
102
|
+
credits_charged=credits_charged,
|
|
103
|
+
balance_remaining=balance_remaining,
|
|
104
|
+
cache=cache,
|
|
105
|
+
cache_hits=cache_hits,
|
|
106
|
+
request_id=request_id,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
batch_meta.additional_properties = d
|
|
110
|
+
return batch_meta
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def additional_keys(self) -> list[str]:
|
|
114
|
+
return list(self.additional_properties.keys())
|
|
115
|
+
|
|
116
|
+
def __getitem__(self, key: str) -> Any:
|
|
117
|
+
return self.additional_properties[key]
|
|
118
|
+
|
|
119
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
120
|
+
self.additional_properties[key] = value
|
|
121
|
+
|
|
122
|
+
def __delitem__(self, key: str) -> None:
|
|
123
|
+
del self.additional_properties[key]
|
|
124
|
+
|
|
125
|
+
def __contains__(self, key: str) -> bool:
|
|
126
|
+
return key in self.additional_properties
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import Any, TypeVar
|
|
5
|
+
|
|
6
|
+
from attrs import define as _attrs_define
|
|
7
|
+
from attrs import field as _attrs_field
|
|
8
|
+
|
|
9
|
+
from ..models.create_checkout_body_pack import CreateCheckoutBodyPack
|
|
10
|
+
|
|
11
|
+
T = TypeVar("T", bound="CreateCheckoutBody")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@_attrs_define
|
|
15
|
+
class CreateCheckoutBody:
|
|
16
|
+
"""
|
|
17
|
+
Attributes:
|
|
18
|
+
pack (CreateCheckoutBodyPack):
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
pack: CreateCheckoutBodyPack
|
|
22
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
23
|
+
|
|
24
|
+
def to_dict(self) -> dict[str, Any]:
|
|
25
|
+
pack = self.pack.value
|
|
26
|
+
|
|
27
|
+
field_dict: dict[str, Any] = {}
|
|
28
|
+
field_dict.update(self.additional_properties)
|
|
29
|
+
field_dict.update(
|
|
30
|
+
{
|
|
31
|
+
"pack": pack,
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return field_dict
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
39
|
+
d = dict(src_dict)
|
|
40
|
+
pack = CreateCheckoutBodyPack(d.pop("pack"))
|
|
41
|
+
|
|
42
|
+
create_checkout_body = cls(
|
|
43
|
+
pack=pack,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
create_checkout_body.additional_properties = d
|
|
47
|
+
return create_checkout_body
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def additional_keys(self) -> list[str]:
|
|
51
|
+
return list(self.additional_properties.keys())
|
|
52
|
+
|
|
53
|
+
def __getitem__(self, key: str) -> Any:
|
|
54
|
+
return self.additional_properties[key]
|
|
55
|
+
|
|
56
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
57
|
+
self.additional_properties[key] = value
|
|
58
|
+
|
|
59
|
+
def __delitem__(self, key: str) -> None:
|
|
60
|
+
del self.additional_properties[key]
|
|
61
|
+
|
|
62
|
+
def __contains__(self, key: str) -> bool:
|
|
63
|
+
return key in self.additional_properties
|