33from enum import Enum
44from http import HTTPStatus
55
6- import msgspec
76import phonenumbers
87
98from ._product import BaseProduct
10- from ._response import BaseResponse , ErrorResponse
9+ from ._response import BaseResponse , ErrorResponse , decode_response
1110
1211
1312class OTPLanguage (str , Enum ):
@@ -82,11 +81,11 @@ def send(
8281 )
8382
8483 if response .status_code != HTTPStatus .OK :
85- data = msgspec . json . decode (response .content , type = ErrorResponse )
84+ data = decode_response (response .content , type = ErrorResponse )
8685 msg = f"failed to send OTP. { response .status_code } { data .error } "
8786 raise ValueError (msg )
8887
89- data = msgspec . json . decode (response .content , type = OTPSendResponse )
88+ data = decode_response (response .content , type = OTPSendResponse )
9089 if self .debug :
9190 print (f"successfully sent OTP { data .otp_id } to { to } " )
9291
@@ -101,11 +100,11 @@ def resend(self, otp_id: str, /) -> OTPResendResponse:
101100 )
102101
103102 if response .status_code != HTTPStatus .OK :
104- data = msgspec . json . decode (response .content , type = ErrorResponse )
103+ data = decode_response (response .content , type = ErrorResponse )
105104 msg = f"failed to resend OTP. { response .status_code } { data .error } "
106105 raise ValueError (msg )
107106
108- data = msgspec . json . decode (response .content , type = OTPResendResponse )
107+ data = decode_response (response .content , type = OTPResendResponse )
109108 if self .debug :
110109 print (f"successfully resent OTP { otp_id } with status: { data .resent } " )
111110
@@ -121,11 +120,11 @@ def verify(self, otp: int | str, /, *, otp_id: str) -> OTPVerifyResponse:
121120 )
122121
123122 if response .status_code != HTTPStatus .OK :
124- data = msgspec . json . decode (response .content , type = ErrorResponse )
123+ data = decode_response (response .content , type = ErrorResponse )
125124 msg = f"failed to verify OTP. { response .status_code } { data .error } "
126125 raise ValueError (msg )
127126
128- data = msgspec . json . decode (response .content , type = OTPVerifyResponse )
127+ data = decode_response (response .content , type = OTPVerifyResponse )
129128 if self .debug :
130129 print (f"successfully verified OTP ({ otp } ) with status: { data .verified } " )
131130
0 commit comments