Base Resources

Represents interactions with hypertexted resources in the API.

This class is effectively a client within a client, so it can access any API endpoint if the base URI and authentication pair are defined appropriately.

Derived from Resource.

get(uri, **kwargs)[source]

Returns a representation of the REST resource.

Its functionality is derived from Resource.get().

Parameters:
  • uri (string) – URI of REST resource, relative to base URI.
  • kwargs (dict) – Collection of query parameters.
Returns:

Resource representation.

Return type:

EasyDict object.

head(uri)[source]

Retrieves header data of the REST resource.

Its functionality is derived from Resource.head().

Parameters:uri (string) – URI of REST resource, relative to base URI.
Returns:Header data.
Return type:EasyDict object.
options(uri)[source]

Retrieves documentation of the REST resource representation.

Its functionality is derived from Resource.options().

Parameters:uri (string) – URI of REST resource, relative to base URI.
Returns:Resource documentation data.
Return type:EasyDict object.
class soccermetrics.rest.resources.base.Resource(base_uri, auth)[source]

Represents interactions with a REST API resource.

Sets the high-level (versioning) endpoint for the API resource.

Parameters:
  • base_uri (string) – Base URI of API.
  • auth (tuple) – Authentication credential.
get(uid=None, **kwargs)[source]

Retrieves a representation of the REST resource.

If the request is successful, returns an EasyDict object that uses dot notation for the response contents.

A request may be unsuccessful for two reasons:

  • The API returns an error (HTTP code not 200). In this situation, the client raises a SoccermetricsRestException with the HTTP code, the request URI, and a detailed error message.
  • The requests module raises an exception. In this case, the client raises a SoccermetricsRestException with HTTP code 500, the request URI and a detailed error message from the module.
Parameters:
  • uid (integer) – Unique ID of API resource representation.
  • kwargs (dict) – Collection of query parameters.
Returns:

Resource representation.

Return type:

EasyDict object.

head()[source]

Retrieves header data of the REST resource.

The response is an object with the following attribute:

Attribute Description
headers Response headers

If the request is successful, the client returns an EasyDict object that uses dot notation for the response contents.

If the request is unsuccessful (HTTP code 4xx or 5xx), the client raises a SoccermetricsRestException that includes the HTTP status code and the request URI.

Returns:Header data.
Return type:EasyDict object.
options()[source]

Retrieves documentation of the REST resource representation.

If the status code is 200 (OK), returns the documentation. Otherwise, returns an error.

The response is an object with the following attributes:

Attribute Description
headers Response headers
data Resource documentation

Link resources are not included in the documentation.

Returns:Resource documentation data.
Return type:EasyDict object.
class soccermetrics.rest.resources.base.Response(base_uri, auth, resp)[source]

Represents a REST API response object and its pagination properties and methods.

The response is an object with the following attributes:

Attribute Description
status Response status code
headers Response headers
_meta Response meta-data, internal use only
data Response data

The response also contains the following properties:

Property Description
page Current page of response
pages Total pages of response
records_page Number of records per page
records Total records in response

You can use the following methods to page through the response:

Method Description
first() First page of API response
prev() Previous page of API response
next() Next page of API response
last() Last page of API response

If you wish to access all of the data at once, there is the all() method.

Derived from Resource.

all()[source]

Retrieve all data of the API response at once.

first()[source]

Go to first page of the API response.

If meta-data does not exist (i.e. no GET data), return None.

last()[source]

Go to last page of the API response.

If meta-data does not exist (i.e. no GET data), return None.

next()[source]

Go to next page of the API response.

If meta-data does not exist (i.e. no GET data), return None.

page[source]

Current page of API response given pagination settings.

If meta-data does not exist (i.e. no GET data), the current page is zero.

pages[source]

Total pages in API response given pagination settings.

If meta-data does not exist (i.e. no GET data), the total number of pages is zero.

prev()[source]

Go to previous page of the API response.

If meta-data does not exist (i.e. no GET data), return None.

records[source]

Total records in the API response.

If meta-data does not exist (i.e. no GET data), total number of records is zero.

records_page[source]

Records per page of the API response, either default or set by user’s API request.

If meta-data does not exist (i.e. no GET data), records per page is zero.