Exemple #1
0
    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)
Exemple #2
0
    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"))
Exemple #3
0
    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)
Exemple #4
0
    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"))
Exemple #5
0
    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)