-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef3c21f
commit d52e674
Showing
35 changed files
with
1,314 additions
and
1,427 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
httpx = "==0.24.1" | ||
|
||
[dev-packages] | ||
sphinx = "<6.0.0" | ||
mkdocs = "<1.6.0" | ||
mkdocs-material = "<9.3.0" | ||
pytest = "<8.0.0" | ||
pytest-asyncio = "<0.22.0" | ||
pytest-localserver = "<1.0.0" | ||
|
||
[requires] | ||
python_version = "3.7" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,2 @@ | ||
from . import api, exceptions, parsers, sessions | ||
from .exceptions import ( | ||
Error, | ||
OAuthError, | ||
InvalidGrantError, | ||
InvalidUserError, | ||
APIError, | ||
EmptyResponseError, | ||
) | ||
from .sessions import ( | ||
TokenSession, | ||
CodeSession, | ||
ImplicitSession, | ||
) | ||
from .api import API | ||
|
||
__version__ = '0.1.0.post2' | ||
"""aiovkcom.""" | ||
from .api import API # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,87 @@ | ||
"""vk.com API.""" | ||
from typing import Any, Dict, Generator, Tuple | ||
|
||
from .sessions import TokenSession | ||
from .session import TokenSession | ||
|
||
|
||
class API: | ||
"""vk.com REST API.""" | ||
"""vk.com API. | ||
Attributes: | ||
session (TokenSession): session. | ||
""" | ||
|
||
__slots__ = ('session', ) | ||
|
||
def __init__(self, session: TokenSession): | ||
self.session = session | ||
def __init__(self, v: str, access_token: str) -> None: | ||
"""Set session.""" | ||
self.session = TokenSession(v=v, access_token=access_token) | ||
|
||
def __await__(self) -> Generator['API', None, None]: | ||
"""Await self.""" | ||
yield self | ||
|
||
async def __aenter__(self) -> 'API': | ||
"""Enter.""" | ||
return self | ||
|
||
def __getattr__(self, name): | ||
async def __aexit__(self, *args: Tuple[Any, Any, Any]) -> None: | ||
"""Exit.""" | ||
if self.session.client.is_closed is False: | ||
await self.session.client.aclose() | ||
|
||
def __getattr__(self, name) -> 'APIMethod': | ||
"""Return an API method.""" | ||
return APIMethod(self, name) | ||
|
||
async def __call__(self, name, **params): | ||
async def __call__(self, name: str, **params: Dict[str, Any]) -> 'APIMethod': # noqa | ||
"""Call an API method by its name. | ||
Args: | ||
name (str): full method's name | ||
params (Dict[str, Any]): query parameters | ||
Return: | ||
APIMethod | ||
""" | ||
return await getattr(self, name)(**params) | ||
|
||
|
||
class APIMethod: | ||
"""vk.com REST API method.""" | ||
"""vk.com REST API method. | ||
Attributes: | ||
api (API): API instance | ||
name (str): full method's name | ||
""" | ||
|
||
__slots__ = ('api', 'name') | ||
|
||
def __init__(self, api: API, name: str): | ||
def __init__(self, api: API, name: str) -> None: | ||
"""Set method name.""" | ||
self.api = api | ||
self.name = name | ||
|
||
def __getattr__(self, name): | ||
def __getattr__(self, name: str) -> 'APIMethod': | ||
"""Chain methods. | ||
Args: | ||
name (str): method name | ||
""" | ||
return APIMethod(self.api, self.name + '.' + name) | ||
|
||
async def __call__(self, **params): | ||
async def __call__(self, **params: Dict[str, Any]) -> Dict[str, Any]: | ||
"""Execute a request. | ||
Args: | ||
params (Dict[str, Any]): query parameters | ||
Returns: | ||
Dict[str, Any] | ||
""" | ||
return await self.api.session.request(self.name, params) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.