Skip to content

Commit

Permalink
add exception for invalid phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
GLEF1X committed Apr 25, 2021
1 parent 904dd51 commit d3b696e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion glQiwiApi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .utils.exceptions import * # NOQA
from .yoo_money import YooMoneyAPI # NOQA

__version__ = '0.2.14'
__version__ = '0.2.16'

__all__ = (
(
Expand Down
21 changes: 20 additions & 1 deletion glQiwiApi/qiwi/qiwi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ def session(self) -> ClientSession:

@property
def stripped_number(self) -> str:
return self.phone_number.replace("+", "")
try:
return self.phone_number.replace("+", "")
except AttributeError:
raise InvalidData(
"You should pass on phone number to execute this method"
) from None

async def to_card(
self,
Expand Down Expand Up @@ -197,6 +202,11 @@ async def _detect_mobile_number(self, phone_number: str):

async def get_balance(self) -> Sum:
"""Метод для получения баланса киви"""
if not isinstance(self.phone_number, str):
raise InvalidData(
"Для вызова этого метода вы должны передать номер кошелька"
)

headers = self._auth_token(deepcopy(DEFAULT_QIWI_HEADERS))
url = BASE_QIWI_URL + '/funding-sources/v2/persons/'
async for response in self._requests.fast().fetch(
Expand Down Expand Up @@ -338,6 +348,10 @@ async def check_restriction(self) -> Union[
:return: Список, где находиться словарь с ограничениями,
если ограничений нет - возвращает пустой список
"""
if not isinstance(self.phone_number, str):
raise InvalidData(
"Для вызова этого метода вы должны передать номер кошелька"
)
headers = self._auth_token(deepcopy(DEFAULT_QIWI_HEADERS))
url = BASE_QIWI_URL + '/person-profile/v1/persons/'
async for response in self._requests.fast().fetch(
Expand All @@ -356,6 +370,11 @@ async def get_identification(self) -> Identification:
:return: Response object
"""
if not isinstance(self.phone_number, str):
raise InvalidData(
"Для вызова этого метода вы должны передать номер кошелька"
)

headers = self._auth_token(deepcopy(DEFAULT_QIWI_HEADERS))
url = BASE_QIWI_URL + '/identification/v1/persons/'
async for response in self._requests.fast().fetch(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
packages=setuptools.find_packages(),
include_package_data=True,
name="glQiwiApi", # Replace with your own username
version="0.2.16",
version="0.2.17",
author="GLEF1X",
author_email="[email protected]",
description="Light and fast wrapper for qiwi and yoomoney",
Expand Down

0 comments on commit d3b696e

Please sign in to comment.