|
13 | 13 | from vws._async_vws_request import async_target_api_request |
14 | 14 | from vws._image_utils import ImageType as _ImageType |
15 | 15 | from vws._image_utils import get_image_data as _get_image_data |
| 16 | +from vws._json_utils import json_object, string_field, string_list_field |
16 | 17 | from vws._reco_counts import ( |
17 | 18 | reco_counts_report_body, |
18 | 19 | reco_counts_report_path, |
@@ -152,12 +153,15 @@ async def make_request( |
152 | 153 | ): # pragma: no cover |
153 | 154 | raise ServerError(response=response) |
154 | 155 |
|
155 | | - result_code = json.loads(s=response.text)["result_code"] # pyrefly: ignore [unknown-variable-type] |
| 156 | + result_code = string_field( |
| 157 | + value=json_object(value=response.text), |
| 158 | + name="result_code", |
| 159 | + ) |
156 | 160 | if result_code == expected_result_code: |
157 | 161 | return response |
158 | 162 |
|
159 | 163 | raise VWSError.from_result_code( |
160 | | - result_code=result_code, # pyrefly: ignore [unknown-argument-type] |
| 164 | + result_code=result_code, |
161 | 165 | response=response, |
162 | 166 | ) |
163 | 167 |
|
@@ -238,7 +242,10 @@ async def add_target( |
238 | 242 | content_type="application/json", |
239 | 243 | ) |
240 | 244 |
|
241 | | - return str(object=json.loads(s=response.text)["target_id"]) # pyrefly: ignore [unknown-argument-type] |
| 245 | + return string_field( |
| 246 | + value=json_object(value=response.text), |
| 247 | + name="target_id", |
| 248 | + ) |
242 | 249 |
|
243 | 250 | async def get_target_record(self, target_id: str) -> TargetStatusAndRecord: |
244 | 251 | """Get a given target's target record from the Target |
@@ -276,7 +283,7 @@ async def get_target_record(self, target_id: str) -> TargetStatusAndRecord: |
276 | 283 | content_type="application/json", |
277 | 284 | ) |
278 | 285 |
|
279 | | - result_data = json.loads(s=response.text) |
| 286 | + result_data = json_object(value=response.text) |
280 | 287 | return TargetStatusAndRecord.from_response_dict( |
281 | 288 | response_dict=result_data, |
282 | 289 | ) |
@@ -373,7 +380,10 @@ async def list_targets(self) -> list[str]: |
373 | 380 | content_type="application/json", |
374 | 381 | ) |
375 | 382 |
|
376 | | - return list(json.loads(s=response.text)["results"]) # pyrefly: ignore [unknown-argument-type] |
| 383 | + return string_list_field( |
| 384 | + value=json_object(value=response.text), |
| 385 | + name="results", |
| 386 | + ) |
377 | 387 |
|
378 | 388 | async def get_target_summary_report( |
379 | 389 | self, target_id: str |
@@ -413,7 +423,7 @@ async def get_target_summary_report( |
413 | 423 | content_type="application/json", |
414 | 424 | ) |
415 | 425 |
|
416 | | - result_data = dict(json.loads(s=response.text)) |
| 426 | + result_data = json_object(value=response.text) |
417 | 427 | return TargetSummaryReport.from_response_dict( |
418 | 428 | response_dict=result_data, |
419 | 429 | ) |
@@ -450,7 +460,7 @@ async def get_database_summary_report( |
450 | 460 | content_type="application/json", |
451 | 461 | ) |
452 | 462 |
|
453 | | - response_data = dict(json.loads(s=response.text)) |
| 463 | + response_data = json_object(value=response.text) |
454 | 464 | return DatabaseSummaryReport.from_response_dict( |
455 | 465 | response_dict=response_data, |
456 | 466 | ) |
@@ -504,7 +514,7 @@ async def request_database_reco_counts_report( |
504 | 514 | content_type="application/json", |
505 | 515 | ) |
506 | 516 |
|
507 | | - response_data = dict(json.loads(s=response.text)) |
| 517 | + response_data = json_object(value=response.text) |
508 | 518 | return RecoCountsReportRequest.from_response_dict( |
509 | 519 | response_dict=response_data, |
510 | 520 | ) |
@@ -657,8 +667,9 @@ async def get_duplicate_targets(self, target_id: str) -> list[str]: |
657 | 667 | content_type="application/json", |
658 | 668 | ) |
659 | 669 |
|
660 | | - return list( |
661 | | - json.loads(s=response.text)["similar_targets"], # pyrefly: ignore [unknown-argument-type] |
| 670 | + return string_list_field( |
| 671 | + value=json_object(value=response.text), |
| 672 | + name="similar_targets", |
662 | 673 | ) |
663 | 674 |
|
664 | 675 | async def update_target( |
|
0 commit comments