File tree Expand file tree Collapse file tree 5 files changed +90
-0
lines changed
Expand file tree Collapse file tree 5 files changed +90
-0
lines changed Original file line number Diff line number Diff line change 22
33from .avatars import Avatars
44from .email_validation import EmailValidation
5+ from .iban_validation import IBANValidation
56from .ip_geolocation import IPGeolocation
67from .phone_validation import PhoneValidation
78from .vat import VAT
89
910__all__ : Final [list [str ]] = [
1011 "Avatars" ,
1112 "EmailValidation" ,
13+ "IBANValidation" ,
1214 "IPGeolocation" ,
1315 "PhoneValidation" ,
1416 "VAT"
Original file line number Diff line number Diff line change 1+ from typing import Final
2+
3+ from .iban_validation import IBANValidation
4+ from .iban_validation_response import IBANValidationResponse
5+
6+ __all__ : Final [list [str ]] = [
7+ "IBANValidation" ,
8+ "IBANValidationResponse"
9+ ]
Original file line number Diff line number Diff line change 1+ from abstract_api .bases import BaseService
2+ from abstract_api .exceptions import ResponseParseError
3+
4+ from .iban_validation_response import IBANValidationResponse
5+
6+
7+ class IBANValidation (BaseService ):
8+ """AbstractAPI IBAN validation and verification service.
9+
10+ Used to validate and verify a IBAN number.
11+
12+ Attributes:
13+ _subdomain: IBAN validation service subdomain.
14+ """
15+ _subdomain : str = "ibanvalidation"
16+
17+ def check (self , iban : str ) -> IBANValidationResponse :
18+ """Validates an IBAN.
19+
20+ Args:
21+ iban: The IBAN to validate. Note that the API will accept white
22+ spaces, so BE71 0961 2345 6769 is considered as valid
23+ as BE71096123456769.
24+
25+ Returns:
26+ IBANValidationResponse representing API call response.
27+ """
28+ response = self ._service_request (iban = iban )
29+
30+ # TODO: Move to parent
31+ try :
32+ iban_validation_response = IBANValidationResponse (
33+ response = response
34+ )
35+ except Exception as e :
36+ raise ResponseParseError (
37+ "Failed to parse response as IBANValidationResponse"
38+ ) from e
39+
40+ return iban_validation_response
Original file line number Diff line number Diff line change 1+ from typing import TYPE_CHECKING
2+
3+ import requests
4+
5+ from abstract_api .bases import JSONResponse
6+
7+ from .response_fields import RESPONSE_FIELDS
8+
9+
10+ class IBANValidationResponse (JSONResponse ):
11+ """IBAN validation service response."""
12+
13+ def __init__ (self , response : requests .models .Response ) -> None :
14+ """Initializes a new IBANValidationResponse."""
15+ super ().__init__ (response )
16+ self ._response_fields = RESPONSE_FIELDS
17+ for field in RESPONSE_FIELDS :
18+ if TYPE_CHECKING :
19+ assert isinstance (self .meta .body_json , dict )
20+ value = self .meta .body_json .get (field )
21+ # TODO: Move to parent class
22+ setattr (self , f"_{ field } " , value )
23+
24+ @property
25+ def iban (self ) -> str :
26+ """The IBAN submitted for validation."""
27+ return self ._get_response_field ("iban" )
28+
29+ @property
30+ def is_valid (self ) -> bool :
31+ """Whether the IBAN submitted is valid."""
32+ return self ._get_response_field ("is_valid" )
Original file line number Diff line number Diff line change 1+ """Response fields of IBAN validation service endpoint."""
2+
3+
4+ RESPONSE_FIELDS : frozenset [str ] = frozenset ({
5+ "iban" ,
6+ "is_valid"
7+ })
You can’t perform that action at this time.
0 commit comments