Skip to content

Commit

Permalink
feat(Verification): Start verification splitted into smaller DTOs
Browse files Browse the repository at this point in the history
  • Loading branch information
650elx committed Jan 22, 2024
1 parent 0ac9c0a commit 97d53f2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
37 changes: 27 additions & 10 deletions sinch/domains/verification/endpoints/start_verification.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
)
25 changes: 20 additions & 5 deletions sinch/domains/verification/models/responses.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
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
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
Expand Down

0 comments on commit 97d53f2

Please sign in to comment.