diff --git a/sinch/domains/verification/endpoints/start_verification.py b/sinch/domains/verification/endpoints/start_verification.py index 2770367..db52c8c 100644 --- a/sinch/domains/verification/endpoints/start_verification.py +++ b/sinch/domains/verification/endpoints/start_verification.py @@ -1,8 +1,15 @@ from sinch.core.models.http_response import HTTPResponse from sinch.domains.verification.endpoints.verification_endpoint import VerificationEndpoint from sinch.core.enums import HTTPAuthentication, HTTPMethods +from sinch.domains.verification.enums import VerificationMethod from sinch.domains.verification.models.requests import StartVerificationRequest -from sinch.domains.verification.models.responses import StartVerificationResponse +from sinch.domains.verification.models.responses import ( + StartVerificationResponse, + StartSMSInitiateVerificationResponse, + StartDataInitiateVerificationResponse, + StartCalloutInitiateVerificationResponse, + StartFlashCallInitiateVerificationResponse +) class StartVerificationEndpoint(VerificationEndpoint): @@ -22,12 +29,22 @@ def request_body(self): return self.request_data.as_json() def handle_response(self, response: HTTPResponse) -> StartVerificationResponse: - return StartVerificationResponse( - id=response.body.get("id"), - method=response.body.get("method"), - _links=response.body.get("_links"), - sms=response.body.get("sms"), - flash_call=response.body.get("flashCall"), - callout=response.body.get("callout"), - seamless=response.body.get("seamless"), - ) + if self.request_data.method == VerificationMethod.SMS.value: + return StartSMSInitiateVerificationResponse( + **response.body + ) + elif self.request_data.method == VerificationMethod.FLASHCALL.value: + return StartFlashCallInitiateVerificationResponse( + id=response.body.get("id"), + method=response.body.get("method"), + _links=response.body.get("_links"), + flash_call=response.body.get("flashCall") + ) + elif self.request_data.method == VerificationMethod.CALLOUT.value: + return StartCalloutInitiateVerificationResponse( + **response.body + ) + elif self.request_data.method == VerificationMethod.SEAMLESS.value: + return StartDataInitiateVerificationResponse( + **response.body + ) diff --git a/sinch/domains/verification/models/responses.py b/sinch/domains/verification/models/responses.py index 0972ac4..de33390 100644 --- a/sinch/domains/verification/models/responses.py +++ b/sinch/domains/verification/models/responses.py @@ -1,7 +1,6 @@ from dataclasses import dataclass from sinch.core.models.base_model import SinchBaseModel from sinch.domains.verification.enums import VerificationMethod, VerificationStatus -from typing import Optional @dataclass @@ -9,10 +8,26 @@ class StartVerificationResponse(SinchBaseModel): id: str method: VerificationMethod _links: list - sms: Optional[dict] = None - flash_call: Optional[dict] = None - callout: Optional[dict] = None - seamless: Optional[dict] = None + + +@dataclass +class StartSMSInitiateVerificationResponse(StartVerificationResponse): + sms: dict + + +@dataclass +class StartFlashCallInitiateVerificationResponse(StartVerificationResponse): + flash_call: dict + + +@dataclass +class StartCalloutInitiateVerificationResponse(StartVerificationResponse): + callout: dict + + +@dataclass +class StartDataInitiateVerificationResponse(StartVerificationResponse): + seamless: dict @dataclass