<commit_before>from itertools import chain
import requests

from soccermetrics import SoccermetricsRestException
from soccermetrics import __api_version__ as API_VERSION

class Resource(object):
    """
    Represents a REST resource.
    """
    def __init__(self, base_uri, auth):
        self.base_uri = base_uri
        self.auth = auth

        self.endpoint = "/%s" % API_VERSION

    def get(self, uid=None, **kwargs):
        """
        Retrieves a representation of REST resource.
        """
        uri = "%s%s/%d" % (self.base_uri, self.endpoint, uid) if uid else \
            "%s%s" % (self.base_uri, self.endpoint)

        full_param_dict = dict(chain(kwargs.items() + self.auth.items()))

        resp = requests.get(uri,params=full_param_dict)

        if resp.status_code == 200:
            result = resp.json()['result']
            return result[0] if len(result) == 1 else result
        else:
            raise SoccermetricsRestException(resp.status_code,resp.url)

    def head(self):
        """
        Retrieves header data of REST resource.
        """
        uri = "%s%s" % (self.base_uri, self.endpoint)

        resp = requests.head(uri,params=self.auth)

        if resp.status_code < 400:
            return resp.headers
        else:
            raise SoccermetricsRestException(resp.status_code,resp.url)

    def options(self):
        """
        Retrieves documentation of REST resource representation.

        Link resources are not included in the documentation.
        """
        uri = "%s%s" % (self.base_uri, self.endpoint)

        resp = requests.options(uri,params=self.auth)

        if resp.status_code == 200:
            return dict(headers=resp.headers,
                    data=resp.json()['result']['data'])
        else:
            raise SoccermetricsRestException(resp.status_code,resp.url)


class Link(Resource):
    """
    Access to linked resources, can also access any API endpoint.
    """
    def __init__(self, base_uri, auth):
        super(Link, self).__init__(base_uri, auth)

    def get(self, uri, **kwargs):
        self.endpoint = uri
        return super(Link, self).get(**kwargs)

    def head(self, uri):<commit_msg>Wrap responses in EasyDict() to allow dot notation<commit_after>from itertools import chain
from easydict import EasyDict
import requests

from soccermetrics import SoccermetricsRestException
from soccermetrics import __api_version__ as API_VERSION

class Resource(object):
    """
    Represents a REST resource.
    """
    def __init__(self, base_uri, auth):
        self.base_uri = base_uri
        self.auth = auth

        self.endpoint = "/%s" % API_VERSION

    def get(self, uid=None, **kwargs):
        """
        Retrieves a representation of REST resource.
        """
        uri = "%s%s/%d" % (self.base_uri, self.endpoint, uid) if uid else \
            "%s%s" % (self.base_uri, self.endpoint)

        full_param_dict = dict(chain(kwargs.items() + self.auth.items()))

        resp = requests.get(uri,params=full_param_dict)

        if resp.status_code == 200:
            result = resp.json()['result']
            return EasyDict(result[0]) if len(result) == 1 else EasyDict(result)
        else:
            raise SoccermetricsRestException(resp.status_code,resp.url)

    def head(self):
        """
        Retrieves header data of REST resource.
        """
        uri = "%s%s" % (self.base_uri, self.endpoint)

        resp = requests.head(uri,params=self.auth)

        if resp.status_code < 400:
            return EasyDict(resp.headers)
        else:
            raise SoccermetricsRestException(resp.status_code,resp.url)

    def options(self):
        """
        Retrieves documentation of REST resource representation.

        Link resources are not included in the documentation.
        """
        uri = "%s%s" % (self.base_uri, self.endpoint)

        resp = requests.options(uri,params=self.auth)

        if resp.status_code == 200:
            return EasyDict(dict(headers=resp.headers,
                                 data=resp.json()['result']['data']))
        else:
            raise SoccermetricsRestException(resp.status_code,resp.url)


class Link(Resource):
    """
    Access to linked resources, can also access any API endpoint.
    """
    def __init__(self, base_uri, auth):
        super(Link, self).__init__(base_uri, auth)

    def get(self, uri, **kwargs):
        self.endpoint = uri
        return super(Link, self).get(**kwargs)

    def head(self, uri):
{'fraction_non_alphanumeric': 0.1129818342933097, 'fraction_numerical': 0.004873726185201595, 'mean_word_length': 2.3972911963882617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2475193', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1301, 'n_words': 326}