-
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
f737433
commit 8ec6fb9
Showing
42 changed files
with
1,903 additions
and
3,731 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 = "<=1.0.0" | ||
|
||
[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,33 +1,3 @@ | ||
from . import api, exceptions, objects, parsers, sessions, utils | ||
from .utils import parseaddr | ||
from .exceptions import ( | ||
Error, | ||
OAuthError, | ||
InvalidGrantError, | ||
InvalidClientError, | ||
APIError, | ||
APIScrapperError, | ||
CookieError, | ||
) | ||
from .sessions import ( | ||
PublicSession, | ||
TokenSession, | ||
ClientSession, | ||
ServerSession, | ||
CodeSession, | ||
CodeClientSession, | ||
CodeServerSession, | ||
ImplicitSession, | ||
ImplicitClientSession, | ||
ImplicitServerSession, | ||
PasswordSession, | ||
PasswordClientSession, | ||
PasswordServerSession, | ||
RefreshSession, | ||
RefreshClientSession, | ||
RefreshServerSession, | ||
) | ||
from .api import API | ||
|
||
|
||
__version__ = '0.1.1.post1' | ||
"""aiomailru.""" | ||
from .api import API # noqa: F401 | ||
from .auth import CodeGrant, PasswordGrant, RefreshGrant, full_scope # 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,108 @@ | ||
"""My.Mail.Ru API.""" | ||
from typing import Any, Dict, Generator, Tuple | ||
|
||
from .sessions import TokenSession | ||
from .session import TokenSession | ||
|
||
|
||
class API: | ||
"""Platform@Mail.Ru REST API.""" | ||
"""Platform@Mail.Ru REST API. | ||
Attributes: | ||
session (TokenSesion): session. | ||
""" | ||
|
||
__slots__ = ('session', ) | ||
|
||
def __init__(self, session: TokenSession): | ||
self.session = session | ||
def __init__( | ||
self, | ||
app_id: str, | ||
session_key: str, | ||
private_key: str = '', | ||
secret_key: str = '', | ||
uid: str = '', | ||
) -> None: | ||
"""Set session.""" | ||
if uid and private_key: | ||
secret = private_key | ||
secure = '0' | ||
if secret_key: | ||
secret = secret_key | ||
secure = '1' | ||
uid = '' | ||
self.session = TokenSession( | ||
app_id=app_id, | ||
session_key=session_key, | ||
secret=secret, | ||
secure=secure, | ||
uid=uid, | ||
) | ||
|
||
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 not self.session.client.is_closed: | ||
await self.session.client.aclose() | ||
|
||
def __getattr__(self, name: str) -> '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 | ||
Returns: | ||
APIMethod | ||
""" | ||
return await getattr(self, name)(**params) | ||
|
||
|
||
class APIMethod: | ||
"""Platform@Mail.Ru REST API method.""" | ||
"""Platform@Mail.Ru 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): | ||
return APIMethod(self.api, self.name + '.' + name) | ||
def __getattr__(self, name: str) -> 'APIMethod': | ||
"""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, **params): | ||
""" | ||
params['method'] = self.name | ||
return await self.api.session.request(params=params) |
Oops, something went wrong.