|
23 | 23 | ProjectInactive, |
24 | 24 | TargetNameExist, |
25 | 25 | TargetProcessingTimeout, |
| 26 | + TargetStatusNotSuccess, |
26 | 27 | TargetStatusProcessing, |
27 | 28 | UnknownTarget, |
28 | 29 | ) |
@@ -111,6 +112,7 @@ def _raise_for_result_code( |
111 | 112 | 'ProjectInactive': ProjectInactive, |
112 | 113 | 'TargetNameExist': TargetNameExist, |
113 | 114 | 'TargetStatusProcessing': TargetStatusProcessing, |
| 115 | + 'TargetStatusNotSuccess': TargetStatusNotSuccess, |
114 | 116 | 'UnknownTarget': UnknownTarget, |
115 | 117 | }[result_code] |
116 | 118 |
|
@@ -490,3 +492,73 @@ def get_duplicate_targets(self, target_id: str) -> List[str]: |
490 | 492 | ) |
491 | 493 |
|
492 | 494 | return list(response.json()['similar_targets']) |
| 495 | + |
| 496 | + def update_target( |
| 497 | + self, |
| 498 | + target_id: str, |
| 499 | + name: Optional[str] = None, |
| 500 | + width: Optional[Union[int, float]] = None, |
| 501 | + image: Optional[io.BytesIO] = None, |
| 502 | + active_flag: Optional[bool] = None, |
| 503 | + application_metadata: Optional[bytes] = None, |
| 504 | + ) -> None: |
| 505 | + """ |
| 506 | + Add a target to a Vuforia Web Services database. |
| 507 | +
|
| 508 | + See |
| 509 | + https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target |
| 510 | + for parameter details. |
| 511 | +
|
| 512 | + Args: |
| 513 | + target_id: The ID of the target to get details of. |
| 514 | + name: The name of the target. |
| 515 | + width: The width of the target. |
| 516 | + image: The image of the target. |
| 517 | + active_flag: Whether or not the target is active for query. |
| 518 | + application_metadata: The application metadata of the target. |
| 519 | + This will be base64 encoded. |
| 520 | +
|
| 521 | + Raises: |
| 522 | + ~vws.exceptions.AuthenticationFailure: The secret key is not |
| 523 | + correct. |
| 524 | + ~vws.exceptions.BadImage: There is a problem with the given image. |
| 525 | + For example, it must be a JPEG or PNG file in the grayscale or |
| 526 | + RGB color space. |
| 527 | + ~vws.exceptions.Fail: There was an error with the request. For |
| 528 | + example, the given access key does not match a known database. |
| 529 | + ~vws.exceptions.MetadataTooLarge: The given metadata is too large. |
| 530 | + The maximum size is 1 MB of data when Base64 encoded. |
| 531 | + ~vws.exceptions.ImageTooLarge: The given image is too large. |
| 532 | + ~vws.exceptions.TargetNameExist: A target with the given ``name`` |
| 533 | + already exists. |
| 534 | + ~vws.exceptions.ProjectInactive: The project is inactive. |
| 535 | + """ |
| 536 | + data: Dict[str, Union[str, bool, float, int]] = {} |
| 537 | + |
| 538 | + if name is not None: |
| 539 | + data['name'] = name |
| 540 | + |
| 541 | + if width is not None: |
| 542 | + data['width'] = width |
| 543 | + |
| 544 | + if image is not None: |
| 545 | + image_data = image.getvalue() |
| 546 | + image_data_encoded = base64.b64encode(image_data).decode('ascii') |
| 547 | + data['image'] = image_data_encoded |
| 548 | + |
| 549 | + if active_flag is not None: |
| 550 | + data['active_flag'] = active_flag |
| 551 | + |
| 552 | + if application_metadata is not None: |
| 553 | + metadata_encoded_str = base64.b64encode(application_metadata) |
| 554 | + metadata_encoded = metadata_encoded_str.decode('ascii') |
| 555 | + data['application_metadata'] = metadata_encoded |
| 556 | + |
| 557 | + content = bytes(json.dumps(data), encoding='utf-8') |
| 558 | + |
| 559 | + self._make_request( |
| 560 | + method='PUT', |
| 561 | + content=content, |
| 562 | + request_path=f'/targets/{target_id}', |
| 563 | + expected_result_code='Success', |
| 564 | + ) |
0 commit comments