Skip to content

Commit

Permalink
bump verseion to 1.0.0rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantintogoi committed Dec 1, 2024
1 parent f737433 commit 8ec6fb9
Show file tree
Hide file tree
Showing 42 changed files with 1,903 additions and 3,731 deletions.
19 changes: 19 additions & 0 deletions .readthedocs.yaml
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

25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions Pipfile
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"
827 changes: 827 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

41 changes: 5 additions & 36 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
.. image:: https://img.shields.io/badge/license-BSD-blue.svg
:target: https://github.com/KonstantinTogoi/aiomailru/blob/master/LICENSE
:target: https://github.com/konstantintogoi/aiomailru/blob/master/LICENSE

.. image:: https://img.shields.io/pypi/v/aiomailru.svg
:target: https://pypi.python.org/pypi/aiomailru

.. image:: https://img.shields.io/pypi/pyversions/aiomailru.svg
:target: https://pypi.python.org/pypi/aiomailru

.. image:: https://readthedocs.org/projects/aiomailru/badge/?version=latest
:target: https://aiomailru.readthedocs.io/en/latest/

.. image:: https://travis-ci.org/KonstantinTogoi/aiomailru.svg
:target: https://travis-ci.org/KonstantinTogoi/aiomailru

.. index-start-marker1
aiomailru
Expand All @@ -21,17 +15,13 @@ aiomailru
aiomailru is a python `Mail.Ru API <https://api.mail.ru/>`_ wrapper.
The main features are:

* authorization (`Authorization Code <https://oauth.net/2/grant-types/authorization-code/>`_, `Implicit Flow <https://oauth.net/2/grant-types/implicit/>`_, `Password Grant <https://oauth.net/2/grant-types/password/>`_, `Refresh Token <https://oauth.net/2/grant-types/refresh-token/>`_)
* `REST API <https://api.mail.ru/docs/reference/rest/>`_ methods
* web scrapers

Usage
-----

To use `Mail.Ru API <https://api.mail.ru/>`_ you need a registered app and
`Mail.Ru <https://mail.ru>`_ account.
For more details, see
`aiomailru Documentation <https://aiomailru.readthedocs.io/>`_.
`aiomailru Documentation <https://konstantintogoi.github.io/aiomailru>`_.

Client application
~~~~~~~~~~~~~~~~~~
Expand All @@ -55,7 +45,7 @@ i.e. when you embed your app's info (private key) in publicly available code.
Use :code:`access_token` and :code:`uid`
that were received after authorization. For more details, see
`authorization instruction <https://aiomailru.readthedocs.io/en/latest/authorization.html>`_.
`authorization instruction <https://konstantintogoi.github.io/aiomailru/authorization>`_.

Server application
~~~~~~~~~~~~~~~~~~
Expand All @@ -77,7 +67,7 @@ Use :code:`ServerSession` when REST API is needed in:
Use :code:`access_token` that was received after authorization.
For more details, see
`authorization instruction <https://aiomailru.readthedocs.io/en/latest/authorization.html>`_.
`authorization instruction <https://konstantintogoi.github.io/aiomailru/authorization>`_.

Installation
------------
Expand All @@ -86,34 +76,13 @@ Installation
$ pip install aiomailru
or

.. code-block:: shell
$ python setup.py install
Supported Python Versions
-------------------------

Python 3.5, 3.6, 3.7 and 3.8 are supported.
Python 3.7, 3.8, 3.9 are supported.

.. index-end-marker1
Test
----

Run all tests.

.. code-block:: shell
$ python setup.py test
Run tests with PyTest.

.. code-block:: shell
$ python -m pytest [-k TEST_NAME]
License
-------

Expand Down
36 changes: 3 additions & 33 deletions aiomailru/__init__.py
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
95 changes: 84 additions & 11 deletions aiomailru/api.py
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)
Loading

0 comments on commit 8ec6fb9

Please sign in to comment.