diff --git a/CHANGES.md b/CHANGES.md index 65d475c..eb247d2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ # Change log +## 0.4.0 +* Add support for returning featured collections. + ## 0.3.0 * Add support for photo and video search with filters. * Added `avg_color` attribute to `Photo` object. diff --git a/README.md b/README.md index efbf927..d959ae0 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,11 @@ Note: this is limited to collections belonging to the API user. ```ruby client.collections.all ``` +### List all featured collections. + +```ruby +client.collections.featured.all +``` ### Get all media for a collection diff --git a/lib/pexels/client/collections.rb b/lib/pexels/client/collections.rb index 6c550ee..e4133f0 100644 --- a/lib/pexels/client/collections.rb +++ b/lib/pexels/client/collections.rb @@ -14,6 +14,17 @@ def all(per_page: 15, page: 1) Pexels::CollectionSet.new(response) end + def featured(per_page: 15, page: 1) + response = @client.request( + "#{Pexels.api_version}/collections/featured", + params: { + per_page: per_page, + page: page + }) + + Pexels::CollectionSet.new(response) + end + def [](id, type: nil, per_page: 15, page: 1) response = @client.request( "#{Pexels.api_version}/collections/#{id}", diff --git a/lib/pexels/version.rb b/lib/pexels/version.rb index 2367cdf..4872eb3 100644 --- a/lib/pexels/version.rb +++ b/lib/pexels/version.rb @@ -1,3 +1,3 @@ module Pexels - VERSION = '0.3.0' + VERSION = '0.4.0' end diff --git a/test/collection_test.rb b/test/collection_test.rb index 326761f..00aab7b 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -27,6 +27,25 @@ def test_all assert_kind_of Pexels::CollectionSet, collection_with_params.prev_page end + def test_featured + collection = @client.collections.featured + + assert_kind_of Pexels::CollectionSet, collection + assert_equal collection.per_page, 15 + assert_equal collection.page, 1 + + assert collection.collections.is_a? Array + assert collection.collections.any? + assert collection.first.is_a? Pexels::Collection + + collection_with_params = @client.collections.featured(per_page: 1, page: 2) + assert_equal collection_with_params.per_page, 1 + assert_equal collection_with_params.page, 2 + assert_equal collection_with_params.collections.length, 1 + assert_kind_of Pexels::CollectionSet, collection_with_params.next_page + assert_kind_of Pexels::CollectionSet, collection_with_params.prev_page + end + def test_get_collection_media collection = @client.collections[@collection.id] assert_kind_of Pexels::CollectionMediaSet, collection