From 46cca82529f9148320fdb9938dd02211c2790aed Mon Sep 17 00:00:00 2001 From: 650elx Date: Mon, 29 Apr 2024 16:48:36 +0200 Subject: [PATCH] feat(Verification): more robust response handling --- .../verification/endpoints/start_verification.py | 13 ++++++++----- sinch/domains/verification/enums.py | 2 +- sinch/domains/verification/models/requests.py | 2 +- sinch/domains/verification/models/responses.py | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sinch/domains/verification/endpoints/start_verification.py b/sinch/domains/verification/endpoints/start_verification.py index 9d8568a2..3eb9956e 100644 --- a/sinch/domains/verification/endpoints/start_verification.py +++ b/sinch/domains/verification/endpoints/start_verification.py @@ -34,6 +34,7 @@ def request_body(self): def handle_response(self, response: HTTPResponse) -> StartVerificationResponse: super().handle_response(response) if self.request_data.method == VerificationMethod.SMS.value: + sms_response = response.body.get("sms") return StartSMSInitiateVerificationResponse( id=response.body.get("id"), method=response.body.get("method"), @@ -41,19 +42,20 @@ def handle_response(self, response: HTTPResponse) -> StartVerificationResponse: sms=SMSResponse( interception_timeout=response.body["sms"].get("interceptionTimeout"), template=response.body["sms"].get("template") - ) + ) if sms_response else None ) - elif self.request_data.method == VerificationMethod.FLASHCALL.value: + elif self.request_data.method == VerificationMethod.FLASH_CALL.value: + flash_call_response = response.body.get("flashCall") return StartFlashCallInitiateVerificationResponse( id=response.body.get("id"), method=response.body.get("method"), _links=response.body.get("_links"), - flashcall=FlashCallResponse( + flash_call=FlashCallResponse( cli_filter=response.body["flashCall"].get("cliFilter"), interception_timeout=response.body["flashCall"].get("interceptionTimeout"), report_timeout=response.body["flashCall"].get("reportTimeout"), deny_call_after=response.body["flashCall"].get("denyCallAfter") - ) + ) if flash_call_response else None ) elif self.request_data.method == VerificationMethod.CALLOUT.value: return StartCalloutInitiateVerificationResponse( @@ -62,11 +64,12 @@ def handle_response(self, response: HTTPResponse) -> StartVerificationResponse: _links=response.body.get("_links") ) elif self.request_data.method == VerificationMethod.SEAMLESS.value: + seamless_response = response.body.get("seamless") return StartDataInitiateVerificationResponse( id=response.body.get("id"), method=response.body.get("method"), _links=response.body.get("_links"), seamless=DataResponse( target_uri=response.body["seamless"].get("targetUri") - ) + ) if seamless_response else None ) diff --git a/sinch/domains/verification/enums.py b/sinch/domains/verification/enums.py index 82f6c80d..26e0212c 100644 --- a/sinch/domains/verification/enums.py +++ b/sinch/domains/verification/enums.py @@ -3,7 +3,7 @@ class VerificationMethod(Enum): SMS = "sms" - FLASHCALL = "flashcall" + FLASH_CALL = "flashCall" CALLOUT = "callout" SEAMLESS = "seamless" diff --git a/sinch/domains/verification/models/requests.py b/sinch/domains/verification/models/requests.py index eabe8cb4..1cd784a8 100644 --- a/sinch/domains/verification/models/requests.py +++ b/sinch/domains/verification/models/requests.py @@ -40,7 +40,7 @@ def as_dict(self): @dataclass class StartFlashCallVerificationRequest(StartVerificationRequest): dial_timeout: int - method: str = VerificationMethod.FLASHCALL.value + method: str = VerificationMethod.FLASH_CALL.value def as_dict(self): payload = super().as_dict() diff --git a/sinch/domains/verification/models/responses.py b/sinch/domains/verification/models/responses.py index a21b1350..b0c5ad27 100644 --- a/sinch/domains/verification/models/responses.py +++ b/sinch/domains/verification/models/responses.py @@ -36,7 +36,7 @@ class StartSMSInitiateVerificationResponse(StartVerificationResponse): @dataclass class StartFlashCallInitiateVerificationResponse(StartVerificationResponse): - flashcall: FlashCallResponse + flash_call: FlashCallResponse @dataclass