truagents 0.0.0.dev0__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 (56) hide show
  1. truagents/__init__.py +18 -0
  2. truagents/__version__.py +1 -0
  3. truagents/auth.py +293 -0
  4. truagents/client.py +304 -0
  5. truagents/errors.py +193 -0
  6. truagents/generated/__init__.py +8 -0
  7. truagents/generated/api/__init__.py +1 -0
  8. truagents/generated/api/email_unsubscribe/__init__.py +1 -0
  9. truagents/generated/api/email_unsubscribe/list_email_unsubscribes.py +290 -0
  10. truagents/generated/api/email_unsubscribe/push_email_unsubscribes.py +236 -0
  11. truagents/generated/api/o_auth/__init__.py +1 -0
  12. truagents/generated/api/o_auth/issue_o_auth_token.py +241 -0
  13. truagents/generated/api/sms_unsubscribe/__init__.py +1 -0
  14. truagents/generated/api/sms_unsubscribe/list_sms_unsubscribes.py +290 -0
  15. truagents/generated/api/sms_unsubscribe/push_sms_unsubscribes.py +232 -0
  16. truagents/generated/api/voice_unsubscribe/__init__.py +1 -0
  17. truagents/generated/api/voice_unsubscribe/list_phone_unsubscribes.py +298 -0
  18. truagents/generated/api/voice_unsubscribe/push_phone_unsubscribes.py +232 -0
  19. truagents/generated/client.py +282 -0
  20. truagents/generated/errors.py +16 -0
  21. truagents/generated/models/__init__.py +65 -0
  22. truagents/generated/models/email_skipped_item.py +83 -0
  23. truagents/generated/models/email_skipped_item_reason.py +11 -0
  24. truagents/generated/models/email_source_enum.py +11 -0
  25. truagents/generated/models/email_unsubscribe_batch_request.py +93 -0
  26. truagents/generated/models/email_unsubscribe_batch_response.py +119 -0
  27. truagents/generated/models/email_unsubscribe_item.py +50 -0
  28. truagents/generated/models/email_unsubscribe_list_response.py +113 -0
  29. truagents/generated/models/email_unsubscribe_record.py +98 -0
  30. truagents/generated/models/email_unsubscribe_updated_entry.py +79 -0
  31. truagents/generated/models/o_auth_client_credentials_request.py +87 -0
  32. truagents/generated/models/o_auth_client_credentials_request_grant_type.py +8 -0
  33. truagents/generated/models/o_auth_error_response.py +83 -0
  34. truagents/generated/models/o_auth_error_response_error.py +11 -0
  35. truagents/generated/models/o_auth_refresh_token_request.py +75 -0
  36. truagents/generated/models/o_auth_refresh_token_request_grant_type.py +8 -0
  37. truagents/generated/models/o_auth_token_response.py +97 -0
  38. truagents/generated/models/o_auth_token_response_token_type.py +8 -0
  39. truagents/generated/models/phone_skipped_item.py +83 -0
  40. truagents/generated/models/phone_skipped_item_reason.py +11 -0
  41. truagents/generated/models/phone_source_enum.py +11 -0
  42. truagents/generated/models/phone_unsubscribe_batch_request.py +92 -0
  43. truagents/generated/models/phone_unsubscribe_batch_response.py +118 -0
  44. truagents/generated/models/phone_unsubscribe_item.py +51 -0
  45. truagents/generated/models/phone_unsubscribe_list_response.py +111 -0
  46. truagents/generated/models/phone_unsubscribe_record.py +99 -0
  47. truagents/generated/models/phone_unsubscribe_updated_entry.py +79 -0
  48. truagents/generated/models/rest_error_response.py +74 -0
  49. truagents/generated/models/unauthorized_organization_error.py +90 -0
  50. truagents/generated/models/unauthorized_organization_error_error.py +8 -0
  51. truagents/generated/types.py +54 -0
  52. truagents/observability.py +70 -0
  53. truagents/retry.py +64 -0
  54. truagents-0.0.0.dev0.dist-info/METADATA +171 -0
  55. truagents-0.0.0.dev0.dist-info/RECORD +56 -0
  56. truagents-0.0.0.dev0.dist-info/WHEEL +4 -0
