Skip to content

Commit 330c52c

Browse files
committed
Add API call by magic
1 parent 84986a2 commit 330c52c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

vk_api/vk_api.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def vk_login(self, captcha_sid=None, captcha_key=None):
174174
captcha = Captcha(self, captcha_sid, self.vk_login)
175175

176176
if self.error_handlers[CAPTCHA_ERROR_CODE]:
177-
self.error_handlers[CAPTCHA_ERROR_CODE](captcha)
177+
return self.error_handlers[CAPTCHA_ERROR_CODE](captcha)
178178
else:
179179
raise AuthorizationError('Authorization error (capcha)')
180180
elif 'm=1' in response.url:
@@ -352,6 +352,9 @@ def too_many_rps_handler(self, error):
352352
def auth_handler(self):
353353
raise AuthorizationError("No handler for two-factor authorization.")
354354

355+
def get_api(self):
356+
return VkApiMethod(self)
357+
355358
def method(self, method, values=None, captcha_sid=None, captcha_key=None):
356359
""" Использование методов API
357360
@@ -424,6 +427,25 @@ def method(self, method, values=None, captcha_sid=None, captcha_key=None):
424427
return response['response']
425428

426429

430+
class VkApiMethod:
431+
def __init__(self, vk, method=None):
432+
self._vk = vk
433+
self._method = method
434+
435+
def __getattr__(self, method):
436+
if self._method:
437+
self._method += '.' + method
438+
return self
439+
440+
return VkApiMethod(self._vk, method)
441+
442+
def __call__(self, *args, **kwargs):
443+
return self._vk.method(self._method, kwargs)
444+
445+
def get_doc(self):
446+
doc(self._method)
447+
448+
427449
def doc(method=None):
428450
""" Открывает документацию на метод или список всех методов
429451

0 commit comments

Comments
 (0)