Skip to content

Commit 110402c

Browse files
committed
Progress
1 parent 14e64b6 commit 110402c

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

src/vws/vws.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,76 @@ def get_duplicate_targets(self, target_id: str) -> List[str]:
490490
)
491491

492492
return list(response.json()['similar_targets'])
493+
494+
def update_target(
495+
self,
496+
target_id: str,
497+
name: Optional[str] = None,
498+
width: Optional[Union[int, float]] = None,
499+
image: Optional[io.BytesIO] = None,
500+
active_flag: Optional[bool] = None,
501+
application_metadata: Optional[bytes] = None,
502+
) -> str:
503+
"""
504+
Add a target to a Vuforia Web Services database.
505+
506+
See
507+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target
508+
for parameter details.
509+
510+
Args:
511+
name: The name of the target.
512+
width: The width of the target.
513+
image: The image of the target.
514+
active_flag: Whether or not the target is active for query.
515+
application_metadata: The application metadata of the target.
516+
This will be base64 encoded.
517+
518+
Returns:
519+
The target ID of the new target.
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+
if image is None:
537+
image_data_encoded = None
538+
else:
539+
image_data = image.getvalue()
540+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
541+
542+
if application_metadata is None:
543+
metadata_encoded = None
544+
else:
545+
metadata_encoded_str = base64.b64encode(application_metadata)
546+
metadata_encoded = metadata_encoded_str.decode('ascii')
547+
548+
data = {
549+
'name': name,
550+
'width': width,
551+
'image': image_data_encoded,
552+
'active_flag': active_flag,
553+
'application_metadata': metadata_encoded,
554+
}
555+
556+
content = bytes(json.dumps(data), encoding='utf-8')
557+
558+
response = self._make_request(
559+
method='PUT',
560+
content=content,
561+
request_path=f'/targets/{target_id}',
562+
expected_result_code='Success',
563+
)
564+
565+
return str(response.json()['target_id'])

tests/test_vws.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ def test_update_target(
444444
"""
445445
It is possible to update a target.
446446
"""
447+
target_id = client.add_target(
448+
name='x',
449+
width=1,
450+
image=high_quality_image,
451+
)
452+
client.update_target(target_id=target_id)
447453

448454
def test_target_status_not_success(
449455
self,
@@ -453,6 +459,12 @@ def test_target_status_not_success(
453459
"""
454460
It is possible to update a target.
455461
"""
462+
target_id = client.add_target(
463+
name='x',
464+
width=1,
465+
image=high_quality_image,
466+
)
467+
client.update_target(target_id=target_id)
456468

457469
def test_no_fields_given(
458470
self,
@@ -462,3 +474,9 @@ def test_no_fields_given(
462474
"""
463475
It is possible to update a target.
464476
"""
477+
target_id = client.add_target(
478+
name='x',
479+
width=1,
480+
image=high_quality_image,
481+
)
482+
client.update_target(target_id=target_id)

0 commit comments

Comments
 (0)