diff --git a/mati/types/enums.py b/mati/types/enums.py index 0a17c00..879bcd9 100644 --- a/mati/types/enums.py +++ b/mati/types/enums.py @@ -13,6 +13,20 @@ class PageType(SerializableEnum): back = 'back' +@dataclass +class BaseModel: + @classmethod + def _filter_excess_fields(cls, obj_dict: Dict) -> None: + excess = set(obj_dict.keys()) - {f.name for f in fields(cls)} + for f in excess: + del obj_dict[f] + + @classmethod + def _from_dict(cls, obj_dict: Dict[str, Any]) -> 'BaseModel': + cls._filter_excess_fields(obj_dict) + return cls(**obj_dict) + + class ValidationInputType(SerializableEnum): document_photo = 'document-photo' selfie_photo = 'selfie-photo' @@ -28,25 +42,12 @@ class ValidationType(SerializableEnum): @dataclass -class VerificationDocumentStep: +class VerificationDocumentStep(BaseModel): id: str status: int error: Optional[Dict] = None data: Optional[Dict] = field(default_factory=dict) - @classmethod - def _filter_excess_fields(cls, obj_dict: Dict) -> None: - excess = set(obj_dict.keys()) - {f.name for f in fields(cls)} - for f in excess: - del obj_dict[f] - - @classmethod - def _from_dict( - cls, obj_dict: Dict[str, Any] - ) -> 'VerificationDocumentStep': - cls._filter_excess_fields(obj_dict) - return cls(**obj_dict) - @dataclass class Errors: @@ -57,7 +58,7 @@ class Errors: @dataclass -class VerificationDocument: +class VerificationDocument(BaseModel): country: str region: str photos: List[str] @@ -66,17 +67,6 @@ class VerificationDocument: subtype: Optional[str] = None fields: Optional[dict] = None - @classmethod - def _filter_excess_fields(cls, obj_dict: Dict) -> None: - excess = set(obj_dict.keys()) - {f.name for f in fields(cls)} - for f in excess: - del obj_dict[f] - - @classmethod - def _from_dict(cls, obj_dict: Dict[str, Any]) -> 'VerificationDocument': - cls._filter_excess_fields(obj_dict) - return cls(**obj_dict) - @property def errors(self) -> List[Errors]: if not self.steps: @@ -200,23 +190,12 @@ class LivenessMedia: @dataclass -class Liveness: +class Liveness(BaseModel): status: int id: str data: Optional[LivenessMedia] = None error: Optional[Dict] = None - @classmethod - def _filter_excess_fields(cls, obj_dict: Dict) -> None: - excess = set(obj_dict.keys()) - {f.name for f in fields(cls)} - for f in excess: - del obj_dict[f] - - @classmethod - def _from_dict(cls, obj_dict: Dict[str, Any]) -> 'Liveness': - cls._filter_excess_fields(obj_dict) - return cls(**obj_dict) - @dataclass class DocumentScore: diff --git a/mati/version.py b/mati/version.py index dce5733..d30bdd0 100644 --- a/mati/version.py +++ b/mati/version.py @@ -1 +1 @@ -__version__ = '2.0.6.dev4' +__version__ = '2.0.6.dev5'