@@ -0,0 +1,290 @@
1
+ import datetime
2
+ from http import HTTPStatus
3
+ from typing import Any
4
+
5
+ import httpx
6
+
7
+ from ... import errors
8
+ from ...client import AuthenticatedClient, Client
9
+ from ...models.phone_unsubscribe_list_response import PhoneUnsubscribeListResponse
10
+ from ...models.rest_error_response import RestErrorResponse
11
+ from ...models.unauthorized_organization_error import UnauthorizedOrganizationError
12
+ from ...types import UNSET, Response, Unset
13
+
14
+
15
+ def _get_kwargs(
16
+ *,
17
+ org_slug: str | Unset = UNSET,
18
+ since: datetime.datetime | Unset = UNSET,
19
+ until: datetime.datetime | Unset = UNSET,
20
+ cursor: str | Unset = UNSET,
21
+ limit: int | Unset = 100,
22
+ ) -> dict[str, Any]:
23
+
24
+ params: dict[str, Any] = {}
25
+
26
+ params["org_slug"] = org_slug
27
+
28
+ json_since: str | Unset = UNSET
29
+ if not isinstance(since, Unset):
30
+ json_since = since.isoformat()
31
+ params["since"] = json_since
32
+
33
+ json_until: str | Unset = UNSET
34
+ if not isinstance(until, Unset):
35
+ json_until = until.isoformat()
36
+ params["until"] = json_until
37
+
38
+ params["cursor"] = cursor
39
+
40
+ params["limit"] = limit
41
+
42
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
43
+
44
+ _kwargs: dict[str, Any] = {
45
+ "method": "get",
46
+ "url": "/api/v1/unsubscribe/sms",
47
+ "params": params,
48
+ }
49
+
50
+ return _kwargs
51
+
52
+
53
+ def _parse_response(
54
+ *, client: AuthenticatedClient | Client, response: httpx.Response
55
+ ) -> (
56
+ PhoneUnsubscribeListResponse
57
+ | RestErrorResponse
58
+ | UnauthorizedOrganizationError
59
+ | None
60
+ ):
61
+ if response.status_code == 200:
62
+ response_200 = PhoneUnsubscribeListResponse.from_dict(response.json())
63
+
64
+ return response_200
65
+
66
+ if response.status_code == 400:
67
+ response_400 = RestErrorResponse.from_dict(response.json())
68
+
69
+ return response_400
70
+
71
+ if response.status_code == 401:
72
+ response_401 = RestErrorResponse.from_dict(response.json())
73
+
74
+ return response_401
75
+
76
+ if response.status_code == 403:
77
+ response_403 = UnauthorizedOrganizationError.from_dict(response.json())
78
+
79
+ return response_403
80
+
81
+ if response.status_code == 429:
82
+ response_429 = RestErrorResponse.from_dict(response.json())
83
+
84
+ return response_429
85
+
86
+ if client.raise_on_unexpected_status:
87
+ raise errors.UnexpectedStatus(response.status_code, response.content)
88
+ else:
89
+ return None
90
+
91
+
92
+ def _build_response(
93
+ *, client: AuthenticatedClient | Client, response: httpx.Response
94
+ ) -> Response[
95
+ PhoneUnsubscribeListResponse | RestErrorResponse | UnauthorizedOrganizationError
96
+ ]:
97
+ return Response(
98
+ status_code=HTTPStatus(response.status_code),
99
+ content=response.content,
100
+ headers=response.headers,
101
+ parsed=_parse_response(client=client, response=response),
102
+ )
103
+
104
+
105
+ def sync_detailed(
106
+ *,
107
+ client: AuthenticatedClient | Client,
108
+ org_slug: str | Unset = UNSET,
109
+ since: datetime.datetime | Unset = UNSET,
110
+ until: datetime.datetime | Unset = UNSET,
111
+ cursor: str | Unset = UNSET,
112
+ limit: int | Unset = 100,
113
+ ) -> Response[
114
+ PhoneUnsubscribeListResponse | RestErrorResponse | UnauthorizedOrganizationError
115
+ ]:
116
+ """List SMS opt-out / opt-in records
117
+
118
+ Returns the current state of SMS unsubscribe records for the organization addressed by `org_slug`
119
+ (or the `client_id`'s default organization when omitted), ordered by `updated_at` descending. Treat
120
+ the endpoint as a change stream: `since` / `until` bound the pagination window and `cursor` walks
121
+ toward older records. Rate limited to 60 requests per minute per `client_id`.
122
+
123
+ Args:
124
+ org_slug (str | Unset):
125
+ since (datetime.datetime | Unset):
126
+ until (datetime.datetime | Unset):
127
+ cursor (str | Unset):
128
+ limit (int | Unset): Default: 100.
129
+
130
+ Raises:
131
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
132
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
133
+
134
+ Returns:
135
+ Response[PhoneUnsubscribeListResponse | RestErrorResponse | UnauthorizedOrganizationError]
136
+ """
137
+
138
+ kwargs = _get_kwargs(
139
+ org_slug=org_slug,
140
+ since=since,
141
+ until=until,
142
+ cursor=cursor,
143
+ limit=limit,
144
+ )
145
+
146
+ response = client.get_httpx_client().request(
147
+ **kwargs,
148
+ )
149
+
150
+ return _build_response(client=client, response=response)
151
+
152
+
153
+ def sync(
154
+ *,
155
+ client: AuthenticatedClient | Client,
156
+ org_slug: str | Unset = UNSET,
157
+ since: datetime.datetime | Unset = UNSET,
158
+ until: datetime.datetime | Unset = UNSET,
159
+ cursor: str | Unset = UNSET,
160
+ limit: int | Unset = 100,
161
+ ) -> (
162
+ PhoneUnsubscribeListResponse
163
+ | RestErrorResponse
164
+ | UnauthorizedOrganizationError
165
+ | None
166
+ ):
167
+ """List SMS opt-out / opt-in records
168
+
169
+ Returns the current state of SMS unsubscribe records for the organization addressed by `org_slug`
170
+ (or the `client_id`'s default organization when omitted), ordered by `updated_at` descending. Treat
171
+ the endpoint as a change stream: `since` / `until` bound the pagination window and `cursor` walks
172
+ toward older records. Rate limited to 60 requests per minute per `client_id`.
173
+
174
+ Args:
175
+ org_slug (str | Unset):
176
+ since (datetime.datetime | Unset):
177
+ until (datetime.datetime | Unset):
178
+ cursor (str | Unset):
179
+ limit (int | Unset): Default: 100.
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
+ PhoneUnsubscribeListResponse | RestErrorResponse | UnauthorizedOrganizationError
187
+ """
188
+
189
+ return sync_detailed(
190
+ client=client,
191
+ org_slug=org_slug,
192
+ since=since,
193
+ until=until,
194
+ cursor=cursor,
195
+ limit=limit,
196
+ ).parsed
197
+
198
+
199
+ async def asyncio_detailed(
200
+ *,
201
+ client: AuthenticatedClient | Client,
202
+ org_slug: str | Unset = UNSET,
203
+ since: datetime.datetime | Unset = UNSET,
204
+ until: datetime.datetime | Unset = UNSET,
205
+ cursor: str | Unset = UNSET,
206
+ limit: int | Unset = 100,
207
+ ) -> Response[
208
+ PhoneUnsubscribeListResponse | RestErrorResponse | UnauthorizedOrganizationError
209
+ ]:
210
+ """List SMS opt-out / opt-in records
211
+
212
+ Returns the current state of SMS unsubscribe records for the organization addressed by `org_slug`
213
+ (or the `client_id`'s default organization when omitted), ordered by `updated_at` descending. Treat
214
+ the endpoint as a change stream: `since` / `until` bound the pagination window and `cursor` walks
215
+ toward older records. Rate limited to 60 requests per minute per `client_id`.
216
+
217
+ Args:
218
+ org_slug (str | Unset):
219
+ since (datetime.datetime | Unset):
220
+ until (datetime.datetime | Unset):
221
+ cursor (str | Unset):
222
+ limit (int | Unset): Default: 100.
223
+
224
+ Raises:
225
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
226
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
227
+
228
+ Returns:
229
+ Response[PhoneUnsubscribeListResponse | RestErrorResponse | UnauthorizedOrganizationError]
230
+ """
231
+
232
+ kwargs = _get_kwargs(
233
+ org_slug=org_slug,
234
+ since=since,
235
+ until=until,
236
+ cursor=cursor,
237
+ limit=limit,
238
+ )
239
+
240
+ response = await client.get_async_httpx_client().request(**kwargs)
241
+
242
+ return _build_response(client=client, response=response)
243
+
244
+
245
+ async def asyncio(
246
+ *,
247
+ client: AuthenticatedClient | Client,
248
+ org_slug: str | Unset = UNSET,
249
+ since: datetime.datetime | Unset = UNSET,
250
+ until: datetime.datetime | Unset = UNSET,
251
+ cursor: str | Unset = UNSET,
252
+ limit: int | Unset = 100,
253
+ ) -> (
254
+ PhoneUnsubscribeListResponse
255
+ | RestErrorResponse
256
+ | UnauthorizedOrganizationError
257
+ | None
258
+ ):
259
+ """List SMS opt-out / opt-in records
260
+
261
+ Returns the current state of SMS unsubscribe records for the organization addressed by `org_slug`
262
+ (or the `client_id`'s default organization when omitted), ordered by `updated_at` descending. Treat
263
+ the endpoint as a change stream: `since` / `until` bound the pagination window and `cursor` walks
264
+ toward older records. Rate limited to 60 requests per minute per `client_id`.
265
+
266
+ Args:
267
+ org_slug (str | Unset):
268
+ since (datetime.datetime | Unset):
269
+ until (datetime.datetime | Unset):
270
+ cursor (str | Unset):
271
+ limit (int | Unset): Default: 100.
272
+
273
+ Raises:
274
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
275
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
276
+
277
+ Returns:
278
+ PhoneUnsubscribeListResponse | RestErrorResponse | UnauthorizedOrganizationError
279
+ """
280
+
281
+ return (
282
+ await asyncio_detailed(
283
+ client=client,
284
+ org_slug=org_slug,
285
+ since=since,
286
+ until=until,
287
+ cursor=cursor,
288
+ limit=limit,
289
+ )
290
+ ).parsed
@@ -0,0 +1,232 @@
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.phone_unsubscribe_batch_request import PhoneUnsubscribeBatchRequest
9
+ from ...models.phone_unsubscribe_batch_response import PhoneUnsubscribeBatchResponse
10
+ from ...models.rest_error_response import RestErrorResponse
11
+ from ...models.unauthorized_organization_error import UnauthorizedOrganizationError
12
+ from ...types import Response
13
+
14
+
15
+ def _get_kwargs(
16
+ *,
17
+ body: PhoneUnsubscribeBatchRequest,
18
+ ) -> dict[str, Any]:
19
+ headers: dict[str, Any] = {}
20
+
21
+ _kwargs: dict[str, Any] = {
22
+ "method": "post",
23
+ "url": "/api/v1/unsubscribe/sms",
24
+ }
25
+
26
+ _kwargs["json"] = body.to_dict()
27
+
28
+ headers["Content-Type"] = "application/json"
29
+
30
+ _kwargs["headers"] = headers
31
+ return _kwargs
32
+
33
+
34
+ def _parse_response(
35
+ *, client: AuthenticatedClient | Client, response: httpx.Response
36
+ ) -> (
37
+ PhoneUnsubscribeBatchResponse
38
+ | RestErrorResponse
39
+ | UnauthorizedOrganizationError
40
+ | None
41
+ ):
42
+ if response.status_code == 200:
43
+ response_200 = PhoneUnsubscribeBatchResponse.from_dict(response.json())
44
+
45
+ return response_200
46
+
47
+ if response.status_code == 400:
48
+ response_400 = RestErrorResponse.from_dict(response.json())
49
+
50
+ return response_400
51
+
52
+ if response.status_code == 401:
53
+ response_401 = RestErrorResponse.from_dict(response.json())
54
+
55
+ return response_401
56
+
57
+ if response.status_code == 403:
58
+ response_403 = UnauthorizedOrganizationError.from_dict(response.json())
59
+
60
+ return response_403
61
+
62
+ if response.status_code == 422:
63
+ response_422 = PhoneUnsubscribeBatchResponse.from_dict(response.json())
64
+
65
+ return response_422
66
+
67
+ if response.status_code == 429:
68
+ response_429 = RestErrorResponse.from_dict(response.json())
69
+
70
+ return response_429
71
+
72
+ if client.raise_on_unexpected_status:
73
+ raise errors.UnexpectedStatus(response.status_code, response.content)
74
+ else:
75
+ return None
76
+
77
+
78
+ def _build_response(
79
+ *, client: AuthenticatedClient | Client, response: httpx.Response
80
+ ) -> Response[
81
+ PhoneUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
82
+ ]:
83
+ return Response(
84
+ status_code=HTTPStatus(response.status_code),
85
+ content=response.content,
86
+ headers=response.headers,
87
+ parsed=_parse_response(client=client, response=response),
88
+ )
89
+
90
+
91
+ def sync_detailed(
92
+ *,
93
+ client: AuthenticatedClient | Client,
94
+ body: PhoneUnsubscribeBatchRequest,
95
+ ) -> Response[
96
+ PhoneUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
97
+ ]:
98
+ """Push SMS opt-out / opt-in changes
99
+
100
+ Apply a batch of `{ phone, unsubscribed }` state changes to one organization — the value supplied in
101
+ `org_slug` (top-level body field) or the `client_id`'s default organization when omitted. Items are
102
+ processed in array order; per-item failures do NOT roll back accepted items. Up to 10,000 items per
103
+ request. Idempotent. Rate limited to 60 requests per minute per `client_id`.
104
+
105
+ Args:
106
+ body (PhoneUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
107
+ [{'phone': '+15551234567', 'unsubscribed': True}]}.
108
+
109
+ Raises:
110
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
111
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
112
+
113
+ Returns:
114
+ Response[PhoneUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError]
115
+ """
116
+
117
+ kwargs = _get_kwargs(
118
+ body=body,
119
+ )
120
+
121
+ response = client.get_httpx_client().request(
122
+ **kwargs,
123
+ )
124
+
125
+ return _build_response(client=client, response=response)
126
+
127
+
128
+ def sync(
129
+ *,
130
+ client: AuthenticatedClient | Client,
131
+ body: PhoneUnsubscribeBatchRequest,
132
+ ) -> (
133
+ PhoneUnsubscribeBatchResponse
134
+ | RestErrorResponse
135
+ | UnauthorizedOrganizationError
136
+ | None
137
+ ):
138
+ """Push SMS opt-out / opt-in changes
139
+
140
+ Apply a batch of `{ phone, unsubscribed }` state changes to one organization — the value supplied in
141
+ `org_slug` (top-level body field) or the `client_id`'s default organization when omitted. Items are
142
+ processed in array order; per-item failures do NOT roll back accepted items. Up to 10,000 items per
143
+ request. Idempotent. Rate limited to 60 requests per minute per `client_id`.
144
+
145
+ Args:
146
+ body (PhoneUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
147
+ [{'phone': '+15551234567', 'unsubscribed': True}]}.
148
+
149
+ Raises:
150
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
151
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
152
+
153
+ Returns:
154
+ PhoneUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
155
+ """
156
+
157
+ return sync_detailed(
158
+ client=client,
159
+ body=body,
160
+ ).parsed
161
+
162
+
163
+ async def asyncio_detailed(
164
+ *,
165
+ client: AuthenticatedClient | Client,
166
+ body: PhoneUnsubscribeBatchRequest,
167
+ ) -> Response[
168
+ PhoneUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
169
+ ]:
170
+ """Push SMS opt-out / opt-in changes
171
+
172
+ Apply a batch of `{ phone, unsubscribed }` state changes to one organization — the value supplied in
173
+ `org_slug` (top-level body field) or the `client_id`'s default organization when omitted. Items are
174
+ processed in array order; per-item failures do NOT roll back accepted items. Up to 10,000 items per
175
+ request. Idempotent. Rate limited to 60 requests per minute per `client_id`.
176
+
177
+ Args:
178
+ body (PhoneUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
179
+ [{'phone': '+15551234567', 'unsubscribed': True}]}.
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[PhoneUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError]
187
+ """
188
+
189
+ kwargs = _get_kwargs(
190
+ body=body,
191
+ )
192
+
193
+ response = await client.get_async_httpx_client().request(**kwargs)
194
+
195
+ return _build_response(client=client, response=response)
196
+
197
+
198
+ async def asyncio(
199
+ *,
200
+ client: AuthenticatedClient | Client,
201
+ body: PhoneUnsubscribeBatchRequest,
202
+ ) -> (
203
+ PhoneUnsubscribeBatchResponse
204
+ | RestErrorResponse
205
+ | UnauthorizedOrganizationError
206
+ | None
207
+ ):
208
+ """Push SMS opt-out / opt-in changes
209
+
210
+ Apply a batch of `{ phone, unsubscribed }` state changes to one organization — the value supplied in
211
+ `org_slug` (top-level body field) or the `client_id`'s default organization when omitted. Items are
212
+ processed in array order; per-item failures do NOT roll back accepted items. Up to 10,000 items per
213
+ request. Idempotent. Rate limited to 60 requests per minute per `client_id`.
214
+
215
+ Args:
216
+ body (PhoneUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
217
+ [{'phone': '+15551234567', 'unsubscribed': True}]}.
218
+
219
+ Raises:
220
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
221
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
222
+
223
+ Returns:
224
+ PhoneUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
225
+ """
226
+
227
+ return (
228
+ await asyncio_detailed(
229
+ client=client,
230
+ body=body,
231
+ )
232
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""