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.
Files changed (61) hide show
  1. xdataapi/__init__.py +8 -0
  2. xdataapi/api/__init__.py +1 -0
  3. xdataapi/api/account/__init__.py +1 -0
  4. xdataapi/api/account/get_me.py +144 -0
  5. xdataapi/api/billing/__init__.py +1 -0
  6. xdataapi/api/billing/create_checkout.py +206 -0
  7. xdataapi/api/billing/list_packs.py +144 -0
  8. xdataapi/api/tweets/__init__.py +1 -0
  9. xdataapi/api/tweets/get_quotes.py +241 -0
  10. xdataapi/api/tweets/get_replies.py +230 -0
  11. xdataapi/api/tweets/get_retweeters.py +245 -0
  12. xdataapi/api/tweets/get_thread.py +226 -0
  13. xdataapi/api/tweets/get_tweet.py +213 -0
  14. xdataapi/api/tweets/get_tweets.py +223 -0
  15. xdataapi/api/tweets/search_tweets.py +277 -0
  16. xdataapi/api/users/__init__.py +1 -0
  17. xdataapi/api/users/get_follower_ids.py +254 -0
  18. xdataapi/api/users/get_followers.py +254 -0
  19. xdataapi/api/users/get_following.py +246 -0
  20. xdataapi/api/users/get_user.py +213 -0
  21. xdataapi/api/users/get_user_tweets.py +241 -0
  22. xdataapi/api/users/get_users.py +231 -0
  23. xdataapi/client.py +268 -0
  24. xdataapi/errors.py +16 -0
  25. xdataapi/models/__init__.py +67 -0
  26. xdataapi/models/batch_error.py +79 -0
  27. xdataapi/models/batch_error_code.py +15 -0
  28. xdataapi/models/batch_meta.py +126 -0
  29. xdataapi/models/batch_meta_cache.py +11 -0
  30. xdataapi/models/create_checkout_body.py +63 -0
  31. xdataapi/models/create_checkout_body_pack.py +11 -0
  32. xdataapi/models/create_checkout_response_200.py +97 -0
  33. xdataapi/models/error.py +78 -0
  34. xdataapi/models/error_body.py +72 -0
  35. xdataapi/models/error_body_code.py +22 -0
  36. xdataapi/models/get_me_response_200.py +88 -0
  37. xdataapi/models/get_tweets_body.py +61 -0
  38. xdataapi/models/get_users_body.py +61 -0
  39. xdataapi/models/id_page.py +117 -0
  40. xdataapi/models/list_packs_response_200.py +105 -0
  41. xdataapi/models/list_packs_response_200_data_item.py +88 -0
  42. xdataapi/models/list_packs_response_200_rate_limits_item.py +70 -0
  43. xdataapi/models/media.py +96 -0
  44. xdataapi/models/media_type.py +10 -0
  45. xdataapi/models/meta.py +106 -0
  46. xdataapi/models/meta_cache.py +10 -0
  47. xdataapi/models/problem.py +131 -0
  48. xdataapi/models/search_tweets_product.py +12 -0
  49. xdataapi/models/tweet.py +310 -0
  50. xdataapi/models/tweet_batch.py +150 -0
  51. xdataapi/models/tweet_page.py +133 -0
  52. xdataapi/models/tweet_response.py +128 -0
  53. xdataapi/models/user.py +204 -0
  54. xdataapi/models/user_batch.py +150 -0
  55. xdataapi/models/user_page.py +133 -0
  56. xdataapi/models/user_response.py +128 -0
  57. xdataapi/py.typed +1 -0
  58. xdataapi/types.py +54 -0
  59. xdataapi-0.3.0.dist-info/METADATA +148 -0
  60. xdataapi-0.3.0.dist-info/RECORD +61 -0
  61. xdataapi-0.3.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,241 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+ from urllib.parse import quote
