diff --git a/alice/onboarding/onboarding_client.py b/alice/onboarding/onboarding_client.py index 1c9de6f..1293947 100644 --- a/alice/onboarding/onboarding_client.py +++ b/alice/onboarding/onboarding_client.py @@ -1043,6 +1043,9 @@ def create_report( response = self.session.get( f"{self.url}/user/report", headers=headers, timeout=self.timeout ) + import pdb + + pdb.set_trace() except requests.exceptions.Timeout: return Failure(OnboardingError.timeout(operation="create_report")) diff --git a/alice/onboarding/onboarding_errors.py b/alice/onboarding/onboarding_errors.py index c648fc3..39cf07a 100644 --- a/alice/onboarding/onboarding_errors.py +++ b/alice/onboarding/onboarding_errors.py @@ -29,6 +29,8 @@ def from_response(operation: str, response: Response) -> "OnboardingError": code = response.status_code try: message = response.json() + # old {'error': {'message': 'Method Not Allowed: to unlock it please open a ticket with the support team', 'type': 'EntryPointNotAvailableHttpError'}} + # new {'detail': 'Webhook Result not found'} except Exception: message = {"message": "no content"} return OnboardingError(operation=operation, code=code, message=message) diff --git a/alice/webhooks/webhooks.py b/alice/webhooks/webhooks.py index 76dd19e..4215efd 100644 --- a/alice/webhooks/webhooks.py +++ b/alice/webhooks/webhooks.py @@ -43,11 +43,11 @@ def __init__( self.verbose = verbose @early_return - def get_available_events( + def get_subscriptable_events( self, verbose: Optional[bool] = False ) -> Result[bool, Union[OnboardingError, AuthError]]: """ - Get public available events. + Get public subscriptable events. Parameters ---------- @@ -74,6 +74,12 @@ def get_available_events( ) ) + @early_return + def get_available_events( + self, verbose: Optional[bool] = False + ) -> Result[bool, Union[OnboardingError, AuthError]]: + return self.get_subscriptable_events(verbose) + @early_return def create_webhook( self, webhook: Webhook, verbose: Optional[bool] = False diff --git a/alice/webhooks/webhooks_client.py b/alice/webhooks/webhooks_client.py index c2c117c..a217289 100644 --- a/alice/webhooks/webhooks_client.py +++ b/alice/webhooks/webhooks_client.py @@ -38,12 +38,12 @@ def _auth_headers(self, token: str) -> Dict[str, Any]: @early_return @timeit - def get_available_events( + def get_subscriptable_events( self, verbose: Optional[bool] = False ) -> Result[Response, AuthError]: """ - Get public available events. + Get public subscriptable events. Parameters ---------- @@ -55,17 +55,26 @@ def get_available_events( ------- A Response object [requests library] if success """ - print_intro("get_available_events", verbose=verbose) + print_intro("get_subscriptable_events", verbose=verbose) backend_token = self.auth.create_backend_token().unwrap_or_return() print_token("backend_token_with_user", backend_token, verbose=verbose) headers = self._auth_headers(backend_token) - response = self.session.get(self.url + "/webhook/events", headers=headers) + response = self.session.get( + self.url + "/webhook/subscriptable/events", headers=headers + ) print_response(response=response, verbose=verbose) return Success(response) + @early_return + @timeit + def get_available_events( + self, verbose: Optional[bool] = False + ) -> Result[Response, AuthError]: + return self.get_subscriptable_events(verbose) + @early_return @timeit def create_webhook( diff --git a/examples/onboarding_wait_for_completion_false.py b/examples/onboarding_wait_for_completion_false.py index 93c957c..0d78103 100644 --- a/examples/onboarding_wait_for_completion_false.py +++ b/examples/onboarding_wait_for_completion_false.py @@ -12,7 +12,6 @@ def onboarding_example(api_key: str, verbose: Optional[bool] = False) -> None: config = Config( api_key=api_key, verbose=verbose, - onboarding_url="https://apis.staging.alicebiometrics.com/onboarding", ) onboarding = Onboarding.from_config(config) diff --git a/examples/onboarding_with_webhooks.py b/examples/onboarding_with_webhooks.py index b080e08..d36fb9a 100644 --- a/examples/onboarding_with_webhooks.py +++ b/examples/onboarding_with_webhooks.py @@ -14,8 +14,8 @@ def configure_webhooks(api_key: str, verbose: Optional[bool] = False) -> None: webhooks_client = Webhooks.from_config(config) # Check Available events - available_events = webhooks_client.get_available_events().unwrap() - selected_event = available_events[0] + subscriptable_events = webhooks_client.get_subscriptable_events().unwrap_or_raise() + selected_event = subscriptable_events[0] # Create a new Webhook webhook = Webhook( @@ -26,7 +26,7 @@ def configure_webhooks(api_key: str, verbose: Optional[bool] = False) -> None: event_version=selected_event.get("version"), secret=str(secrets.token_hex(20)), ) - webhook_id = webhooks_client.create_webhook(webhook).unwrap() + webhook_id = webhooks_client.create_webhook(webhook).unwrap_or_raise() # Update an existent Webhook webhook_to_update = Webhook( @@ -34,24 +34,25 @@ def configure_webhooks(api_key: str, verbose: Optional[bool] = False) -> None: active=False, post_url="http://alicebiometrics.com", api_key="b0b905d6-228f-44bf-a130-c85d7aecd765", - event_name="user_created", + event_name="user.created", event_version="1", algorithm="sha512", secret=str(secrets.token_hex(20)), ) - webhooks_client.update_webhook(webhook_to_update) + webhooks_client.update_webhook(webhook_to_update).unwrap_or_raise() # Update the activation of a Webhook webhooks_client.update_webhook_activation(webhook_id, True) - retrieved_webhook = webhooks_client.get_webhook(webhook_id).unwrap() + retrieved_webhook = webhooks_client.get_webhook(webhook_id).unwrap_or_raise() assert retrieved_webhook.active # Send a ping using configured webhook result = webhooks_client.ping_webhook(webhook_id) # Retrieve an existent Webhook - retrieved_webhook = webhooks_client.get_webhook(webhook_id).unwrap() + retrieved_webhook = webhooks_client.get_webhook(webhook_id).unwrap_or_raise() assert retrieved_webhook.active + breakpoint() assert retrieved_webhook.post_url == "http://alicebiometrics.com" # Retrieve all configured webhooks @@ -62,10 +63,12 @@ def configure_webhooks(api_key: str, verbose: Optional[bool] = False) -> None: assert_success(result) # Retrieve all webhook results of a specific webhook - webhook_results = webhooks_client.get_webhook_results(webhook_id).unwrap() + webhook_results = webhooks_client.get_webhook_results(webhook_id).unwrap_or_raise() # Retrieve las webhook result of a specific webhook - last_webhook_result = webhooks_client.get_last_webhook_result(webhook_id).unwrap() + last_webhook_result = webhooks_client.get_last_webhook_result( + webhook_id + ).unwrap_or_raise() if __name__ == "__main__":