latitudesh-python-sdk 2.0.0__py3-none-any.whl → 2.0.1__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.

Potentially problematic release.


This version of latitudesh-python-sdk might be problematic. Click here for more details.

Files changed (43) hide show
  1. latitudesh_python_sdk/_version.py +3 -3
  2. latitudesh_python_sdk/apikeys.py +51 -138
  3. latitudesh_python_sdk/basesdk.py +4 -4
  4. latitudesh_python_sdk/billing.py +11 -32
  5. latitudesh_python_sdk/events_sdk.py +9 -34
  6. latitudesh_python_sdk/firewalls_sdk.py +89 -264
  7. latitudesh_python_sdk/ipaddresses_sdk.py +25 -68
  8. latitudesh_python_sdk/models/__init__.py +27 -4
  9. latitudesh_python_sdk/models/apierror.py +30 -14
  10. latitudesh_python_sdk/models/deploy_config.py +11 -6
  11. latitudesh_python_sdk/models/error_object.py +11 -6
  12. latitudesh_python_sdk/models/latitudesherror.py +26 -0
  13. latitudesh_python_sdk/models/no_response_error.py +13 -0
  14. latitudesh_python_sdk/models/region_resource_data.py +4 -4
  15. latitudesh_python_sdk/models/responsevalidationerror.py +25 -0
  16. latitudesh_python_sdk/models/server.py +11 -6
  17. latitudesh_python_sdk/models/server_data.py +6 -3
  18. latitudesh_python_sdk/models/server_region_resource_data.py +40 -0
  19. latitudesh_python_sdk/models/update_serverop.py +1 -3
  20. latitudesh_python_sdk/models/virtual_network.py +11 -6
  21. latitudesh_python_sdk/operatingsystems_sdk.py +11 -32
  22. latitudesh_python_sdk/plans.py +57 -188
  23. latitudesh_python_sdk/privatenetworks.py +87 -262
  24. latitudesh_python_sdk/projects_sdk.py +43 -130
  25. latitudesh_python_sdk/regions_sdk.py +21 -66
  26. latitudesh_python_sdk/roles.py +21 -64
  27. latitudesh_python_sdk/servers_sdk.py +207 -604
  28. latitudesh_python_sdk/sshkeys_sdk.py +85 -304
  29. latitudesh_python_sdk/storage.py +33 -120
  30. latitudesh_python_sdk/tags.py +39 -126
  31. latitudesh_python_sdk/teams_sdk.py +35 -100
  32. latitudesh_python_sdk/teamsmembers.py +31 -96
  33. latitudesh_python_sdk/traffic_sdk.py +25 -68
  34. latitudesh_python_sdk/userdata_sdk.py +79 -298
  35. latitudesh_python_sdk/userprofile.py +31 -100
  36. latitudesh_python_sdk/utils/serializers.py +3 -2
  37. latitudesh_python_sdk/utils/unmarshal_json_response.py +24 -0
  38. latitudesh_python_sdk/virtualmachines.py +35 -122
  39. latitudesh_python_sdk/vpnsessions.py +55 -146
  40. {latitudesh_python_sdk-2.0.0.dist-info → latitudesh_python_sdk-2.0.1.dist-info}/METADATA +47 -24
  41. {latitudesh_python_sdk-2.0.0.dist-info → latitudesh_python_sdk-2.0.1.dist-info}/RECORD +43 -38
  42. {latitudesh_python_sdk-2.0.0.dist-info → latitudesh_python_sdk-2.0.1.dist-info}/LICENSE +0 -0
  43. {latitudesh_python_sdk-2.0.0.dist-info → latitudesh_python_sdk-2.0.1.dist-info}/WHEEL +0 -0
@@ -5,6 +5,7 @@ from latitudesh_python_sdk import models, utils
5
5
  from latitudesh_python_sdk._hooks import HookContext
6
6
  from latitudesh_python_sdk.types import OptionalNullable, UNSET
7
7
  from latitudesh_python_sdk.utils import get_security_from_env
8
+ from latitudesh_python_sdk.utils.unmarshal_json_response import unmarshal_json_response
8
9
  from typing import Any, Mapping, Optional, Union
