Sha256: 86349ce8d8c76d657a23bf1214862f2b1a28f73a951575ad6528d1ffdb526d57

Contents?: true

Size: 1.1 KB

Versions: 18

Compression:

Stored size: 1.1 KB

Contents

module Unsplash # :nodoc:

  # Unsplash Category operations.
  class Category < Client

    class << self

      # Get a list of all of the Unsplash photo categories.
      # @return [Array] The list categories.
      def all
        JSON.parse(connection.get("/categories/").body).map do |category|
          new category
        end
      end

      # Get an Unsplash Category.
      # @param id [Integer] The ID of the category to retrieve.
      # @return [Unsplash::Category] The specified category.
      def find(id)
        new JSON.parse(connection.get("/categories/#{id}").body)
      end
    end

    # Get a list of all photos in this category.
    # @param page  [Integer] Which page of search results to return.
    # @param per_page [Integer] The number of search results per page. 
    # @return [Array] A single page of +Unsplash::Photo+s.
    def photos(page = 1, per_page = 10)
      params = {
        page:     page,
        per_page: per_page
      }
      list = JSON.parse(connection.get("/categories/#{id}/photos", params).body)
      list.map { |photo| Unsplash::Photo.new photo }
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
unsplash-1.5.5 lib/unsplash/category.rb
unsplash-1.5.4 lib/unsplash/category.rb
unsplash-1.5.3 lib/unsplash/category.rb
unsplash-1.5.2 lib/unsplash/category.rb
unsplash-1.5.1 lib/unsplash/category.rb
unsplash-1.5.0 lib/unsplash/category.rb
unsplash-1.4.3 lib/unsplash/category.rb
unsplash-1.4.2 lib/unsplash/category.rb
unsplash-1.4.1 lib/unsplash/category.rb
unsplash-1.4.0 lib/unsplash/category.rb
unsplash-1.3.1 lib/unsplash/category.rb
unsplash-1.3.0 lib/unsplash/category.rb
unsplash-1.2.1 lib/unsplash/category.rb
unsplash-1.2.0 lib/unsplash/category.rb
unsplash-1.1.0 lib/unsplash/category.rb
unsplash-1.0.0 lib/unsplash/category.rb
unsplash-1.0.0.pre.rc.2 lib/unsplash/category.rb
unsplash-1.0.0.pre.rc.1 lib/unsplash/category.rb