syllable-sdk 0.35.32__py3-none-any.whl → 0.35.34__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 (51) hide show
  1. syllable_sdk/__init__.py +0 -1
  2. syllable_sdk/_version.py +3 -3
  3. syllable_sdk/agents.py +80 -211
  4. syllable_sdk/basesdk.py +5 -5
  5. syllable_sdk/batches.py +132 -329
  6. syllable_sdk/campaigns.py +74 -183
  7. syllable_sdk/channels.py +30 -73
  8. syllable_sdk/conversations.py +16 -37
  9. syllable_sdk/custom_messages.py +74 -183
  10. syllable_sdk/dashboards.py +64 -195
  11. syllable_sdk/data_sources.py +74 -183
  12. syllable_sdk/errors/__init__.py +55 -0
  13. syllable_sdk/errors/apierror.py +38 -0
  14. syllable_sdk/errors/httpvalidationerror.py +26 -0
  15. syllable_sdk/errors/no_response_error.py +13 -0
  16. syllable_sdk/errors/responsevalidationerror.py +25 -0
  17. syllable_sdk/errors/syllablesdkerror.py +26 -0
  18. syllable_sdk/events.py +16 -37
  19. syllable_sdk/folders.py +116 -295
  20. syllable_sdk/full_summary.py +16 -37
  21. syllable_sdk/incidents.py +84 -215
  22. syllable_sdk/insights_sdk.py +16 -41
  23. syllable_sdk/insights_tools.py +96 -253
  24. syllable_sdk/language_groups.py +86 -215
  25. syllable_sdk/latency.py +16 -37
  26. syllable_sdk/models/__init__.py +0 -8
  27. syllable_sdk/numbers.py +44 -113
  28. syllable_sdk/organizations.py +52 -139
  29. syllable_sdk/permissions.py +12 -33
  30. syllable_sdk/prompts.py +94 -251
  31. syllable_sdk/roles.py +72 -181
  32. syllable_sdk/services.py +72 -185
  33. syllable_sdk/session_debug.py +44 -109
  34. syllable_sdk/session_labels.py +44 -109
  35. syllable_sdk/sessions.py +56 -141
  36. syllable_sdk/takeouts.py +36 -99
  37. syllable_sdk/targets.py +74 -187
  38. syllable_sdk/test.py +16 -37
  39. syllable_sdk/tools.py +72 -181
  40. syllable_sdk/transcript.py +18 -39
  41. syllable_sdk/twilio.py +44 -109
  42. syllable_sdk/users.py +94 -247
  43. syllable_sdk/utils/serializers.py +3 -2
  44. syllable_sdk/utils/unmarshal_json_response.py +24 -0
  45. syllable_sdk/v1.py +94 -247
  46. syllable_sdk/workflows.py +116 -291
  47. {syllable_sdk-0.35.32.dist-info → syllable_sdk-0.35.34.dist-info}/METADATA +58 -45
  48. {syllable_sdk-0.35.32.dist-info → syllable_sdk-0.35.34.dist-info}/RECORD +49 -44
  49. syllable_sdk/models/apierror.py +0 -22
  50. syllable_sdk/models/httpvalidationerror.py +0 -21
  51. {syllable_sdk-0.35.32.dist-info → syllable_sdk-0.35.34.dist-info}/WHEEL +0 -0
syllable_sdk/users.py CHANGED
@@ -1,10 +1,11 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
3
  from .basesdk import BaseSDK
4
- from syllable_sdk import models, utils
4
+ from syllable_sdk import errors, models, utils
5
5
  from syllable_sdk._hooks import HookContext
6
6
  from syllable_sdk.types import BaseModel, OptionalNullable, UNSET
7
7
  from syllable_sdk.utils import get_security_from_env
8
+ from syllable_sdk.utils.unmarshal_json_response import unmarshal_json_response
8
9
  from typing import Any, List, Mapping, Optional, Union, cast
9
10
 
10
11
 
@@ -107,31 +108,20 @@ class Users(BaseSDK):
107
108
 
108
109
  response_data: Any = None
109
110
  if utils.match_response(http_res, "200", "application/json"):
