<commit_before>import base64
import logging

import gocardless
import urlbuilder
from gocardless.utils import generate_signature, to_query, signature_valid
from gocardless.request import Request
from gocardless.exceptions import ClientError, SignatureError
from gocardless.resources import (Merchant, Subscription, Bill,
                                  PreAuthorization, User)

logger = logging.getLogger(__name__)


class Client(object):
    """The main interface to the GoCardless API

    This class is the starting point for interacting with GoCardless.
    If you are a merchant than you can obtain a client instance by setting
    your account details in :py:func:`gocardless.set_details`.

    If you are a
    partner and need OAuth access to other merchants' accounts then you need
    to create a client using your app id and app secret, then use the OAuth
    APIs to obtain authorization over the merchants' account.

    """

    API_PATH = '/api/v1'

    BASE_URLS = {
        'production': 'https://gocardless.com',
        'sandbox': 'https://sandbox.gocardless.com',
    }

    base_url = None

    @classmethod
    def get_base_url(cls):
        """
        Return the correct base URL for the current environment. If one has
        been manually set, default to that.
        """
        return cls.base_url or cls.BASE_URLS[gocardless.environment]

    def __init__(self, app_id, app_secret, access_token=None,
                 merchant_id=None):
        """Create a client

        :param string app_id: Your application id.
        :param string app_secret: Your app secret.
        :param string access_token: The access token for this account, this
            should be your access token from the developer settings page unless
            you are trying to manage another merchants' account via OAuth.
        :param string merchant_id: The merchant id for this account, should be
            your merchant id unless you are trying to manage another account
            via OAuth.
        """
        self._app_id = app_id
        self._app_secret = app_secret
        if access_token:
            self._access_token = access_token
        if merchant_id:
            self._merchant_id = merchant_id

    def api_get(self, path, **kwargs):
        """
        Issue an GET request to the API server.

        :param path: the path that will be added to the API prefix
        """
        return self._request('get', self.API_PATH + path, **kwargs)

    def api_post(self, path, data, **kwargs):
        """Issue a POST request to the API server

        :param path: The path that will be added to the API prefix
        :param data: The data to post to the url.
        """
        return self._request('post', self.API_PATH + path, data=data,
                             **kwargs)

    def api_put(self, path, data={}, **kwargs):
        """Issue a PUT request to the API server

        :param path: The path that will be added to the API prefix
        :param data: The data to put to the url.
        """
        return self._request('put', self.API_PATH + path, data=data,
                             **kwargs)

    def api_delete(self, path, **kwargs):
        """Issue a delete to the API server.

        :param path: the path that will be added to the API prefix
        :param params: query string parameters
        """
        return self._request('delete', self.API_PATH + path, **kwargs)

    def _request(self, method, path, **kwargs):
        """
        Send a request to the GoCardless API servers.

        :param method: the HTTP method to use (e.g. +:get+, +:post+)
        :param path: the path fragment of the URL<commit_msg>Move constants to module level<commit_after>import base64
import logging

import gocardless
import urlbuilder
from gocardless.utils import generate_signature, to_query, signature_valid
from gocardless.request import Request
from gocardless.exceptions import ClientError, SignatureError
from gocardless.resources import (Merchant, Subscription, Bill,
                                  PreAuthorization, User)

logger = logging.getLogger(__name__)

API_PATH = '/api/v1'
BASE_URLS = {
    'production': 'https://gocardless.com',
    'sandbox': 'https://sandbox.gocardless.com',
}


class Client(object):
    """The main interface to the GoCardless API

    This class is the starting point for interacting with GoCardless.
    If you are a merchant than you can obtain a client instance by setting
    your account details in :py:func:`gocardless.set_details`.

    If you are a
    partner and need OAuth access to other merchants' accounts then you need
    to create a client using your app id and app secret, then use the OAuth
    APIs to obtain authorization over the merchants' account.

    """

    base_url = None

    @classmethod
    def get_base_url(cls):
        """
        Return the correct base URL for the current environment. If one has
        been manually set, default to that.
        """
        return cls.base_url or BASE_URLS[gocardless.environment]

    def __init__(self, app_id, app_secret, access_token=None,
                 merchant_id=None):
        """Create a client

        :param string app_id: Your application id.
        :param string app_secret: Your app secret.
        :param string access_token: The access token for this account, this
            should be your access token from the developer settings page unless
            you are trying to manage another merchants' account via OAuth.
        :param string merchant_id: The merchant id for this account, should be
            your merchant id unless you are trying to manage another account
            via OAuth.
        """
        self._app_id = app_id
        self._app_secret = app_secret
        if access_token:
            self._access_token = access_token
        if merchant_id:
            self._merchant_id = merchant_id

    def api_get(self, path, **kwargs):
        """
        Issue an GET request to the API server.

        :param path: the path that will be added to the API prefix
        """
        return self._request('get', API_PATH + path, **kwargs)

    def api_post(self, path, data, **kwargs):
        """Issue a POST request to the API server

        :param path: The path that will be added to the API prefix
        :param data: The data to post to the url.
        """
        return self._request('post', API_PATH + path, data=data,
                             **kwargs)

    def api_put(self, path, data={}, **kwargs):
        """Issue a PUT request to the API server

        :param path: The path that will be added to the API prefix
        :param data: The data to put to the url.
        """
        return self._request('put', API_PATH + path, data=data,
                             **kwargs)

    def api_delete(self, path, **kwargs):
        """Issue a delete to the API server.

        :param path: the path that will be added to the API prefix
        :param params: query string parameters
        """
        return self._request('delete', API_PATH + path, **kwargs)

    def _request(self, method, path, **kwargs):
        """
        Send a request to the GoCardless API servers.

        :param method: the HTTP method to use (e.g. +:get+, +:post+)
        :param path: the path fragment of the URL
{'fraction_non_alphanumeric': 0.0754228041462084, 'fraction_numerical': 0.0008183306055646482, 'mean_word_length': 2.396479851783233, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1834922', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1898, 'n_words': 813}