Skip to content

Commit

Permalink
feat(Verification): more robust response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
650elx committed Apr 29, 2024
1 parent 221d711 commit 46cca82
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions sinch/domains/verification/endpoints/start_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,28 @@ 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"),
_links=response.body.get("_links"),
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(
Expand All @@ -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
)
2 changes: 1 addition & 1 deletion sinch/domains/verification/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class VerificationMethod(Enum):
SMS = "sms"
FLASHCALL = "flashcall"
FLASH_CALL = "flashCall"
CALLOUT = "callout"
SEAMLESS = "seamless"

Expand Down
2 changes: 1 addition & 1 deletion sinch/domains/verification/models/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion sinch/domains/verification/models/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StartSMSInitiateVerificationResponse(StartVerificationResponse):

@dataclass
class StartFlashCallInitiateVerificationResponse(StartVerificationResponse):
flashcall: FlashCallResponse
flash_call: FlashCallResponse


@dataclass
Expand Down

0 comments on commit 46cca82

Please sign in to comment.