<commit_before># -*- coding: utf-8 -*-
"""
Monzo API related code
"""
from __future__ import unicode_literals

import codecs
import json
import os

import requests
from oauthlib.oauth2 import TokenExpiredError
from requests_oauthlib import OAuth2Session
from six.moves.urllib.parse import urljoin

from pymonzo.api_objects import MonzoAccount, MonzoBalance, MonzoTransaction
from pymonzo import config
from pymonzo.exceptions import MonzoAPIError, CantRefreshTokenError

from pymonzo.utils import CommonMixin


class MonzoAPI(CommonMixin):
    """
    Base class that smartly wraps official Monzo API.

    Official docs:
        https://monzo.com/docs/
    """
    api_url = 'https://api.monzo.com/'

    _access_token = None
    _client_id = None
    _client_secret = None
    _auth_code = None

    _cached_accounts = None

    def __init__(self, access_token=None, client_id=None, client_secret=None,
                 auth_code=None):
        """
        We need Monzo access token to work with the API, which we try to get
        in multiple ways detailed below. Basically you need to either pass
        it directly, pass your client ID, client secret and OAuth 2 auth code
        or have the token already saved on the disk from previous OAuth 2
        authorization.

        We then create an OAuth authorised session and get the default
        account ID if there's only one available.

        :param access_token: your Monzo access token
        :type access_token: str
        :param client_id: your Monzo client ID
        :type client_id: str
        :param client_secret: your Monzo client secret
        :type client_secret: str
        :param auth_code: your Monzo OAuth 2 auth code
        :type auth_code: str
        """
        # Lets get the access token from:<commit_msg>pots update<commit_after># -*- coding: utf-8 -*-
"""
Monzo API related code
"""
from __future__ import unicode_literals

import codecs
import json
import os

import requests
from oauthlib.oauth2 import TokenExpiredError
from requests_oauthlib import OAuth2Session
from six.moves.urllib.parse import urljoin

from pymonzo.api_objects import MonzoAccount, MonzoBalance, MonzoTransaction
from pymonzo import config
from pymonzo.exceptions import MonzoAPIError, CantRefreshTokenError

from pymonzo.utils import CommonMixin


class MonzoAPI(CommonMixin):
    """
    Base class that smartly wraps official Monzo API.

    Official docs:
        https://monzo.com/docs/
    """
    api_url = 'https://api.monzo.com/'

    _access_token = None
    _client_id = None
    _client_secret = None
    _auth_code = None

    _cached_accounts = None
    _cached_pots = None

    def __init__(self, access_token=None, client_id=None, client_secret=None,
                 auth_code=None):
        """
        We need Monzo access token to work with the API, which we try to get
        in multiple ways detailed below. Basically you need to either pass
        it directly, pass your client ID, client secret and OAuth 2 auth code
        or have the token already saved on the disk from previous OAuth 2
        authorization.

        We then create an OAuth authorised session and get the default
        account ID if there's only one available.

        :param access_token: your Monzo access token
        :type access_token: str
        :param client_id: your Monzo client ID
        :type client_id: str
        :param client_secret: your Monzo client secret
        :type client_secret: str
        :param auth_code: your Monzo OAuth 2 auth code
        :type auth_code: str
        """
        # Lets get the access token from:
{'fraction_non_alphanumeric': 0.05607734806629834, 'fraction_numerical': 0.0033149171270718232, 'mean_word_length': 2.8893662728249194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1172520', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1009, 'n_words': 394}