Core¶
-
class
TheNounProjectAPI.core.
Core
(key=None, secret=None, testing=False, timeout=5.0)¶ Bases:
TheNounProjectAPI.keys.Keys
Core is a class providing helper functions useful for accessing the TheNounProject API.
Construct a new object for making API requests.
- Parameters
key (str) – The API key from the TheNounProject API. (defaults to None)
secret (str) – The secret key from the TheNounProject API. (defaults to None)
testing (bool) – Whether the methods should return a PreparedRequest, instead of data from the API. Should not be used except for testing this wrapper. (defaults to False)
timeout (Union[float, Tuple[float, float], None]) – Float timeout in seconds, 2-tuples for seperate connect and read timeouts, and None for no timeout. (defaults to 5.0)
-
_send
(url)¶ - Parameters
url (requests.PreparedRequest) – The PreparedRequest with the method, URL and parameters for the request.
- Returns
Returns a requests.Response object generated by performing the URL request with our session.
- Return type
requests.Response
-
_prepare_url
(url, **params)¶ Returns a requests.PreparedRequest object for a request self._method as method, for the given URL, with the given parameters/json, with authentication.
- Parameters
url (str) – The URL of the requested endpoint.
params (dict) – The parameters to be added onto the string.
- Returns
A requests.PreparedRequest object.
- Return type
requests.PreparedRequest
-
_type_assert
(param, param_name, types)¶ Asserts that param is an instance of any type in types.
- Parameters
param (Any) – Parameter to check type of.
param_name (str) – Name of this parameter, for use in error message.
types (Union[Type[Any], Tuple[Type[Any], ..]]) – Types to check param against. Either a single type or a tuple of types.
- Raises
IncorrectType – Raises exception if param is not an instance of any type in types.
- Return type
None
-
_lop_assert
(limit, offset, page)¶ Asserts that limit, offset and page parameters are all integers.
- Parameters
limit (Any) – Limit parameter to be used as a parameter in the URL request.
offset (Any) – Offset parameter to be used as a parameter in the URL request.
page (Any) – Page parameter to be used as a parameter in the URL request.
- Raises
IncorrectType – Raises exception when limit, offset or page are not of NoneType or integer type.
- Return type
None
-
_id_assert
(_id, param_name)¶ Asserts that the _id parameter is positive.
- Parameters
_id (int) – Id of which we want to make sure it is positive.
param_name (str) – Name of this parameter, for use in error message.
- Raises
NonPositive – Raises exception when _id is not positive.
- Return type
None
-
_slug_assert
(slug, param_name)¶ Asserts that slug is nonempty, ascii, and does not contain spaces.
- Parameters
slug (str) – String slug parameter to be used as a parameter in the URL request.
param_name (str) – Name of this parameter, for use in error message.
- Raises
IllegalSlug – Raises exception when slug is empty, contains non-ascii characters, or contains spaces.
- Return type
None
-
_term_assert
(term, param_name)¶ Asserts that term is nonempty.
- Parameters
term (str) – String term parameter to be used as a parameter in the URL request.
param_name (str) – Name of this parameter, for use in error message.
- Raises
IllegalTerm – Raises exception when term has a length of 0.
- Return type
None
-
_close_session
()¶ Closes the requests.Session used for making requests.