9
10
 
10
11
 
@@ -73,26 +74,15 @@ class TeamsSDK(BaseSDK):
73
74
  )
74
75
 
75
76
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
76
- return utils.unmarshal_json(http_res.text, models.Teams)
77
+ return unmarshal_json_response(models.Teams, http_res)
77
78
  if utils.match_response(http_res, "4XX", "*"):
78
79
  http_res_text = utils.stream_to_text(http_res)
79
- raise models.APIError(
80
- "API error occurred", http_res.status_code, http_res_text, http_res
81
- )
80
+ raise models.APIError("API error occurred", http_res, http_res_text)
82
81
  if utils.match_response(http_res, "5XX", "*"):
83
82
  http_res_text = utils.stream_to_text(http_res)
84
- raise models.APIError(
85
- "API error occurred", http_res.status_code, http_res_text, http_res
86
- )
83
+ raise models.APIError("API error occurred", http_res, http_res_text)
87
84
 
88
- content_type = http_res.headers.get("Content-Type")
89
- http_res_text = utils.stream_to_text(http_res)
90
- raise models.APIError(
91
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
92
- http_res.status_code,
93
- http_res_text,
94
- http_res,
95
- )
85
+ raise models.APIError("Unexpected response received", http_res)
96
86
 
97
87
  async def get_async(
98
88
  self,
@@ -158,26 +148,15 @@ class TeamsSDK(BaseSDK):
158
148
  )
159
149
 
160
150
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
161
- return utils.unmarshal_json(http_res.text, models.Teams)
151
+ return unmarshal_json_response(models.Teams, http_res)
162
152
  if utils.match_response(http_res, "4XX", "*"):
163
153
  http_res_text = await utils.stream_to_text_async(http_res)
164
- raise models.APIError(
165
- "API error occurred", http_res.status_code, http_res_text, http_res
166
- )
154
+ raise models.APIError("API error occurred", http_res, http_res_text)
167
155
  if utils.match_response(http_res, "5XX", "*"):
168
156
  http_res_text = await utils.stream_to_text_async(http_res)
169
- raise models.APIError(
170
- "API error occurred", http_res.status_code, http_res_text, http_res
171
- )
157
+ raise models.APIError("API error occurred", http_res, http_res_text)
172
158
 
173
- content_type = http_res.headers.get("Content-Type")
174
- http_res_text = await utils.stream_to_text_async(http_res)
175
- raise models.APIError(
176
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
177
- http_res.status_code,
178
- http_res_text,
179
- http_res,
180
- )
159
+ raise models.APIError("Unexpected response received", http_res)
181
160
 