4
+
5
+ import httpx
6
+
7
+ from ... import errors
8
+ from ...client import AuthenticatedClient, Client
9
+ from ...models.error import Error
10
+ from ...models.tweet_page import TweetPage
11
+ from ...types import UNSET, Response, Unset
12
+
13
+
14
+ def _get_kwargs(
15
+ user: str,
16
+ *,
17
+ count: int | Unset = 20,
18
+ cursor: str | Unset = UNSET,
19
+ fresh: bool | Unset = False,
20
+ ) -> dict[str, Any]:
21
+
22
+ params: dict[str, Any] = {}
23
+
24
+ params["count"] = count
25
+
26
+ params["cursor"] = cursor
27
+
28
+ params["fresh"] = fresh
29
+
30
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
31
+
32
+ _kwargs: dict[str, Any] = {
33
+ "method": "get",
34
+ "url": "/v1/users/{user}/tweets".format(
35
+ user=quote(str(user), safe=""),
36
+ ),
37
+ "params": params,
38
+ }
39
+
40
+ return _kwargs
41
+
42
+
43
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Error | TweetPage | None:
44
+ if response.status_code == 200:
45
+ response_200 = TweetPage.from_dict(response.json())
46
+
47
+ return response_200
48
+
49
+ if response.status_code == 401:
50
+ response_401 = Error.from_dict(response.json())
51
+
52
+ return response_401
53
+
54
+ if response.status_code == 402:
55
+ response_402 = Error.from_dict(response.json())
56
+
57
+ return response_402
58
+
59
+ if response.status_code == 404:
60
+ response_404 = Error.from_dict(response.json())
61
+
62
+ return response_404
63
+
64
+ if response.status_code == 429:
65
+ response_429 = Error.from_dict(response.json())
66
+
67
+ return response_429
68
+
69
+ if response.status_code == 500:
70
+ response_500 = Error.from_dict(response.json())
71
+
72
+ return response_500
73
+
74
+ if response.status_code == 503:
75
+ response_503 = Error.from_dict(response.json())
76
+
77
+ return response_503
78
+
79
+ if client.raise_on_unexpected_status:
80
+ raise errors.UnexpectedStatus(response.status_code, response.content)
81
+ else:
82
+ return None
83
+
84
+
85
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Error | TweetPage]:
86
+ return Response(
87
+ status_code=HTTPStatus(response.status_code),
88
+ content=response.content,
89
+ headers=response.headers,
90
+ parsed=_parse_response(client=client, response=response),
91
+ )
92
+
93
+
94
+ def sync_detailed(
95
+ user: str,
96
+ *,
97
+ client: AuthenticatedClient | Client,
98
+ count: int | Unset = 20,
99
+ cursor: str | Unset = UNSET,
100
+ fresh: bool | Unset = False,
101
+ ) -> Response[Error | TweetPage]:
102
+ """Latest tweets of a user
103
+
104
+ 1 credit per tweet. `user` is a numeric id or a handle.
105
+
106
+ Args:
107
+ user (str):
108
+ count (int | Unset): Default: 20.
109
+ cursor (str | Unset):
110
+ fresh (bool | Unset): Default: False.
111
+
112
+ Raises:
113
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
114
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
115
+
116
+ Returns:
117
+ Response[Error | TweetPage]
118
+ """
119
+
120
+ kwargs = _get_kwargs(
121
+ user=user,
122
+ count=count,
123
+ cursor=cursor,
124
+ fresh=fresh,
125
+ )
126
+
127
+ response = client.get_httpx_client().request(
128
+ **kwargs,
129
+ )
130
+
131
+ return _build_response(client=client, response=response)
132
+
133
+
134
+ def sync(
135
+ user: str,
136
+ *,
137
+ client: AuthenticatedClient | Client,
138
+ count: int | Unset = 20,
139
+ cursor: str | Unset = UNSET,
140
+ fresh: bool | Unset = False,
141
+ ) -> Error | TweetPage | None:
142
+ """Latest tweets of a user
143
+
144
+ 1 credit per tweet. `user` is a numeric id or a handle.
145
+
146
+ Args:
147
+ user (str):
148
+ count (int | Unset): Default: 20.
149
+ cursor (str | Unset):
150
+ fresh (bool | Unset): Default: False.
151
+
152
+ Raises:
153
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
154
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
155
+
156
+ Returns:
157
+ Error | TweetPage
158
+ """
159
+
160
+ return sync_detailed(
161
+ user=user,
162
+ client=client,
163
+ count=count,
164
+ cursor=cursor,
165
+ fresh=fresh,
166
+ ).parsed
167
+
168
+
169
+ async def asyncio_detailed(
170
+ user: str,
171
+ *,
172
+ client: AuthenticatedClient | Client,
173
+ count: int | Unset = 20,
174
+ cursor: str | Unset = UNSET,
175
+ fresh: bool | Unset = False,
176
+ ) -> Response[Error | TweetPage]:
177
+ """Latest tweets of a user
178
+
179
+ 1 credit per tweet. `user` is a numeric id or a handle.
180
+
181
+ Args:
182
+ user (str):
183
+ count (int | Unset): Default: 20.
184
+ cursor (str | Unset):
185
+ fresh (bool | Unset): Default: False.
186
+
187
+ Raises:
188
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
189
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
190
+
191
+ Returns:
192
+ Response[Error | TweetPage]
193
+ """
194
+
195
+ kwargs = _get_kwargs(
196
+ user=user,
197
+ count=count,
198
+ cursor=cursor,
199
+ fresh=fresh,
200
+ )
201
+
202
+ response = await client.get_async_httpx_client().request(**kwargs)
203
+
204
+ return _build_response(client=client, response=response)
205
+
206
+
207
+ async def asyncio(
208
+ user: str,
209
+ *,
210
+ client: AuthenticatedClient | Client,
211
+ count: int | Unset = 20,
212
+ cursor: str | Unset = UNSET,
213
+ fresh: bool | Unset = False,
214
+ ) -> Error | TweetPage | None:
215
+ """Latest tweets of a user
216
+
217
+ 1 credit per tweet. `user` is a numeric id or a handle.
218
+
219
+ Args:
220
+ user (str):
221
+ count (int | Unset): Default: 20.
222
+ cursor (str | Unset):
223
+ fresh (bool | Unset): Default: False.
224
+
225
+ Raises:
226
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
227
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
228
+
229
+ Returns:
230
+ Error | TweetPage
231
+ """
232
+
233
+ return (
234
+ await asyncio_detailed(
235
+ user=user,
236
+ client=client,
237
+ count=count,
238
+ cursor=cursor,
239
+ fresh=fresh,
240
+ )
241
+ ).parsed
@@ -0,0 +1,231 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.error import Error
9
+ from ...models.get_users_body import GetUsersBody
10
+ from ...models.user_batch import UserBatch
11
+ from ...types import UNSET, Response, Unset
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ body: GetUsersBody,
17
+ fresh: bool | Unset = False,
18
+ ) -> dict[str, Any]:
19
+ headers: dict[str, Any] = {}
20
+
21
+ params: dict[str, Any] = {}
22
+
23
+ params["fresh"] = fresh
24
+
25
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
26
+
27
+ _kwargs: dict[str, Any] = {
28
+ "method": "post",
29
+ "url": "/v1/users/batch",
30
+ "params": params,
31
+ }
32
+
33
+ _kwargs["json"] = body.to_dict()
34
+
35
+ headers["Content-Type"] = "application/json"
36
+
37
+ _kwargs["headers"] = headers
38
+ return _kwargs
39
+
40
+
41
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Error | UserBatch | None:
42
+ if response.status_code == 200:
43
+ response_200 = UserBatch.from_dict(response.json())
44
+
45
+ return response_200
46
+
47
+ if response.status_code == 400:
48
+ response_400 = Error.from_dict(response.json())
49
+
50
+ return response_400
51
+
52
+ if response.status_code == 401:
53
+ response_401 = Error.from_dict(response.json())
54
+
55
+ return response_401
56
+
57
+ if response.status_code == 402:
58
+ response_402 = Error.from_dict(response.json())
59
+
60
+ return response_402
61
+
62
+ if response.status_code == 429:
63
+ response_429 = Error.from_dict(response.json())
64
+
65
+ return response_429
66
+
67
+ if response.status_code == 500:
68
+ response_500 = Error.from_dict(response.json())
69
+
70
+ return response_500
71
+
72
+ if response.status_code == 503:
73
+ response_503 = Error.from_dict(response.json())
74
+
75
+ return response_503
76
+
77
+ if client.raise_on_unexpected_status:
78
+ raise errors.UnexpectedStatus(response.status_code, response.content)
79
+ else:
80
+ return None
81
+
82
+
83
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Error | UserBatch]:
84
+ return Response(
85
+ status_code=HTTPStatus(response.status_code),
86
+ content=response.content,
87
+ headers=response.headers,
88
+ parsed=_parse_response(client=client, response=response),
89
+ )
90
+
91
+
92
+ def sync_detailed(
93
+ *,
94
+ client: AuthenticatedClient | Client,
95
+ body: GetUsersBody,
96
+ fresh: bool | Unset = False,
97
+ ) -> Response[Error | UserBatch]:
98
+ """Profiles by handle, batch
99
+
100
+ Up to 100 profiles in one call. 1 credit per profile found; handles that do not exist are listed in
101
+ `errors` and cost nothing. Duplicates are folded. Results in input order. Also `GET
102
+ /v1/users/batch?handles=a,b,c`.
103
+ When the balance covers only part of the list, the tail comes back as `no_credits` and is not
104
+ fetched.
105
+
106
+ Args:
107
+ fresh (bool | Unset): Default: False.
108
+ body (GetUsersBody):
109
+
110
+ Raises:
111
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
112
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
113
+
114
+ Returns:
115
+ Response[Error | UserBatch]
116
+ """
117
+
118
+ kwargs = _get_kwargs(
119
+ body=body,
120
+ fresh=fresh,
121
+ )
122
+
123
+ response = client.get_httpx_client().request(
124
+ **kwargs,
125
+ )
126
+
127
+ return _build_response(client=client, response=response)
128
+
129
+
130
+ def sync(
131
+ *,
132
+ client: AuthenticatedClient | Client,
133
+ body: GetUsersBody,
134
+ fresh: bool | Unset = False,
135
+ ) -> Error | UserBatch | None:
136
+ """Profiles by handle, batch
137
+
138
+ Up to 100 profiles in one call. 1 credit per profile found; handles that do not exist are listed in
139
+ `errors` and cost nothing. Duplicates are folded. Results in input order. Also `GET
140
+ /v1/users/batch?handles=a,b,c`.
141
+ When the balance covers only part of the list, the tail comes back as `no_credits` and is not
142
+ fetched.
143
+
144
+ Args:
145
+ fresh (bool | Unset): Default: False.
146
+ body (GetUsersBody):
147
+
148
+ Raises:
149
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
150
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
151
+
152
+ Returns:
153
+ Error | UserBatch
154
+ """
155
+
156
+ return sync_detailed(
157
+ client=client,
158
+ body=body,
159
+ fresh=fresh,
160
+ ).parsed
161
+
162
+
163
+ async def asyncio_detailed(
164
+ *,
165
+ client: AuthenticatedClient | Client,
166
+ body: GetUsersBody,
167
+ fresh: bool | Unset = False,
168
+ ) -> Response[Error | UserBatch]:
169
+ """Profiles by handle, batch
170
+
171
+ Up to 100 profiles in one call. 1 credit per profile found; handles that do not exist are listed in
172
+ `errors` and cost nothing. Duplicates are folded. Results in input order. Also `GET
173
+ /v1/users/batch?handles=a,b,c`.
174
+ When the balance covers only part of the list, the tail comes back as `no_credits` and is not
175
+ fetched.
176
+
177
+ Args:
178
+ fresh (bool | Unset): Default: False.
179
+ body (GetUsersBody):
180
+
181
+ Raises:
182
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
183
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
184
+
185
+ Returns:
186
+ Response[Error | UserBatch]
187
+ """
188
+
189
+ kwargs = _get_kwargs(
190
+ body=body,
191
+ fresh=fresh,
192
+ )
193
+
194
+ response = await client.get_async_httpx_client().request(**kwargs)
195
+
196
+ return _build_response(client=client, response=response)
197
+
198
+
199
+ async def asyncio(
200
+ *,
201
+ client: AuthenticatedClient | Client,
202
+ body: GetUsersBody,
203
+ fresh: bool | Unset = False,
204
+ ) -> Error | UserBatch | None:
205
+ """Profiles by handle, batch
206
+
207
+ Up to 100 profiles in one call. 1 credit per profile found; handles that do not exist are listed in
208
+ `errors` and cost nothing. Duplicates are folded. Results in input order. Also `GET
209
+ /v1/users/batch?handles=a,b,c`.
210
+ When the balance covers only part of the list, the tail comes back as `no_credits` and is not
211
+ fetched.
212
+
213
+ Args:
214
+ fresh (bool | Unset): Default: False.
215
+ body (GetUsersBody):
216
+
217
+ Raises:
218
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
219
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
220
+
221
+ Returns:
222
+ Error | UserBatch
223
+ """
224
+
225
+ return (
226
+ await asyncio_detailed(
227
+ client=client,
228
+ body=body,
229
+ fresh=fresh,
230
+ )
231
+ ).parsed