<commit_before># Copyright (C) 2014 cybojenix <<EMAIL>>
#
# This file is part of XdaPy.
#
# XdaPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# XdaPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XdaPy.  If not, see <http://www.gnu.org/licenses/>.

from ..base import XdaBase
from ..decorators import login_required


class User(XdaBase):

    @login_required
    def user(self):
        """Return a dict containing info about the logged in user.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/retrieve_get
        """
        method = "GET"
        url = "/v1/user"
        return self.xda.requests.basic_request(method, url)

    @login_required
    def logout(self):
        """Log the user out.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/logout_get
        """
        method = "GET"
        url = "/v1/user/logout"
        self.xda.session.remove_session()
        return self.xda.requests.basic_request(method, url)

    @login_required
    def mentions(self, page=1):
        """Return a dict containing the user's mention feed.

        Args:
            page (int, optional): number of pages to return. Defaults to 1.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/mentions_get
        """
        method = "GET"
        url = "/v1/user/mentions"
        d = {"page": page}
        return self.xda.requests.basic_request(method, url, body=d)

    @login_required
    def quotes(self, page=1):
        """Return a dict containing the user's quote feed.

        Args:
            page (int, optional): number of pages to return. Defaults to 1.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/quotes_get
        """
        method = "GET"
        url = "/v1/user/quotes"
        d = {"page": page}
        return self.xda.requests.basic_request(method, url, body=d)

    def user_info(self, user_id=None):
        """Return a dict containing public info for a user.

        Args:
            user_id (int, optional): The ID of the user to get the info for.
                Defaults to the logged in user's ID.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/retrieveUserInfo_get
        """
        if user_id is None:
            return self.user()
        method = "GET"
        url = "/v1/user/userinfo"
        d = {"userid": user_id}
        return self.xda.requests.basic_request(method, url, body=d)

    @login_required
    def add_my_device(self, device_id):
        """Add a device to "My Devices" for the logged in user.

        Args:
            device_id (int): The ID of the device to add. This is the device's
                top forum ID.

        See Also:
            `forums.find_by_device()`
            https://api.xda-developers.com/explorer/#!/user/retrieveUserInfo_get
        """
        method = "POST"
        url = "/v1/user/addmydevice"
        d = {"deviceid": device_id}
        return self.xda.requests.basic_request(method, url, body=d)

    def login(self, username, password):
        """Log in.

        Args:
            username (str): username.
            password (str): password.<commit_msg>add google+ login/register access points<commit_after># Copyright (C) 2014 cybojenix <<EMAIL>>
#
# This file is part of XdaPy.
#
# XdaPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# XdaPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XdaPy.  If not, see <http://www.gnu.org/licenses/>.

from ..base import XdaBase
from ..decorators import login_required


class User(XdaBase):

    @login_required
    def user(self):
        """Return a dict containing info about the logged in user.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/retrieve_get
        """
        method = "GET"
        url = "/v1/user"
        return self.xda.requests.basic_request(method, url)

    @login_required
    def logout(self):
        """Log the user out.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/logout_get
        """
        method = "GET"
        url = "/v1/user/logout"
        self.xda.session.remove_session()
        return self.xda.requests.basic_request(method, url)

    @login_required
    def mentions(self, page=1):
        """Return a dict containing the user's mention feed.

        Args:
            page (int, optional): number of pages to return. Defaults to 1.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/mentions_get
        """
        method = "GET"
        url = "/v1/user/mentions"
        d = {"page": page}
        return self.xda.requests.basic_request(method, url, body=d)

    @login_required
    def quotes(self, page=1):
        """Return a dict containing the user's quote feed.

        Args:
            page (int, optional): number of pages to return. Defaults to 1.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/quotes_get
        """
        method = "GET"
        url = "/v1/user/quotes"
        d = {"page": page}
        return self.xda.requests.basic_request(method, url, body=d)

    def user_info(self, user_id=None):
        """Return a dict containing public info for a user.

        Args:
            user_id (int, optional): The ID of the user to get the info for.
                Defaults to the logged in user's ID.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/retrieveUserInfo_get
        """
        if user_id is None:
            return self.user()
        method = "GET"
        url = "/v1/user/userinfo"
        d = {"userid": user_id}
        return self.xda.requests.basic_request(method, url, body=d)

    @login_required
    def add_my_device(self, device_id):
        """Add a device to "My Devices" for the logged in user.

        Args:
            device_id (int): The ID of the device to add. This is the device's
                top forum ID.

        See Also:
            `forums.find_by_device()`
            https://api.xda-developers.com/explorer/#!/user/retrieveUserInfo_get
        """
        method = "POST"
        url = "/v1/user/addmydevice"
        d = {"deviceid": device_id}
        return self.xda.requests.basic_request(method, url, body=d)

    def google_login(self, access_token):
        """Use Google+ Login system.

        Args:
            access_token (str): access token for Google+.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/createGoogleLogin_post
        """
        method = "POST"
        url = "/v1/user/googlelogin"
        d = {"access_token": access_token}
        return self.xda.requests.basic_request(method, url, body=d)

    def google_register(self, access_token, username):
        """Register a new account using Google+

        Args:
            access_token (str): access token for Google+.
            username (str): username.

        See Also:
            https://api.xda-developers.com/explorer/#!/user/createGoogleRegister_post
        """
        method = "POST"
        url = "/v1/user/googleregister"
        d = {"access_token": access_token,
             "username": username}
        return self.xda.requests.basic_request(method, url, body=d)

    def login(self, username, password):
        """Log in.

        Args:
            username (str): username.
            password (str): password.
{'fraction_non_alphanumeric': 0.10812109562710236, 'fraction_numerical': 0.0038443056222969728, 'mean_word_length': 2.128523111612176, 'pattern_counts': {'":': 11, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 14, 'lorem ipsum': 0, 'www.': 2, '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': '6767851', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2400, 'n_words': 763}