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,236 @@
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.email_unsubscribe_batch_request import EmailUnsubscribeBatchRequest
9
+ from ...models.email_unsubscribe_batch_response import EmailUnsubscribeBatchResponse
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: EmailUnsubscribeBatchRequest,
18
+ ) -> dict[str, Any]:
19
+ headers: dict[str, Any] = {}
20
+
21
+ _kwargs: dict[str, Any] = {
22
+ "method": "post",
23
+ "url": "/api/v1/unsubscribe/email",
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
+ EmailUnsubscribeBatchResponse
38
+ | RestErrorResponse
39
+ | UnauthorizedOrganizationError
40
+ | None
41
+ ):
42
+ if response.status_code == 200:
43
+ response_200 = EmailUnsubscribeBatchResponse.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 = EmailUnsubscribeBatchResponse.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
+ EmailUnsubscribeBatchResponse | 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: EmailUnsubscribeBatchRequest,
95
+ ) -> Response[
96
+ EmailUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
97
+ ]:
98
+ """Push email opt-out / opt-in changes
99
+
100
+ Apply a batch of `{ email, 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 (EmailUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
107
+ [{'email': 'john@example.com', 'unsubscribed': True}, {'email': 'alice@example.com',
108
+ 'unsubscribed': False}]}.
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[EmailUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError]
116
+ """
117
+
118
+ kwargs = _get_kwargs(
119
+ body=body,
120
+ )
121
+
122
+ response = client.get_httpx_client().request(
123
+ **kwargs,
124
+ )
125
+
126
+ return _build_response(client=client, response=response)
127
+
128
+
129
+ def sync(
130
+ *,
131
+ client: AuthenticatedClient | Client,
132
+ body: EmailUnsubscribeBatchRequest,
133
+ ) -> (
134
+ EmailUnsubscribeBatchResponse
135
+ | RestErrorResponse
136
+ | UnauthorizedOrganizationError
137
+ | None
138
+ ):
139
+ """Push email opt-out / opt-in changes
140
+
141
+ Apply a batch of `{ email, unsubscribed }` state changes to one organization — the value supplied in
142
+ `org_slug` (top-level body field) or the `client_id`'s default organization when omitted. Items are
143
+ processed in array order; per-item failures do NOT roll back accepted items. Up to 10,000 items per
144
+ request. Idempotent. Rate limited to 60 requests per minute per `client_id`.
145
+
146
+ Args:
147
+ body (EmailUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
148
+ [{'email': 'john@example.com', 'unsubscribed': True}, {'email': 'alice@example.com',
149
+ 'unsubscribed': False}]}.
150
+
151
+ Raises:
152
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
153
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
154
+
155
+ Returns:
156
+ EmailUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
157
+ """
158
+
159
+ return sync_detailed(
160
+ client=client,
161
+ body=body,
162
+ ).parsed
163
+
164
+
165
+ async def asyncio_detailed(
166
+ *,
167
+ client: AuthenticatedClient | Client,
168
+ body: EmailUnsubscribeBatchRequest,
169
+ ) -> Response[
170
+ EmailUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
171
+ ]:
172
+ """Push email opt-out / opt-in changes
173
+
174
+ Apply a batch of `{ email, unsubscribed }` state changes to one organization — the value supplied in
175
+ `org_slug` (top-level body field) or the `client_id`'s default organization when omitted. Items are
176
+ processed in array order; per-item failures do NOT roll back accepted items. Up to 10,000 items per
177
+ request. Idempotent. Rate limited to 60 requests per minute per `client_id`.
178
+
179
+ Args:
180
+ body (EmailUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
181
+ [{'email': 'john@example.com', 'unsubscribed': True}, {'email': 'alice@example.com',
182
+ 'unsubscribed': False}]}.
183
+
184
+ Raises:
185
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
186
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
187
+
188
+ Returns:
189
+ Response[EmailUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError]
190
+ """
191
+
192
+ kwargs = _get_kwargs(
193
+ body=body,
194
+ )
195
+
196
+ response = await client.get_async_httpx_client().request(**kwargs)
197
+
198
+ return _build_response(client=client, response=response)
199
+
200
+
201
+ async def asyncio(
202
+ *,
203
+ client: AuthenticatedClient | Client,
204
+ body: EmailUnsubscribeBatchRequest,
205
+ ) -> (
206
+ EmailUnsubscribeBatchResponse
207
+ | RestErrorResponse
208
+ | UnauthorizedOrganizationError
209
+ | None
210
+ ):
211
+ """Push email opt-out / opt-in changes
212
+
213
+ Apply a batch of `{ email, unsubscribed }` state changes to one organization — the value supplied in
214
+ `org_slug` (top-level body field) or the `client_id`'s default organization when omitted. Items are
215
+ processed in array order; per-item failures do NOT roll back accepted items. Up to 10,000 items per
216
+ request. Idempotent. Rate limited to 60 requests per minute per `client_id`.
217
+
218
+ Args:
219
+ body (EmailUnsubscribeBatchRequest): Example: {'org_slug': 'acme-corp', 'items':
220
+ [{'email': 'john@example.com', 'unsubscribed': True}, {'email': 'alice@example.com',
221
+ 'unsubscribed': False}]}.
222
+
223
+ Raises:
224
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
225
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
226
+
227
+ Returns:
228
+ EmailUnsubscribeBatchResponse | RestErrorResponse | UnauthorizedOrganizationError
229
+ """
230
+
231
+ return (
232
+ await asyncio_detailed(
233
+ client=client,
234
+ body=body,
235
+ )
236
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,241 @@
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.o_auth_client_credentials_request import OAuthClientCredentialsRequest
9
+ from ...models.o_auth_error_response import OAuthErrorResponse
10
+ from ...models.o_auth_refresh_token_request import OAuthRefreshTokenRequest
11
+ from ...models.o_auth_token_response import OAuthTokenResponse
12
+ from ...models.rest_error_response import RestErrorResponse
13
+ from ...types import Response
14
+
15
+
16
+ def _get_kwargs(
17
+ *,
18
+ body: OAuthClientCredentialsRequest | OAuthRefreshTokenRequest,
19
+ ) -> dict[str, Any]:
20
+ headers: dict[str, Any] = {}
21
+
22
+ _kwargs: dict[str, Any] = {
23
+ "method": "post",
24
+ "url": "/oauth/token",
25
+ }
26
+
27
+ _kwargs["data"] = body.to_dict()
28
+ headers["Content-Type"] = "application/x-www-form-urlencoded"
29
+
30
+ _kwargs["headers"] = headers
31
+ return _kwargs
32
+
33
+
34
+ def _parse_response(
35
+ *, client: AuthenticatedClient | Client, response: httpx.Response
36
+ ) -> OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse | None:
37
+ if response.status_code == 200:
38
+ response_200 = OAuthTokenResponse.from_dict(response.json())
39
+
40
+ return response_200
41
+
42
+ if response.status_code == 400:
43
+ response_400 = OAuthErrorResponse.from_dict(response.json())
44
+
45
+ return response_400
46
+
47
+ if response.status_code == 401:
48
+ response_401 = OAuthErrorResponse.from_dict(response.json())
49
+
50
+ return response_401
51
+
52
+ if response.status_code == 429:
53
+ response_429 = RestErrorResponse.from_dict(response.json())
54
+
55
+ return response_429
56
+
57
+ if client.raise_on_unexpected_status:
58
+ raise errors.UnexpectedStatus(response.status_code, response.content)
59
+ else:
60
+ return None
61
+
62
+
63
+ def _build_response(
64
+ *, client: AuthenticatedClient | Client, response: httpx.Response
65
+ ) -> Response[OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse]:
66
+ return Response(
67
+ status_code=HTTPStatus(response.status_code),
68
+ content=response.content,
69
+ headers=response.headers,
70
+ parsed=_parse_response(client=client, response=response),
71
+ )
72
+
73
+
74
+ def sync_detailed(
75
+ *,
76
+ client: AuthenticatedClient,
77
+ body: OAuthClientCredentialsRequest | OAuthRefreshTokenRequest,
78
+ ) -> Response[OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse]:
79
+ """Issue or refresh an access token
80
+
81
+ Exchange client credentials (or a refresh token) for a short-lived bearer access token. Accepts both
82
+ grants:
83
+
84
+ - `grant_type=client_credentials` — initial authentication. Credentials may be sent via the
85
+ `Authorization: Basic` header (preferred — see [RFC 6749
86
+ §2.3.1](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1)) or as `client_id` /
87
+ `client_secret` body fields.
88
+ - `grant_type=refresh_token` — renewal. Returns a new access token AND a new refresh token; the
89
+ previous refresh token is invalidated immediately. Refresh tokens are single-use — any reuse revokes
90
+ every active token for the `client_id` and the partner must re-authenticate via
91
+ `client_credentials`.
92
+
93
+ Access tokens live 15 minutes. Refresh tokens live 30 days and are rotated on every use. Rate
94
+ limited to 10 requests per minute per `client_id`.
95
+
96
+ Args:
97
+ body (OAuthClientCredentialsRequest | OAuthRefreshTokenRequest): Token request body.
98
+ Discriminated on `grant_type`.
99
+
100
+ Raises:
101
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
102
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
103
+
104
+ Returns:
105
+ Response[OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse]
106
+ """
107
+
108
+ kwargs = _get_kwargs(
109
+ body=body,
110
+ )
111
+
112
+ response = client.get_httpx_client().request(
113
+ **kwargs,
114
+ )
115
+
116
+ return _build_response(client=client, response=response)
117
+
118
+
119
+ def sync(
120
+ *,
121
+ client: AuthenticatedClient,
122
+ body: OAuthClientCredentialsRequest | OAuthRefreshTokenRequest,
123
+ ) -> OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse | None:
124
+ """Issue or refresh an access token
125
+
126
+ Exchange client credentials (or a refresh token) for a short-lived bearer access token. Accepts both
127
+ grants:
128
+
129
+ - `grant_type=client_credentials` — initial authentication. Credentials may be sent via the
130
+ `Authorization: Basic` header (preferred — see [RFC 6749
131
+ §2.3.1](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1)) or as `client_id` /
132
+ `client_secret` body fields.
133
+ - `grant_type=refresh_token` — renewal. Returns a new access token AND a new refresh token; the
134
+ previous refresh token is invalidated immediately. Refresh tokens are single-use — any reuse revokes
135
+ every active token for the `client_id` and the partner must re-authenticate via
136
+ `client_credentials`.
137
+
138
+ Access tokens live 15 minutes. Refresh tokens live 30 days and are rotated on every use. Rate
139
+ limited to 10 requests per minute per `client_id`.
140
+
141
+ Args:
142
+ body (OAuthClientCredentialsRequest | OAuthRefreshTokenRequest): Token request body.
143
+ Discriminated on `grant_type`.
144
+
145
+ Raises:
146
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
147
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
148
+
149
+ Returns:
150
+ OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse
151
+ """
152
+
153
+ return sync_detailed(
154
+ client=client,
155
+ body=body,
156
+ ).parsed
157
+
158
+
159
+ async def asyncio_detailed(
160
+ *,
161
+ client: AuthenticatedClient,
162
+ body: OAuthClientCredentialsRequest | OAuthRefreshTokenRequest,
163
+ ) -> Response[OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse]:
164
+ """Issue or refresh an access token
165
+
166
+ Exchange client credentials (or a refresh token) for a short-lived bearer access token. Accepts both
167
+ grants:
168
+
169
+ - `grant_type=client_credentials` — initial authentication. Credentials may be sent via the
170
+ `Authorization: Basic` header (preferred — see [RFC 6749
171
+ §2.3.1](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1)) or as `client_id` /
172
+ `client_secret` body fields.
173
+ - `grant_type=refresh_token` — renewal. Returns a new access token AND a new refresh token; the
174
+ previous refresh token is invalidated immediately. Refresh tokens are single-use — any reuse revokes
175
+ every active token for the `client_id` and the partner must re-authenticate via
176
+ `client_credentials`.
177
+
178
+ Access tokens live 15 minutes. Refresh tokens live 30 days and are rotated on every use. Rate
179
+ limited to 10 requests per minute per `client_id`.
180
+
181
+ Args:
182
+ body (OAuthClientCredentialsRequest | OAuthRefreshTokenRequest): Token request body.
183
+ Discriminated on `grant_type`.
184
+
185
+ Raises:
186
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
187
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
188
+
189
+ Returns:
190
+ Response[OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse]
191
+ """
192
+
193
+ kwargs = _get_kwargs(
194
+ body=body,
195
+ )
196
+
197
+ response = await client.get_async_httpx_client().request(**kwargs)
198
+
199
+ return _build_response(client=client, response=response)
200
+
201
+
202
+ async def asyncio(
203
+ *,
204
+ client: AuthenticatedClient,
205
+ body: OAuthClientCredentialsRequest | OAuthRefreshTokenRequest,
206
+ ) -> OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse | None:
207
+ """Issue or refresh an access token
208
+
209
+ Exchange client credentials (or a refresh token) for a short-lived bearer access token. Accepts both
210
+ grants:
211
+
212
+ - `grant_type=client_credentials` — initial authentication. Credentials may be sent via the
213
+ `Authorization: Basic` header (preferred — see [RFC 6749
214
+ §2.3.1](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1)) or as `client_id` /
215
+ `client_secret` body fields.
216
+ - `grant_type=refresh_token` — renewal. Returns a new access token AND a new refresh token; the
217
+ previous refresh token is invalidated immediately. Refresh tokens are single-use — any reuse revokes
218
+ every active token for the `client_id` and the partner must re-authenticate via
219
+ `client_credentials`.
220
+
221
+ Access tokens live 15 minutes. Refresh tokens live 30 days and are rotated on every use. Rate
222
+ limited to 10 requests per minute per `client_id`.
223
+
224
+ Args:
225
+ body (OAuthClientCredentialsRequest | OAuthRefreshTokenRequest): Token request body.
226
+ Discriminated on `grant_type`.
227
+
228
+ Raises:
229
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
230
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
231
+
232
+ Returns:
233
+ OAuthErrorResponse | OAuthTokenResponse | RestErrorResponse
234
+ """
235
+
236
+ return (
237
+ await asyncio_detailed(
238
+ client=client,
239
+ body=body,
240
+ )
241
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""