Example #1
0
    def update_target(
        self,
        target_id: str,
        name: str | None = None,
        width: int | float | None = None,
        image: io.BytesIO | None = None,
        active_flag: bool | None = None,
        application_metadata: str | None = None,
    ) -> None:
        """
        Add a target to a Vuforia Web Services database.

        See
        https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target
        for parameter details.

        Args:
            target_id: The ID of the target to get details of.
            name: The name of the target.
            width: The width of the target.
            image: The image of the target.
            active_flag: Whether or not the target is active for query.
            application_metadata: The application metadata of the target.
                This must be base64 encoded, for example by using::

                    base64.b64encode('input_string').decode('ascii')

                Giving ``None`` will not change the application metadata.

        Raises:
            ~vws.exceptions.vws_exceptions.AuthenticationFailure: The secret
                key is not correct.
            ~vws.exceptions.vws_exceptions.BadImage: There is a problem with
                the given image.  For example, it must be a JPEG or PNG file in
                the grayscale or RGB color space.
            ~vws.exceptions.vws_exceptions.Fail: There was an error with the
                request. For example, the given access key does not match a
                known database.
            ~vws.exceptions.vws_exceptions.MetadataTooLarge: The given metadata
                is too large.  The maximum size is 1 MB of data when Base64
                encoded.
            ~vws.exceptions.vws_exceptions.ImageTooLarge: The given image is
                too large.
            ~vws.exceptions.vws_exceptions.TargetNameExist: A target with the
                given ``name`` already exists.
            ~vws.exceptions.vws_exceptions.ProjectInactive: The project is
                inactive.
            ~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
                error with the time sent to Vuforia.
        """
        data: Dict[str, str | bool | float | int] = {}

        if name is not None:
            data['name'] = name

        if width is not None:
            data['width'] = width

        if image is not None:
            image_data = image.getvalue()
            image_data_encoded = base64.b64encode(image_data).decode('ascii')
            data['image'] = image_data_encoded

        if active_flag is not None:
            data['active_flag'] = active_flag

        if application_metadata is not None:
            data['application_metadata'] = application_metadata

        content = bytes(json.dumps(data), encoding='utf-8')

        self._make_request(
            method='PUT',
            content=content,
            request_path=f'/targets/{target_id}',
            expected_result_code='Success',
        )