<commit_before>AIOHTTP OAuth Client
####################

.. _description:

AIOHTTP OAuth Client -- OAuth support for Aiohttp/Asyncio.

.. _badges:

.. image:: http://img.shields.io/travis/klen/aioauth-client.svg?style=flat-square
    :target: http://travis-ci.org/klen/aioauth-client
    :alt: Build Status

.. image:: http://img.shields.io/pypi/v/aioauth-client.svg?style=flat-square
    :target: https://pypi.python.org/pypi/aioauth-client

.. image:: http://img.shields.io/pypi/dm/aioauth-client.svg?style=flat-square
    :target: https://pypi.python.org/pypi/aioauth-client

.. _contents:

.. contents::

.. _requirements:

Requirements
=============

- python >= 3.3

.. _installation:

Installation
=============

**AIOHTTP OAuth Client** should be installed using pip: ::

    pip install aioauth-client

.. _usage:

Usage
=====


.. code:: python

    # OAuth1
    from aioauth_client import TwitterClient

    twitter = TwitterClient(
        consumer_key='<KEY>',
        consumer_secret='<KEY>',
    )

    request_token, request_token_secret = yield from twitter.get_request_token()

    authorize_url = twitter.get_authorize_url(request_token)
    print("Open",authorize_url,"in a browser")
    # ...
    # Reload client to authorize_url and get oauth_verifier
    # ...
    print("PIN code:")
    oauth_verifier = input()
    oauth_token, oauth_token_secret = yield from twitter.get_access_token(oauth_verifier)

    # Save the tokens for later use

    # ...

    twitter = TwitterClient(
        consumer_key='J8MoJG4bQ9gcmGh8H7XhMg',
        consumer_secret='<KEY>',
        oauth_token=oauth_token,
        oauth_token_secret=oauth_token_secret,
    )

    timeline = yield from twitter.request('GET', 'statuses/home_timeline.json')
    content = yield from timeline.read()
    print(content)

.. code:: python

    # OAuth2
    from aioauth_client import GithubClient

    github = GithubClient(
        client_id='b6281b6fe88fa4c313e6',
        client_secret='21ff23d9f1cad775daee6a38d230e1ee05b04f7c',
    )

    authorize_url = github.get_authorize_url(scope="user:email")

    # ...
    # Reload client to authorize_url and get code
    # ...

    otoken = yield from github.get_access_token(code)

    # Save the token for later use

    # ...

    github = GithubClient(
        client_id='b6281b6fe88fa4c313e6',
        client_secret='21ff23d9f1cad775daee6a38d230e1ee05b04f7c',
        access_token=otoken,
    )

    response = github.request('GET', 'user')
    user_info = yield from response.json()
<commit_msg>Fix documentation for github auth<commit_after>AIOHTTP OAuth Client
####################

.. _description:

AIOHTTP OAuth Client -- OAuth support for Aiohttp/Asyncio.

.. _badges:

.. image:: http://img.shields.io/travis/klen/aioauth-client.svg?style=flat-square
    :target: http://travis-ci.org/klen/aioauth-client
    :alt: Build Status

.. image:: http://img.shields.io/pypi/v/aioauth-client.svg?style=flat-square
    :target: https://pypi.python.org/pypi/aioauth-client

.. image:: http://img.shields.io/pypi/dm/aioauth-client.svg?style=flat-square
    :target: https://pypi.python.org/pypi/aioauth-client

.. _contents:

.. contents::

.. _requirements:

Requirements
=============

- python >= 3.3

.. _installation:

Installation
=============

**AIOHTTP OAuth Client** should be installed using pip: ::

    pip install aioauth-client

.. _usage:

Usage
=====


.. code:: python

    # OAuth1
    from aioauth_client import TwitterClient

    twitter = TwitterClient(
        consumer_key='J8MoJG4bQ9gcmGh8H7XhMg',
        consumer_secret='<KEY>',
    )

    request_token, request_token_secret = yield from twitter.get_request_token()

    authorize_url = twitter.get_authorize_url(request_token)
    print("Open",authorize_url,"in a browser")
    # ...
    # Reload client to authorize_url and get oauth_verifier
    # ...
    print("PIN code:")
    oauth_verifier = input()
    oauth_token, oauth_token_secret = yield from twitter.get_access_token(oauth_verifier)

    # Save the tokens for later use

    # ...

    twitter = TwitterClient(
        consumer_key='J8MoJG4bQ9gcmGh8H7XhMg',
        consumer_secret='<KEY>',
        oauth_token=oauth_token,
        oauth_token_secret=oauth_token_secret,
    )

    timeline = yield from twitter.request('GET', 'statuses/home_timeline.json')
    content = yield from timeline.read()
    print(content)

.. code:: python

    # OAuth2
    from aioauth_client import GithubClient

    github = GithubClient(
        client_id='b6281b6fe88fa4c313e6',
        client_secret='21ff23d9f1cad775daee6a38d230e1ee05b04f7c',
    )

    authorize_url = github.get_authorize_url(scope="user:email")

    # ...
    # Reload client to authorize_url and get code
    # ...

    otoken, _ = yield from github.get_access_token(code)

    # Save the token for later use

    # ...

    github = GithubClient(
        client_id='b6281b6fe88fa4c313e6',
        client_secret='21ff23d9f1cad775daee6a38d230e1ee05b04f7c',
        access_token=otoken,
    )

    response = yield from github.request('GET', 'user')
    user_info = yield from response.json()

{'fraction_non_alphanumeric': 0.1326709526592636, 'fraction_numerical': 0.030196766023767776, 'mean_word_length': 3.2429752066115705, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2160774', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1763, 'n_words': 304}