Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document in Readme how to work with URI params #208

Open
joshuabeny1999 opened this issue Dec 9, 2024 · 0 comments
Open

Document in Readme how to work with URI params #208

joshuabeny1999 opened this issue Dec 9, 2024 · 0 comments

Comments

@joshuabeny1999
Copy link

The current Readme lacks the information how to dynamic input URL Template variables provided by the thing description. I needed to reverse engineer the code to find out that the TDHTTPReqeust has additional params for that.

Here an example how i implemented the degregister Roboter part in my code using this params successfully:

    private boolean deregisterOperator(ThingDescription td, String robotUri, String token) {
        try {
            // Find the "removeOperator" action in the Thing Description
            Optional<ActionAffordance> deregisterAction = td.getActionByName("removeOperator");
            if (deregisterAction.isPresent()) {
                Optional<Form> deregisterForm = deregisterAction.get().getFirstFormForOperationType(TD.invokeAction);
                if (deregisterForm.isPresent()) {
                    // Retrieve the required input schema and prepare the payload
                    Map<String, Object> deregisterPayload = new HashMap<>();
                    deregisterPayload.put("token", token); // Replace with the actual token used during registration

                    TDHttpRequest request = new TDHttpRequest(deregisterForm.get(), TD.invokeAction, deregisterAction.get().getUriVariables().get(), deregisterPayload);

                    TDHttpResponse response = request.execute();
                    if (response.getStatusCode() == 200 || response.getStatusCode() == 204) {
                        System.out.println("Operator deregistred successfully with token: " + token);
                        return true;
                    } else {
                        System.out.println("Failed to deregister operator. HTTP status: " + response.getStatusCode());
                        return false;
                    }
                }

            }
        } catch (Exception e) {
            System.out.println("Error while deregistering operator from robot " + robotUri + ": " + e.getMessage());
        }
        return false;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant