def related(self, collection_id): """ Retrieve a list of collections related to this one. :param collection_id [string]: The collection’s ID. Required. :return: [Array]: A single page of the Collection list. """ url = "/collections/%s/related" % collection_id result = self._get(url) return CollectionModel.parse_list(result)
def get_curated(self, collection_id): """ Retrieve a single curated collection. To view a user’s private collections, the 'read_collections' scope is required. :param collection_id [string]: The collections’s ID. Required. :return: [Collection]: The Unsplash Collection. """ url = "/collections/curated/%s" % collection_id result = self._get(url) return CollectionModel.parse(result)
def curated(self, page=1, per_page=10): """ Get a single page from the list of curated collections. :param page [integer]: Page number to retrieve. (Optional; default: 1) :param per_page [integer]: Number of items per page. (Optional; default: 10) :return: [Array]: A single page of the Collection list. """ url = "/collections/curated" result = self._all(url, page=page, per_page=per_page) return CollectionModel.parse_list(result)
def collections(self, username, page=1, per_page=10): """ Get a list of collections created by the user. :param username [string]: The user’s username. Required. :param page [integer]: Page number to retrieve. (Optional; default: 1) :param per_page [integer]: Number of items per page. (Optional; default: 10) :return: [Array]: A single page of the Collection list. """ url = "/users/{username}/collections".format(username=username) params = {"page": page, "per_page": per_page} result = self._get(url, params=params) return CollectionModel.parse_list(result)
def collections(self, query, page=1, per_page=10): """ Get a single page of collection results for a query. :param query [string]: Search terms. :param page [integer]: Page number to retrieve. (Optional; default: 1) :param per_page [integer]: Number of items per page. (Optional; default: 10) :return: [dict]: {u'total': 0, u'total_pages': 0, u'results': [Collection]} """ url = "/search/collections" data = self._search(url, query, page=page, per_page=per_page) data["results"] = CollectionModel.parse_list(data.get("results")) return data
def remove_photo(self, collection_id, photo_id): """ Remove a photo from one of the logged-in user’s collections. Requires the 'write_collections' scope. :param collection_id [string]: The collection’s ID. Required. :param photo_id [string]: The photo’s ID. Required. :return: [Tuple]: The Unsplash Collection and Photo """ url = "/collections/%s/remove" % collection_id data = {"collection_id": collection_id, "photo_id": photo_id} result = self._delete(url, data=data) or {} return CollectionModel.parse( result.get("collection")), PhotoModel.parse(result.get("photo"))
def create(self, title, description=None, private=False): """ Create a new collection. This requires the 'write_collections' scope. :param title [string]: The title of the collection. (Required.) :param description [string]: The collection’s description. (Optional.) :param private [boolean]: Whether to make this collection private. (Optional; default false). :return: [Collection]: The Unsplash Collection. """ url = "/collections" data = {"title": title, "description": description, "private": private} result = self._post(url, data=data) return CollectionModel.parse(result)
def add_photo(self, collection_id, photo_id): """ Add a photo to one of the logged-in user’s collections. Requires the 'write_collections' scope. Note: If the photo is already in the collection, this acion has no effect. :param collection_id [string]: The collection’s ID. Required. :param photo_id [string]: The photo’s ID. Required. :return: [Tuple]: The Unsplash Collection and Photo """ url = "/collections/%s/add" % collection_id data = {"collection_id": collection_id, "photo_id": photo_id} result = self._post(url, data=data) or {} return CollectionModel.parse( result.get("collection")), PhotoModel.parse(result.get("photo"))
def update(self, collection_id, title=None, description=None, private=False): """ Update an existing collection belonging to the logged-in user. This requires the 'write_collections' scope. :param collection_id [string]: The collection’s ID. Required. :param title [string]: The title of the collection. (Required.) :param description [string]: The collection’s description. (Optional.) :param private [boolean]: Whether to make this collection private. (Optional; default false). :return: [Collection]: The Unsplash Collection. """ url = "/collections/%s" % collection_id data = {"title": title, "description": description, "private": private} result = self._put(url, data=data) return CollectionModel.parse(result)