-
Notifications
You must be signed in to change notification settings - Fork 2
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
5892124
commit b09900a
Showing
36 changed files
with
1,797 additions
and
2,359 deletions.
There are no files selected for viewing
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,19 @@ | ||
# Read the Docs configuration file for MkDocs projects | ||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details | ||
|
||
# Required | ||
version: 2 | ||
|
||
# Set the version of Python and other tools you might need | ||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.7" | ||
|
||
sphinx: | ||
configuration: docs/source/conf.py | ||
|
||
python: | ||
install: | ||
- requirements: docs/requirements.txt | ||
|
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 = "*" | ||
|
||
[dev-packages] | ||
sphinx = "*" | ||
mkdocs = "*" | ||
mkdocs-material = "*" | ||
pytest = "*" | ||
pytest-asyncio = "*" | ||
pytest-localserver = "*" | ||
|
||
[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,28 +1,3 @@ | ||
from . import exceptions, utils, parsers, sessions, api | ||
from .exceptions import ( | ||
Error, | ||
OAuthError, | ||
InvalidGrantError, | ||
InvalidClientError, | ||
InvalidUserError, | ||
APIError, | ||
EmptyResponseError, | ||
) | ||
from .sessions import ( | ||
PublicSession, | ||
TokenSession, | ||
ClientSession, | ||
ServerSession, | ||
CodeSession, | ||
CodeServerSession, | ||
ImplicitSession, | ||
ImplicitClientSession, | ||
PasswordSession, | ||
PasswordClientSession, | ||
RefreshSession, | ||
RefreshServerSession, | ||
) | ||
from .api import API | ||
|
||
|
||
__version__ = '0.1.1.post1' | ||
"""aiookru.""" | ||
from .api import API # noqa: F401 | ||
from .auth import CodeGrant, RefreshGrant # 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,35 +1,100 @@ | ||
"""ok.ru API.""" | ||
from hashlib import md5 | ||
from typing import Any, Dict, Generator, Tuple | ||
|
||
from .sessions import TokenSession | ||
from .session import TokenSession | ||
|
||
|
||
class API: | ||
"""ok.ru API.""" | ||
"""ok.ru API. | ||
Attributes: | ||
session (TokenSession): session. | ||
""" | ||
|
||
__slots__ = ('session', ) | ||
|
||
def __init__(self, session: TokenSession): | ||
self.session = session | ||
def __init__( | ||
self, | ||
access_token: str, | ||
application_key: str, | ||
session_secret_key: str = '', | ||
application_secret_key: str = '', | ||
): | ||
"""Set session.""" | ||
if session_secret_key: | ||
secret_key = session_secret_key | ||
elif application_secret_key: | ||
plain_secret = access_token + application_secret_key | ||
secret_key = md5(plain_secret.encode('utf-8')).hexdigest().lower() | ||
else: | ||
secret_key = '' | ||
self.session = TokenSession( | ||
application_key=application_key, | ||
access_token=access_token, | ||
secret_key=secret_key, | ||
) | ||
|
||
def __getattr__(self, name): | ||
def __await__(self) -> Generator['API', None, None]: | ||
"""Await self.""" | ||
yield self | ||
|
||
async def __aenter__(self) -> 'API': | ||
"""Enter.""" | ||
return self | ||
|
||
async def __aexit__(self, *args: Tuple[Any, Any, Any]) -> None: | ||
"""Exit.""" | ||
if not self.session.client.is_closed: | ||
await self.session.client.aclose() | ||
|
||
def __getattr__(self, name: str): | ||
"""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: | ||
"""ok.ru REST API method.""" | ||
|
||
__slots__ = ('api', 'name') | ||
__slots__ = ('_api', '_name') | ||
|
||
def __init__(self, api: API, name: str): | ||
self.api = api | ||
self.name = name | ||
"""Set method name.""" | ||
self._api = api | ||
self._name = name | ||
|
||
def __getattr__(self, name): | ||
return APIMethod(self.api, self.name + '.' + name) | ||
"""Chain methods. | ||
Args: | ||
name (str): method name | ||
""" | ||
return APIMethod(self._api, f'{self._name}.{name}') | ||
|
||
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] | ||
async def __call__(self, *args, **params): | ||
params['method'] = self.name | ||
return await self.api.session.request(params=params) | ||
""" | ||
params['method'] = self._name | ||
return await self._api.session.request(params=params) |
Oops, something went wrong.