Skip to content

module/oauth.py

module.oauth

OAuth

OAuth

OAuth

Parameters:

Name Type Description Default
mail str

Mail address

required
Source code in module/oauth.py
class OAuth:
    ''' OAuth

    Args:
        mail (str): Mail address

    '''

    def __init__(self, mail: str) -> None:
        self.mail = mail

    def get(self) -> Optional[dict[str, Any]]:
        ''' Get data

        Returns:
            Return the data by the mail.

        '''
        return OAuthDB().find_one({'_id': self.mail})

    @staticmethod
    def add(mail: str, data: Optional[dict[str, Any]] = None,
            token: Optional[Credentials] = None) -> None:
        ''' add data, token

        Args:
            mail (str): Mail address.
            data (dict): The data from the oauth response.
            token (dict): OAuth token.

        '''

        if any((data, token)):
            oauth_db = OAuthDB()

            if data is not None:
                oauth_db.add_data(mail=mail, data=data)

            if token is not None:
                oauth_db.add_token(mail=mail, credentials=token)

    @staticmethod
    def owner(mail: str) -> Optional[str]:
        ''' return the owner

        Args:
            mail (str): Mail address.

        Raises:
            Exception: No oauth data of `{mail}`.

        '''
        data = OAuthDB().find_one({'_id': mail}, {'owner': 1})
        if not data:
            raise Exception(f'No oauth data of `{mail}`')

        return data.get('owner')

add staticmethod

add(
    mail: str,
    data: Optional[dict[str, Any]] = None,
    token: Optional[Credentials] = None,
) -> None

add data, token

Parameters:

Name Type Description Default
mail str

Mail address.

required
data dict

The data from the oauth response.

None
token dict

OAuth token.

None
Source code in module/oauth.py
@staticmethod
def add(mail: str, data: Optional[dict[str, Any]] = None,
        token: Optional[Credentials] = None) -> None:
    ''' add data, token

    Args:
        mail (str): Mail address.
        data (dict): The data from the oauth response.
        token (dict): OAuth token.

    '''

    if any((data, token)):
        oauth_db = OAuthDB()

        if data is not None:
            oauth_db.add_data(mail=mail, data=data)

        if token is not None:
            oauth_db.add_token(mail=mail, credentials=token)

get

get() -> Optional[dict[str, Any]]

Get data

Returns:

Type Description
Optional[dict[str, Any]]

Return the data by the mail.

Source code in module/oauth.py
def get(self) -> Optional[dict[str, Any]]:
    ''' Get data

    Returns:
        Return the data by the mail.

    '''
    return OAuthDB().find_one({'_id': self.mail})

owner staticmethod

owner(mail: str) -> Optional[str]

return the owner

Parameters:

Name Type Description Default
mail str

Mail address.

required

Raises:

Type Description
Exception

No oauth data of {mail}.

Source code in module/oauth.py
@staticmethod
def owner(mail: str) -> Optional[str]:
    ''' return the owner

    Args:
        mail (str): Mail address.

    Raises:
        Exception: No oauth data of `{mail}`.

    '''
    data = OAuthDB().find_one({'_id': mail}, {'owner': 1})
    if not data:
        raise Exception(f'No oauth data of `{mail}`')

    return data.get('owner')