Collections

class TheNounProjectAPI.collections.Collections(key=None, secret=None, testing=False, timeout=5.0)

Bases: TheNounProjectAPI.core.Core

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)

get_collection_by_id(_id)

Fetches a single Collection by id.

Parameters

_id (int) – Collection ID.

Raises

NonPositive – Raises exception when id is nonpositive.

Returns

CollectionModel object identified by the _id.

Return type

CollectionModel

get_collection_by_slug(slug)

Fetches a single Collection by slug.

Parameters

slug (str) – Collection slug.

Raises

IllegalSlug – Raises exception when slug is an empty string, contains non ascii characters or contains multiple words.

Returns

CollectionModel object identified by the slug.

Return type

CollectionModel

get_collection(identifier)

Fetches a single Collection, either by id or by slug.

Parameters

identifier (Union[int, str]) – Collection identifier (id or slug).

Raises
  • NonPositive – Raises exception when identifier is a nonpositive integer.

  • IllegalSlug – Raises exception when identifier is a string that’s empty, non-ascii or with multiple words.

Returns

CollectionModel object identified by the identifier.

Return type

CollectionModel

get_collections(limit=None, offset=None, page=None)

Fetches a list of all Collections.

Parameters
  • limit (int) – Maximum number of results. (defaults to None)

  • offset (int) – Number of results to displace or skip over. (defaults to None)

  • page (int) – Number of results of limit length to displace or skip over. (defaults to None)

Returns

List of CollectionModel objects.

Return type

List[CollectionModel]

get_user_collections(user_id)

Fetches a list of Collections associated with a user.

Parameters

user_id (int) – User id.

Raises

NonPositive – Raises exception when user_id is not positive.

Returns

List of CollectionModel objects associated with a user identified by the user_id.

Return type

List[CollectionModel]

get_user_collection(user_id, slug)

Fetches a single Collection associated with a user.

Parameters
  • user_id (int) – User id.

  • slug (str) – Collection slug.

Raises
  • NonPositive – Raises exception when user_id is not positive.

  • IllegalSlug – Raises exception when slug is an empty string, contains non ascii characters or contains multiple words.

Returns

CollectionModel object identified by the slug, from the user identified by the user_id.

Return type

CollectionModel