182
161
  def create(
183
162
  self,
@@ -254,29 +233,18 @@ class TeamsSDK(BaseSDK):
254
233
 
255
234
  response_data: Any = None
256
235
  if utils.match_response(http_res, "201", "application/vnd.api+json"):
257
- return utils.unmarshal_json(http_res.text, models.PostTeamResponseBody)
236
+ return unmarshal_json_response(models.PostTeamResponseBody, http_res)
258
237
  if utils.match_response(http_res, ["406", "422"], "application/vnd.api+json"):
259
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
260
- raise models.ErrorObject(data=response_data)
238
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
239
+ raise models.ErrorObject(response_data, http_res)
261
240
  if utils.match_response(http_res, "4XX", "*"):
262
241
  http_res_text = utils.stream_to_text(http_res)
263
- raise models.APIError(
264
- "API error occurred", http_res.status_code, http_res_text, http_res
265
- )
242
+ raise models.APIError("API error occurred", http_res, http_res_text)
266
243
  if utils.match_response(http_res, "5XX", "*"):
267
244
  http_res_text = utils.stream_to_text(http_res)
268
- raise models.APIError(
269
- "API error occurred", http_res.status_code, http_res_text, http_res
270
- )
245
+ raise models.APIError("API error occurred", http_res, http_res_text)
271
246
 
272
- content_type = http_res.headers.get("Content-Type")
273
- http_res_text = utils.stream_to_text(http_res)
274
- raise models.APIError(
275
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
276
- http_res.status_code,
277
- http_res_text,
278
- http_res,
279
- )
247
+ raise models.APIError("Unexpected response received", http_res)
280
248
 
281
249
  async def create_async(
282
250
  self,
@@ -353,29 +321,18 @@ class TeamsSDK(BaseSDK):
353
321
 
354
322
  response_data: Any = None
355
323
  if utils.match_response(http_res, "201", "application/vnd.api+json"):
356
- return utils.unmarshal_json(http_res.text, models.PostTeamResponseBody)
324
+ return unmarshal_json_response(models.PostTeamResponseBody, http_res)
357
325
  if utils.match_response(http_res, ["406", "422"], "application/vnd.api+json"):
358
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
359
- raise models.ErrorObject(data=response_data)
326
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
327
+ raise models.ErrorObject(response_data, http_res)
360
328
  if utils.match_response(http_res, "4XX", "*"):
361
329
  http_res_text = await utils.stream_to_text_async(http_res)
362
- raise models.APIError(
363
- "API error occurred", http_res.status_code, http_res_text, http_res
364
- )
330
+ raise models.APIError("API error occurred", http_res, http_res_text)
365
331
  if utils.match_response(http_res, "5XX", "*"):
366
332
  http_res_text = await utils.stream_to_text_async(http_res)
367
- raise models.APIError(
368
- "API error occurred", http_res.status_code, http_res_text, http_res
369
- )
333
+ raise models.APIError("API error occurred", http_res, http_res_text)
370
334
 
371
- content_type = http_res.headers.get("Content-Type")
372
- http_res_text = await utils.stream_to_text_async(http_res)
373
- raise models.APIError(
374
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
375
- http_res.status_code,
376
- http_res_text,
377
- http_res,
378
- )
335
+ raise models.APIError("Unexpected response received", http_res)
379
336
 
380
337
  def update(
381
338
  self,
@@ -463,31 +420,20 @@ class TeamsSDK(BaseSDK):
463
420
 
464
421
  response_data: Any = None
465
422
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
466
- return utils.unmarshal_json(
467
- http_res.text, models.PatchCurrentTeamResponseBody
423
+ return unmarshal_json_response(
424
+ models.PatchCurrentTeamResponseBody, http_res
468
425
  )
469
426
  if utils.match_response(http_res, ["403", "404"], "application/vnd.api+json"):
470
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
471
- raise models.ErrorObject(data=response_data)
427
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
428
+ raise models.ErrorObject(response_data, http_res)
472
429
  if utils.match_response(http_res, "4XX", "*"):
473
430
  http_res_text = utils.stream_to_text(http_res)
474
- raise models.APIError(
475
- "API error occurred", http_res.status_code, http_res_text, http_res
476
- )
431
+ raise models.APIError("API error occurred", http_res, http_res_text)
477
432
  if utils.match_response(http_res, "5XX", "*"):
478
433
  http_res_text = utils.stream_to_text(http_res)
479
- raise models.APIError(
480
- "API error occurred", http_res.status_code, http_res_text, http_res
481
- )
434
+ raise models.APIError("API error occurred", http_res, http_res_text)
482
435
 
483
- content_type = http_res.headers.get("Content-Type")
484
- http_res_text = utils.stream_to_text(http_res)
485
- raise models.APIError(
486
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
487
- http_res.status_code,
488
- http_res_text,
489
- http_res,
490
- )
436
+ raise models.APIError("Unexpected response received", http_res)
491
437
 
492
438
  async def update_async(
493
439
  self,
@@ -575,28 +521,17 @@ class TeamsSDK(BaseSDK):
575
521
 
576
522
  response_data: Any = None
577
523
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
578
- return utils.unmarshal_json(
579
- http_res.text, models.PatchCurrentTeamResponseBody
524
+ return unmarshal_json_response(
525
+ models.PatchCurrentTeamResponseBody, http_res
580
526
  )
581
527
  if utils.match_response(http_res, ["403", "404"], "application/vnd.api+json"):
582
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
583
- raise models.ErrorObject(data=response_data)
528
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
529
+ raise models.ErrorObject(response_data, http_res)
584
530
  if utils.match_response(http_res, "4XX", "*"):
585
531
  http_res_text = await utils.stream_to_text_async(http_res)
586
- raise models.APIError(
587
- "API error occurred", http_res.status_code, http_res_text, http_res
588
- )
532
+ raise models.APIError("API error occurred", http_res, http_res_text)
589
533
  if utils.match_response(http_res, "5XX", "*"):
590
534
  http_res_text = await utils.stream_to_text_async(http_res)
591
- raise models.APIError(
592
- "API error occurred", http_res.status_code, http_res_text, http_res
593
- )
535
+ raise models.APIError("API error occurred", http_res, http_res_text)
594
536
 
595
- content_type = http_res.headers.get("Content-Type")
596
- http_res_text = await utils.stream_to_text_async(http_res)
597
- raise models.APIError(
598
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
599
- http_res.status_code,
600
- http_res_text,
601
- http_res,
602
- )
537
+ raise models.APIError("Unexpected response received", http_res)
@@ -6,6 +6,7 @@ from latitudesh_python_sdk import models, utils
6
6
  from latitudesh_python_sdk._hooks import HookContext
7
7
  from latitudesh_python_sdk.types import OptionalNullable, UNSET
8
8
  from latitudesh_python_sdk.utils import get_security_from_env
9
+ from latitudesh_python_sdk.utils.unmarshal_json_response import unmarshal_json_response
9
10
  from typing import Any, Dict, List, Mapping, Optional, Union
10
11
 
11
12
 
@@ -105,28 +106,17 @@ class TeamsMembers(BaseSDK):
105
106
 
106
107
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
107
108
  return models.GetTeamMembersResponse(
108
- result=utils.unmarshal_json(http_res.text, models.TeamMembers),
109
+ result=unmarshal_json_response(models.TeamMembers, http_res),
109
110
  next=next_func,
110
111
  )
111
112
  if utils.match_response(http_res, "4XX", "*"):
112
113
  http_res_text = utils.stream_to_text(http_res)
113
- raise models.APIError(
114
- "API error occurred", http_res.status_code, http_res_text, http_res
115
- )
114
+ raise models.APIError("API error occurred", http_res, http_res_text)
116
115
  if utils.match_response(http_res, "5XX", "*"):
117
116
  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
- )
117
+ raise models.APIError("API error occurred", http_res, http_res_text)
121
118
 
122
- content_type = http_res.headers.get("Content-Type")
123
- http_res_text = utils.stream_to_text(http_res)
124
- raise models.APIError(
125
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
126
- http_res.status_code,
127
- http_res_text,
128
- http_res,
129
- )
119
+ raise models.APIError("Unexpected response received", http_res)
130
120
 
131
121
  async def list_async(
132
122
  self,
@@ -223,28 +213,17 @@ class TeamsMembers(BaseSDK):
223
213
 
224
214
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
225
215
  return models.GetTeamMembersResponse(
226
- result=utils.unmarshal_json(http_res.text, models.TeamMembers),
216
+ result=unmarshal_json_response(models.TeamMembers, http_res),
227
217
  next=next_func,
228
218
  )
229
219
  if utils.match_response(http_res, "4XX", "*"):
230
220
  http_res_text = await utils.stream_to_text_async(http_res)
231
- raise models.APIError(
232
- "API error occurred", http_res.status_code, http_res_text, http_res
233
- )
221
+ raise models.APIError("API error occurred", http_res, http_res_text)
234
222
  if utils.match_response(http_res, "5XX", "*"):
235
223
  http_res_text = await utils.stream_to_text_async(http_res)
236
- raise models.APIError(
237
- "API error occurred", http_res.status_code, http_res_text, http_res
238
- )
224
+ raise models.APIError("API error occurred", http_res, http_res_text)
239
225
 
240
- content_type = http_res.headers.get("Content-Type")
241
- http_res_text = await utils.stream_to_text_async(http_res)
242
- raise models.APIError(
243
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
244
- http_res.status_code,
245
- http_res_text,
246
- http_res,
247
- )
226
+ raise models.APIError("Unexpected response received", http_res)
248
227
 
249
228
  def add(
250
229
  self,
@@ -328,29 +307,18 @@ class TeamsMembers(BaseSDK):
328
307
 
329
308
  response_data: Any = None
330
309
  if utils.match_response(http_res, "201", "application/vnd.api+json"):
331
- return utils.unmarshal_json(http_res.text, models.Membership)
310
+ return unmarshal_json_response(models.Membership, http_res)
332
311
  if utils.match_response(http_res, ["403", "422"], "application/vnd.api+json"):
333
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
334
- raise models.ErrorObject(data=response_data)
312
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
313
+ raise models.ErrorObject(response_data, http_res)
335
314
  if utils.match_response(http_res, "4XX", "*"):
336
315
  http_res_text = utils.stream_to_text(http_res)
337
- raise models.APIError(
338
- "API error occurred", http_res.status_code, http_res_text, http_res
339
- )
316
+ raise models.APIError("API error occurred", http_res, http_res_text)
340
317
  if utils.match_response(http_res, "5XX", "*"):
341
318
  http_res_text = utils.stream_to_text(http_res)
342
- raise models.APIError(
343
- "API error occurred", http_res.status_code, http_res_text, http_res
344
- )
319
+ raise models.APIError("API error occurred", http_res, http_res_text)
345
320
 
346
- content_type = http_res.headers.get("Content-Type")
347
- http_res_text = utils.stream_to_text(http_res)
348
- raise models.APIError(
349
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
350
- http_res.status_code,
351
- http_res_text,
352
- http_res,
353
- )
321
+ raise models.APIError("Unexpected response received", http_res)
354
322
 
355
323
  async def add_async(
356
324
  self,
@@ -434,29 +402,18 @@ class TeamsMembers(BaseSDK):
434
402
 
435
403
  response_data: Any = None
436
404
  if utils.match_response(http_res, "201", "application/vnd.api+json"):
437
- return utils.unmarshal_json(http_res.text, models.Membership)
405
+ return unmarshal_json_response(models.Membership, http_res)
438
406
  if utils.match_response(http_res, ["403", "422"], "application/vnd.api+json"):
439
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
440
- raise models.ErrorObject(data=response_data)
407
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
408
+ raise models.ErrorObject(response_data, http_res)
441
409
  if utils.match_response(http_res, "4XX", "*"):
442
410
  http_res_text = await utils.stream_to_text_async(http_res)
443
- raise models.APIError(
444
- "API error occurred", http_res.status_code, http_res_text, http_res
445
- )
411
+ raise models.APIError("API error occurred", http_res, http_res_text)
446
412
  if utils.match_response(http_res, "5XX", "*"):
447
413
  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
- )
414
+ raise models.APIError("API error occurred", http_res, http_res_text)
451
415
 
452
- content_type = http_res.headers.get("Content-Type")
453
- http_res_text = await utils.stream_to_text_async(http_res)
454
- raise models.APIError(
455
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
456
- http_res.status_code,
457
- http_res_text,
458
- http_res,
459
- )
416
+ raise models.APIError("Unexpected response received", http_res)
460
417
 
461
418
  def remove_member(
462
419
  self,
@@ -532,27 +489,16 @@ class TeamsMembers(BaseSDK):
532
489
  if utils.match_response(http_res, "200", "*"):
533
490
  return
534
491
  if utils.match_response(http_res, "404", "application/vnd.api+json"):
535
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
536
- raise models.ErrorObject(data=response_data)
492
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
493
+ raise models.ErrorObject(response_data, http_res)
537
494
  if utils.match_response(http_res, ["403", "4XX"], "*"):
538
495
  http_res_text = utils.stream_to_text(http_res)
539
- raise models.APIError(
540
- "API error occurred", http_res.status_code, http_res_text, http_res
541
- )
496
+ raise models.APIError("API error occurred", http_res, http_res_text)
542
497
  if utils.match_response(http_res, "5XX", "*"):
543
498
  http_res_text = utils.stream_to_text(http_res)
544
- raise models.APIError(
545
- "API error occurred", http_res.status_code, http_res_text, http_res
546
- )
499
+ raise models.APIError("API error occurred", http_res, http_res_text)
547
500
 
548
- content_type = http_res.headers.get("Content-Type")
549
- http_res_text = utils.stream_to_text(http_res)
550
- raise models.APIError(
551
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
552
- http_res.status_code,
553
- http_res_text,
554
- http_res,
555
- )
501
+ raise models.APIError("Unexpected response received", http_res)
556
502
 
557
503
  async def remove_member_async(
558
504
  self,
@@ -628,24 +574,13 @@ class TeamsMembers(BaseSDK):
628
574
  if utils.match_response(http_res, "200", "*"):
629
575
  return
630
576
  if utils.match_response(http_res, "404", "application/vnd.api+json"):
631
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
632
- raise models.ErrorObject(data=response_data)
577
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
578
+ raise models.ErrorObject(response_data, http_res)
633
579
  if utils.match_response(http_res, ["403", "4XX"], "*"):
634
580
  http_res_text = await utils.stream_to_text_async(http_res)
635
- raise models.APIError(
636
- "API error occurred", http_res.status_code, http_res_text, http_res
637
- )
581
+ raise models.APIError("API error occurred", http_res, http_res_text)
638
582
  if utils.match_response(http_res, "5XX", "*"):
639
583
  http_res_text = await utils.stream_to_text_async(http_res)
640
- raise models.APIError(
641
- "API error occurred", http_res.status_code, http_res_text, http_res
642
- )
584
+ raise models.APIError("API error occurred", http_res, http_res_text)
643
585
 
644
- content_type = http_res.headers.get("Content-Type")
645
- http_res_text = await utils.stream_to_text_async(http_res)
646
- raise models.APIError(
647
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
648
- http_res.status_code,
649
- http_res_text,
650
- http_res,
651
- )
586
+ raise models.APIError("Unexpected response received", http_res)
@@ -5,6 +5,7 @@ from latitudesh_python_sdk import models, utils
5
5
  from latitudesh_python_sdk._hooks import HookContext
6
6
  from latitudesh_python_sdk.types import OptionalNullable, UNSET
7
7
  from latitudesh_python_sdk.utils import get_security_from_env
8
+ from latitudesh_python_sdk.utils.unmarshal_json_response import unmarshal_json_response
8
9
  from typing import Any, Mapping, Optional
9
10
 
10
11
 
@@ -89,26 +90,15 @@ class TrafficSDK(BaseSDK):
89
90
  )
90
91
 
91
92
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
92
- return utils.unmarshal_json(http_res.text, models.Traffic)
93
+ return unmarshal_json_response(models.Traffic, http_res)
93
94
  if utils.match_response(http_res, ["422", "4XX"], "*"):
94
95
  http_res_text = utils.stream_to_text(http_res)
95
- raise models.APIError(
96
- "API error occurred", http_res.status_code, http_res_text, http_res
97
- )
96
+ raise models.APIError("API error occurred", http_res, http_res_text)
98
97
  if utils.match_response(http_res, "5XX", "*"):
99
98
  http_res_text = utils.stream_to_text(http_res)
100
- raise models.APIError(
101
- "API error occurred", http_res.status_code, http_res_text, http_res
102
- )
103
-
104
- content_type = http_res.headers.get("Content-Type")
105
- http_res_text = utils.stream_to_text(http_res)
106
- raise models.APIError(
107
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
108
- http_res.status_code,
109
- http_res_text,
110
- http_res,
111
- )
99
+ raise models.APIError("API error occurred", http_res, http_res_text)
100
+
101
+ raise models.APIError("Unexpected response received", http_res)
112
102
 
113
103
  async def get_async(
114
104
  self,
@@ -190,26 +180,15 @@ class TrafficSDK(BaseSDK):
190
180
  )
191
181
 
192
182
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
193
- return utils.unmarshal_json(http_res.text, models.Traffic)
183
+ return unmarshal_json_response(models.Traffic, http_res)
194
184
  if utils.match_response(http_res, ["422", "4XX"], "*"):
195
185
  http_res_text = await utils.stream_to_text_async(http_res)
196
- raise models.APIError(
197
- "API error occurred", http_res.status_code, http_res_text, http_res
198
- )
186
+ raise models.APIError("API error occurred", http_res, http_res_text)
199
187
  if utils.match_response(http_res, "5XX", "*"):
200
188
  http_res_text = await utils.stream_to_text_async(http_res)
201
- raise models.APIError(
202
- "API error occurred", http_res.status_code, http_res_text, http_res
203
- )
204
-
205
- content_type = http_res.headers.get("Content-Type")
206
- http_res_text = await utils.stream_to_text_async(http_res)
207
- raise models.APIError(
208
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
209
- http_res.status_code,
210
- http_res_text,
211
- http_res,
212
- )
189
+ raise models.APIError("API error occurred", http_res, http_res_text)
190
+
191
+ raise models.APIError("Unexpected response received", http_res)
213
192
 
214
193
  def get_quota(
215
194
  self,
@@ -283,29 +262,18 @@ class TrafficSDK(BaseSDK):
283
262
 
284
263
  response_data: Any = None
285
264
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
286
- return utils.unmarshal_json(http_res.text, models.TrafficQuota)
265
+ return unmarshal_json_response(models.TrafficQuota, http_res)
287
266
  if utils.match_response(http_res, "503", "application/vnd.api+json"):
288
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
289
- raise models.ErrorObject(data=response_data)
267
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
268
+ raise models.ErrorObject(response_data, http_res)
290
269
  if utils.match_response(http_res, "4XX", "*"):
291
270
  http_res_text = utils.stream_to_text(http_res)
292
- raise models.APIError(
293
- "API error occurred", http_res.status_code, http_res_text, http_res
294
- )
271
+ raise models.APIError("API error occurred", http_res, http_res_text)
295
272
  if utils.match_response(http_res, "5XX", "*"):
296
273
  http_res_text = utils.stream_to_text(http_res)
297
- raise models.APIError(
298
- "API error occurred", http_res.status_code, http_res_text, http_res
299
- )
300
-
301
- content_type = http_res.headers.get("Content-Type")
302
- http_res_text = utils.stream_to_text(http_res)
303
- raise models.APIError(
304
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
305
- http_res.status_code,
306
- http_res_text,
307
- http_res,
308
- )
274
+ raise models.APIError("API error occurred", http_res, http_res_text)
275
+
276
+ raise models.APIError("Unexpected response received", http_res)
309
277
 
310
278
  async def get_quota_async(
311
279
  self,
@@ -379,26 +347,15 @@ class TrafficSDK(BaseSDK):
379
347
 
380
348
  response_data: Any = None
381
349
  if utils.match_response(http_res, "200", "application/vnd.api+json"):
382
- return utils.unmarshal_json(http_res.text, models.TrafficQuota)
350
+ return unmarshal_json_response(models.TrafficQuota, http_res)
383
351
  if utils.match_response(http_res, "503", "application/vnd.api+json"):
384
- response_data = utils.unmarshal_json(http_res.text, models.ErrorObjectData)
385
- raise models.ErrorObject(data=response_data)
352
+ response_data = unmarshal_json_response(models.ErrorObjectData, http_res)
353
+ raise models.ErrorObject(response_data, http_res)
386
354
  if utils.match_response(http_res, "4XX", "*"):
387
355
  http_res_text = await utils.stream_to_text_async(http_res)
388
- raise models.APIError(
389
- "API error occurred", http_res.status_code, http_res_text, http_res
390
- )
356
+ raise models.APIError("API error occurred", http_res, http_res_text)
391
357
  if utils.match_response(http_res, "5XX", "*"):
392
358
  http_res_text = await utils.stream_to_text_async(http_res)
393
- raise models.APIError(
394
- "API error occurred", http_res.status_code, http_res_text, http_res
395
- )
396
-
397
- content_type = http_res.headers.get("Content-Type")
398
- http_res_text = await utils.stream_to_text_async(http_res)
399
- raise models.APIError(
400
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
401
- http_res.status_code,
402
- http_res_text,
403
- http_res,
404
- )
359
+ raise models.APIError("API error occurred", http_res, http_res_text)
360
+
361
+ raise models.APIError("Unexpected response received", http_res)