110
- return utils.unmarshal_json(http_res.text, models.ListResponseUserResponse)
111
+ return unmarshal_json_response(models.ListResponseUserResponse, http_res)
111
112
  if utils.match_response(http_res, "422", "application/json"):
112
- response_data = utils.unmarshal_json(
113
- http_res.text, models.HTTPValidationErrorData
113
+ response_data = unmarshal_json_response(
114
+ errors.HTTPValidationErrorData, http_res
114
115
  )
115
- raise models.HTTPValidationError(data=response_data)
116
+ raise errors.HTTPValidationError(response_data, http_res)
116
117
  if utils.match_response(http_res, "4XX", "*"):
117
118
  http_res_text = utils.stream_to_text(http_res)
118
- raise models.APIError(
119
- "API error occurred", http_res.status_code, http_res_text, http_res
120
- )
119
+ raise errors.APIError("API error occurred", http_res, http_res_text)
121
120
  if utils.match_response(http_res, "5XX", "*"):
122
121
  http_res_text = utils.stream_to_text(http_res)
123
- raise models.APIError(
124
- "API error occurred", http_res.status_code, http_res_text, http_res
125
- )
122
+ raise errors.APIError("API error occurred", http_res, http_res_text)
126
123
 
127
- content_type = http_res.headers.get("Content-Type")
128
- http_res_text = utils.stream_to_text(http_res)
129
- raise models.APIError(
130
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
131
- http_res.status_code,
132
- http_res_text,
133
- http_res,
134
- )
124
+ raise errors.APIError("Unexpected response received", http_res)
135
125
 
136
126
  async def list_async(
137
127
  self,
@@ -231,31 +221,20 @@ class Users(BaseSDK):
231
221
 
232
222
  response_data: Any = None
233
223
  if utils.match_response(http_res, "200", "application/json"):
234
- return utils.unmarshal_json(http_res.text, models.ListResponseUserResponse)
224
+ return unmarshal_json_response(models.ListResponseUserResponse, http_res)
235
225
  if utils.match_response(http_res, "422", "application/json"):
236
- response_data = utils.unmarshal_json(
237
- http_res.text, models.HTTPValidationErrorData
226
+ response_data = unmarshal_json_response(
227
+ errors.HTTPValidationErrorData, http_res
238
228
  )
239
- raise models.HTTPValidationError(data=response_data)
229
+ raise errors.HTTPValidationError(response_data, http_res)
240
230
  if utils.match_response(http_res, "4XX", "*"):
241
231
  http_res_text = await utils.stream_to_text_async(http_res)
242
- raise models.APIError(
243
- "API error occurred", http_res.status_code, http_res_text, http_res
244
- )
232
+ raise errors.APIError("API error occurred", http_res, http_res_text)
245
233
  if utils.match_response(http_res, "5XX", "*"):
246
234
  http_res_text = await utils.stream_to_text_async(http_res)
247
- raise models.APIError(
248
- "API error occurred", http_res.status_code, http_res_text, http_res
249
- )
235
+ raise errors.APIError("API error occurred", http_res, http_res_text)
250
236
 
251
- content_type = http_res.headers.get("Content-Type")
252
- http_res_text = await utils.stream_to_text_async(http_res)
253
- raise models.APIError(
254
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
255
- http_res.status_code,
256
- http_res_text,
257
- http_res,
258
- )
237
+ raise errors.APIError("Unexpected response received", http_res)
259
238
 
260
239
  def create(
261
240
  self,
@@ -334,31 +313,20 @@ class Users(BaseSDK):
334
313
 
335
314
  response_data: Any = None
336
315
  if utils.match_response(http_res, "200", "application/json"):
337
- return utils.unmarshal_json(http_res.text, models.UserResponse)
316
+ return unmarshal_json_response(models.UserResponse, http_res)
338
317
  if utils.match_response(http_res, "422", "application/json"):
339
- response_data = utils.unmarshal_json(
340
- http_res.text, models.HTTPValidationErrorData
318
+ response_data = unmarshal_json_response(
319
+ errors.HTTPValidationErrorData, http_res
341
320
  )
342
- raise models.HTTPValidationError(data=response_data)
321
+ raise errors.HTTPValidationError(response_data, http_res)
343
322
  if utils.match_response(http_res, "4XX", "*"):
344
323
  http_res_text = utils.stream_to_text(http_res)
345
- raise models.APIError(
346
- "API error occurred", http_res.status_code, http_res_text, http_res
347
- )
324
+ raise errors.APIError("API error occurred", http_res, http_res_text)
348
325
  if utils.match_response(http_res, "5XX", "*"):
349
326
  http_res_text = utils.stream_to_text(http_res)
350
- raise models.APIError(
351
- "API error occurred", http_res.status_code, http_res_text, http_res
352
- )
327
+ raise errors.APIError("API error occurred", http_res, http_res_text)
353
328
 
354
- content_type = http_res.headers.get("Content-Type")
355
- http_res_text = utils.stream_to_text(http_res)
356
- raise models.APIError(
357
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
358
- http_res.status_code,
359
- http_res_text,
360
- http_res,
361
- )
329
+ raise errors.APIError("Unexpected response received", http_res)
362
330
 
363
331
  async def create_async(
364
332
  self,
@@ -437,31 +405,20 @@ class Users(BaseSDK):
437
405
 
438
406
  response_data: Any = None
439
407
  if utils.match_response(http_res, "200", "application/json"):
440
- return utils.unmarshal_json(http_res.text, models.UserResponse)
408
+ return unmarshal_json_response(models.UserResponse, http_res)
441
409
  if utils.match_response(http_res, "422", "application/json"):
442
- response_data = utils.unmarshal_json(
443
- http_res.text, models.HTTPValidationErrorData
410
+ response_data = unmarshal_json_response(
411
+ errors.HTTPValidationErrorData, http_res
444
412
  )
445
- raise models.HTTPValidationError(data=response_data)
413
+ raise errors.HTTPValidationError(response_data, http_res)
446
414
  if utils.match_response(http_res, "4XX", "*"):
447
415
  http_res_text = await utils.stream_to_text_async(http_res)
448
- raise models.APIError(
449
- "API error occurred", http_res.status_code, http_res_text, http_res
450
- )
416
+ raise errors.APIError("API error occurred", http_res, http_res_text)
451
417
  if utils.match_response(http_res, "5XX", "*"):
452
418
  http_res_text = await utils.stream_to_text_async(http_res)
453
- raise models.APIError(
454
- "API error occurred", http_res.status_code, http_res_text, http_res
455
- )
419
+ raise errors.APIError("API error occurred", http_res, http_res_text)
456
420
 
457
- content_type = http_res.headers.get("Content-Type")
458
- http_res_text = await utils.stream_to_text_async(http_res)
459
- raise models.APIError(
460
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
461
- http_res.status_code,
462
- http_res_text,
463
- http_res,
464
- )
421
+ raise errors.APIError("Unexpected response received", http_res)
465
422
 
466
423
  def update(
467
424
  self,
@@ -540,31 +497,20 @@ class Users(BaseSDK):
540
497
 
541
498
  response_data: Any = None
542
499
  if utils.match_response(http_res, "200", "application/json"):
543
- return utils.unmarshal_json(http_res.text, models.UserResponse)
500
+ return unmarshal_json_response(models.UserResponse, http_res)
544
501
  if utils.match_response(http_res, "422", "application/json"):
545
- response_data = utils.unmarshal_json(
546
- http_res.text, models.HTTPValidationErrorData
502
+ response_data = unmarshal_json_response(
503
+ errors.HTTPValidationErrorData, http_res
547
504
  )
548
- raise models.HTTPValidationError(data=response_data)
505
+ raise errors.HTTPValidationError(response_data, http_res)
549
506
  if utils.match_response(http_res, "4XX", "*"):
550
507
  http_res_text = utils.stream_to_text(http_res)
551
- raise models.APIError(
552
- "API error occurred", http_res.status_code, http_res_text, http_res
553
- )
508
+ raise errors.APIError("API error occurred", http_res, http_res_text)
554
509
  if utils.match_response(http_res, "5XX", "*"):
555
510
  http_res_text = utils.stream_to_text(http_res)
556
- raise models.APIError(
557
- "API error occurred", http_res.status_code, http_res_text, http_res
558
- )
511
+ raise errors.APIError("API error occurred", http_res, http_res_text)
559
512
 
560
- content_type = http_res.headers.get("Content-Type")
561
- http_res_text = utils.stream_to_text(http_res)
562
- raise models.APIError(
563
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
564
- http_res.status_code,
565
- http_res_text,
566
- http_res,
567
- )
513
+ raise errors.APIError("Unexpected response received", http_res)
568
514
 
569
515
  async def update_async(
570
516
  self,
@@ -643,31 +589,20 @@ class Users(BaseSDK):
643
589
 
644
590
  response_data: Any = None
645
591
  if utils.match_response(http_res, "200", "application/json"):
646
- return utils.unmarshal_json(http_res.text, models.UserResponse)
592
+ return unmarshal_json_response(models.UserResponse, http_res)
647
593
  if utils.match_response(http_res, "422", "application/json"):
648
- response_data = utils.unmarshal_json(
649
- http_res.text, models.HTTPValidationErrorData
594
+ response_data = unmarshal_json_response(
595
+ errors.HTTPValidationErrorData, http_res
650
596
  )
651
- raise models.HTTPValidationError(data=response_data)
597
+ raise errors.HTTPValidationError(response_data, http_res)
652
598
  if utils.match_response(http_res, "4XX", "*"):
653
599
  http_res_text = await utils.stream_to_text_async(http_res)
654
- raise models.APIError(
655
- "API error occurred", http_res.status_code, http_res_text, http_res
656
- )
600
+ raise errors.APIError("API error occurred", http_res, http_res_text)
657
601
  if utils.match_response(http_res, "5XX", "*"):
658
602
  http_res_text = await utils.stream_to_text_async(http_res)
659
- raise models.APIError(
660
- "API error occurred", http_res.status_code, http_res_text, http_res
661
- )
603
+ raise errors.APIError("API error occurred", http_res, http_res_text)
662
604
 
663
- content_type = http_res.headers.get("Content-Type")
664
- http_res_text = await utils.stream_to_text_async(http_res)
665
- raise models.APIError(
666
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
667
- http_res.status_code,
668
- http_res_text,
669
- http_res,
670
- )
605
+ raise errors.APIError("Unexpected response received", http_res)
671
606
 
672
607
  def delete(
673
608
  self,
@@ -746,31 +681,20 @@ class Users(BaseSDK):
746
681
 
747
682
  response_data: Any = None
748
683
  if utils.match_response(http_res, "200", "application/json"):
749
- return utils.unmarshal_json(http_res.text, Any)
684
+ return unmarshal_json_response(Any, http_res)
750
685
  if utils.match_response(http_res, "422", "application/json"):
751
- response_data = utils.unmarshal_json(
752
- http_res.text, models.HTTPValidationErrorData
686
+ response_data = unmarshal_json_response(
687
+ errors.HTTPValidationErrorData, http_res
753
688
  )
754
- raise models.HTTPValidationError(data=response_data)
689
+ raise errors.HTTPValidationError(response_data, http_res)
755
690
  if utils.match_response(http_res, "4XX", "*"):
756
691
  http_res_text = utils.stream_to_text(http_res)
757
- raise models.APIError(
758
- "API error occurred", http_res.status_code, http_res_text, http_res
759
- )
692
+ raise errors.APIError("API error occurred", http_res, http_res_text)
760
693
  if utils.match_response(http_res, "5XX", "*"):
761
694
  http_res_text = utils.stream_to_text(http_res)
762
- raise models.APIError(
763
- "API error occurred", http_res.status_code, http_res_text, http_res
764
- )
695
+ raise errors.APIError("API error occurred", http_res, http_res_text)
765
696
 
766
- content_type = http_res.headers.get("Content-Type")
767
- http_res_text = utils.stream_to_text(http_res)
768
- raise models.APIError(
769
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
770
- http_res.status_code,
771
- http_res_text,
772
- http_res,
773
- )
697
+ raise errors.APIError("Unexpected response received", http_res)
774
698
 
775
699
  async def delete_async(
776
700
  self,
@@ -849,31 +773,20 @@ class Users(BaseSDK):
849
773
 
850
774
  response_data: Any = None
851
775
  if utils.match_response(http_res, "200", "application/json"):
852
- return utils.unmarshal_json(http_res.text, Any)
776
+ return unmarshal_json_response(Any, http_res)
853
777
  if utils.match_response(http_res, "422", "application/json"):
854
- response_data = utils.unmarshal_json(
855
- http_res.text, models.HTTPValidationErrorData
778
+ response_data = unmarshal_json_response(
779
+ errors.HTTPValidationErrorData, http_res
856
780
  )
857
- raise models.HTTPValidationError(data=response_data)
781
+ raise errors.HTTPValidationError(response_data, http_res)
858
782
  if utils.match_response(http_res, "4XX", "*"):
859
783
  http_res_text = await utils.stream_to_text_async(http_res)
860
- raise models.APIError(
861
- "API error occurred", http_res.status_code, http_res_text, http_res
862
- )
784
+ raise errors.APIError("API error occurred", http_res, http_res_text)
863
785
  if utils.match_response(http_res, "5XX", "*"):
864
786
  http_res_text = await utils.stream_to_text_async(http_res)
865
- raise models.APIError(
866
- "API error occurred", http_res.status_code, http_res_text, http_res
867
- )
787
+ raise errors.APIError("API error occurred", http_res, http_res_text)
868
788
 
869
- content_type = http_res.headers.get("Content-Type")
870
- http_res_text = await utils.stream_to_text_async(http_res)
871
- raise models.APIError(
872
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
873
- http_res.status_code,
874
- http_res_text,
875
- http_res,
876
- )
789
+ raise errors.APIError("Unexpected response received", http_res)
877
790
 
878
791
  def users_get_by_email(
879
792
  self,
@@ -949,31 +862,20 @@ class Users(BaseSDK):
949
862
 
950
863
  response_data: Any = None
951
864
  if utils.match_response(http_res, "200", "application/json"):
952
- return utils.unmarshal_json(http_res.text, models.UserResponse)
865
+ return unmarshal_json_response(models.UserResponse, http_res)
953
866
  if utils.match_response(http_res, "422", "application/json"):
954
- response_data = utils.unmarshal_json(
955
- http_res.text, models.HTTPValidationErrorData
867
+ response_data = unmarshal_json_response(
868
+ errors.HTTPValidationErrorData, http_res
956
869
  )
957
- raise models.HTTPValidationError(data=response_data)
870
+ raise errors.HTTPValidationError(response_data, http_res)
958
871
  if utils.match_response(http_res, "4XX", "*"):
959
872
  http_res_text = utils.stream_to_text(http_res)
960
- raise models.APIError(
961
- "API error occurred", http_res.status_code, http_res_text, http_res
962
- )
873
+ raise errors.APIError("API error occurred", http_res, http_res_text)
963
874
  if utils.match_response(http_res, "5XX", "*"):
964
875
  http_res_text = utils.stream_to_text(http_res)
965
- raise models.APIError(
966
- "API error occurred", http_res.status_code, http_res_text, http_res
967
- )
876
+ raise errors.APIError("API error occurred", http_res, http_res_text)
968
877
 
969
- content_type = http_res.headers.get("Content-Type")
970
- http_res_text = utils.stream_to_text(http_res)
971
- raise models.APIError(
972
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
973
- http_res.status_code,
974
- http_res_text,
975
- http_res,
976
- )
878
+ raise errors.APIError("Unexpected response received", http_res)
977
879
 
978
880
  async def users_get_by_email_async(
979
881
  self,
@@ -1049,31 +951,20 @@ class Users(BaseSDK):
1049
951
 
1050
952
  response_data: Any = None
1051
953
  if utils.match_response(http_res, "200", "application/json"):
1052
- return utils.unmarshal_json(http_res.text, models.UserResponse)
954
+ return unmarshal_json_response(models.UserResponse, http_res)
1053
955
  if utils.match_response(http_res, "422", "application/json"):
1054
- response_data = utils.unmarshal_json(
1055
- http_res.text, models.HTTPValidationErrorData
956
+ response_data = unmarshal_json_response(
957
+ errors.HTTPValidationErrorData, http_res
1056
958
  )
1057
- raise models.HTTPValidationError(data=response_data)
959
+ raise errors.HTTPValidationError(response_data, http_res)
1058
960
  if utils.match_response(http_res, "4XX", "*"):
1059
961
  http_res_text = await utils.stream_to_text_async(http_res)
1060
- raise models.APIError(
1061
- "API error occurred", http_res.status_code, http_res_text, http_res
1062
- )
962
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1063
963
  if utils.match_response(http_res, "5XX", "*"):
1064
964
  http_res_text = await utils.stream_to_text_async(http_res)
1065
- raise models.APIError(
1066
- "API error occurred", http_res.status_code, http_res_text, http_res
1067
- )
965
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1068
966
 
1069
- content_type = http_res.headers.get("Content-Type")
1070
- http_res_text = await utils.stream_to_text_async(http_res)
1071
- raise models.APIError(
1072
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1073
- http_res.status_code,
1074
- http_res_text,
1075
- http_res,
1076
- )
967
+ raise errors.APIError("Unexpected response received", http_res)
1077
968
 
1078
969
  def users_send_email(
1079
970
  self,
@@ -1149,31 +1040,20 @@ class Users(BaseSDK):
1149
1040
 
1150
1041
  response_data: Any = None
1151
1042
  if utils.match_response(http_res, "200", "application/json"):
1152
- return utils.unmarshal_json(http_res.text, Any)
1043
+ return unmarshal_json_response(Any, http_res)
1153
1044
  if utils.match_response(http_res, "422", "application/json"):
1154
- response_data = utils.unmarshal_json(
1155
- http_res.text, models.HTTPValidationErrorData
1045
+ response_data = unmarshal_json_response(
1046
+ errors.HTTPValidationErrorData, http_res
1156
1047
  )
1157
- raise models.HTTPValidationError(data=response_data)
1048
+ raise errors.HTTPValidationError(response_data, http_res)
1158
1049
  if utils.match_response(http_res, "4XX", "*"):
1159
1050
  http_res_text = utils.stream_to_text(http_res)
1160
- raise models.APIError(
1161
- "API error occurred", http_res.status_code, http_res_text, http_res
1162
- )
1051
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1163
1052
  if utils.match_response(http_res, "5XX", "*"):
1164
1053
  http_res_text = utils.stream_to_text(http_res)
1165
- raise models.APIError(
1166
- "API error occurred", http_res.status_code, http_res_text, http_res
1167
- )
1054
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1168
1055
 
1169
- content_type = http_res.headers.get("Content-Type")
1170
- http_res_text = utils.stream_to_text(http_res)
1171
- raise models.APIError(
1172
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1173
- http_res.status_code,
1174
- http_res_text,
1175
- http_res,
1176
- )
1056
+ raise errors.APIError("Unexpected response received", http_res)
1177
1057
 
1178
1058
  async def users_send_email_async(
1179
1059
  self,
@@ -1249,31 +1129,20 @@ class Users(BaseSDK):
1249
1129
 
1250
1130
  response_data: Any = None
1251
1131
  if utils.match_response(http_res, "200", "application/json"):
1252
- return utils.unmarshal_json(http_res.text, Any)
1132
+ return unmarshal_json_response(Any, http_res)
1253
1133
  if utils.match_response(http_res, "422", "application/json"):
1254
- response_data = utils.unmarshal_json(
1255
- http_res.text, models.HTTPValidationErrorData
1134
+ response_data = unmarshal_json_response(
1135
+ errors.HTTPValidationErrorData, http_res
1256
1136
  )
1257
- raise models.HTTPValidationError(data=response_data)
1137
+ raise errors.HTTPValidationError(response_data, http_res)
1258
1138
  if utils.match_response(http_res, "4XX", "*"):
1259
1139
  http_res_text = await utils.stream_to_text_async(http_res)
1260
- raise models.APIError(
1261
- "API error occurred", http_res.status_code, http_res_text, http_res
1262
- )
1140
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1263
1141
  if utils.match_response(http_res, "5XX", "*"):
1264
1142
  http_res_text = await utils.stream_to_text_async(http_res)
1265
- raise models.APIError(
1266
- "API error occurred", http_res.status_code, http_res_text, http_res
1267
- )
1143
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1268
1144
 
1269
- content_type = http_res.headers.get("Content-Type")
1270
- http_res_text = await utils.stream_to_text_async(http_res)
1271
- raise models.APIError(
1272
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1273
- http_res.status_code,
1274
- http_res_text,
1275
- http_res,
1276
- )
1145
+ raise errors.APIError("Unexpected response received", http_res)
1277
1146
 
1278
1147
  def users_delete_account(
1279
1148
  self,
@@ -1342,26 +1211,15 @@ class Users(BaseSDK):
1342
1211
  )
1343
1212
 
1344
1213
  if utils.match_response(http_res, "200", "application/json"):
1345
- return utils.unmarshal_json(http_res.text, Any)
1214
+ return unmarshal_json_response(Any, http_res)
1346
1215
  if utils.match_response(http_res, "4XX", "*"):
1347
1216
  http_res_text = utils.stream_to_text(http_res)
1348
- raise models.APIError(
1349
- "API error occurred", http_res.status_code, http_res_text, http_res
1350
- )
1217
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1351
1218
  if utils.match_response(http_res, "5XX", "*"):
1352
1219
  http_res_text = utils.stream_to_text(http_res)
1353
- raise models.APIError(
1354
- "API error occurred", http_res.status_code, http_res_text, http_res
1355
- )
1220
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1356
1221
 
1357
- content_type = http_res.headers.get("Content-Type")
1358
- http_res_text = utils.stream_to_text(http_res)
1359
- raise models.APIError(
1360
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1361
- http_res.status_code,
1362
- http_res_text,
1363
- http_res,
1364
- )
1222
+ raise errors.APIError("Unexpected response received", http_res)
1365
1223
 
1366
1224
  async def users_delete_account_async(
1367
1225
  self,
@@ -1430,23 +1288,12 @@ class Users(BaseSDK):
1430
1288
  )
1431
1289
 
1432
1290
  if utils.match_response(http_res, "200", "application/json"):
1433
- return utils.unmarshal_json(http_res.text, Any)
1291
+ return unmarshal_json_response(Any, http_res)
1434
1292
  if utils.match_response(http_res, "4XX", "*"):
1435
1293
  http_res_text = await utils.stream_to_text_async(http_res)
1436
- raise models.APIError(
1437
- "API error occurred", http_res.status_code, http_res_text, http_res
1438
- )
1294
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1439
1295
  if utils.match_response(http_res, "5XX", "*"):
1440
1296
  http_res_text = await utils.stream_to_text_async(http_res)
1441
- raise models.APIError(
1442
- "API error occurred", http_res.status_code, http_res_text, http_res
1443
- )
1297
+ raise errors.APIError("API error occurred", http_res, http_res_text)
1444
1298
 
1445
- content_type = http_res.headers.get("Content-Type")
1446
- http_res_text = await utils.stream_to_text_async(http_res)
1447
- raise models.APIError(
1448
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1449
- http_res.status_code,
1450
- http_res_text,
1451
- http_res,
1452
- )
1299
+ raise errors.APIError("Unexpected response received", http_res)
@@ -192,7 +192,9 @@ def is_union(obj: object) -> bool:
192
192
  """
193
193
  Returns True if the given object is a typing.Union or typing_extensions.Union.
194
194
  """
195
- return any(obj is typing_obj for typing_obj in _get_typing_objects_by_name_of("Union"))
195
+ return any(
196
+ obj is typing_obj for typing_obj in _get_typing_objects_by_name_of("Union")
197
+ )
196
198
 
197
199
 
198
200
  def stream_to_text(stream: httpx.Response) -> str:
@@ -245,4 +247,3 @@ def _get_typing_objects_by_name_of(name: str) -> Tuple[Any, ...]:
245
247
  f"Neither typing nor typing_extensions has an object called {name!r}"
246
248
  )
247
249
  return result
248
-
@@ -0,0 +1,24 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from typing import Any, Optional
4
+
5
+ import httpx
6
+
7
+ from .serializers import unmarshal_json
8
+ from syllable_sdk import errors
9
+
10
+
11
+ def unmarshal_json_response(
12
+ typ: Any, http_res: httpx.Response, body: Optional[str] = None
13
+ ) -> Any:
14
+ if body is None:
15
+ body = http_res.text
16
+ try:
17
+ return unmarshal_json(body, typ)
18
+ except Exception as e:
19
+ raise errors.ResponseValidationError(
20
+ "Response validation failed",
21
+ http_res,
22
+ e,
23
+ body,
24
+ ) from e