Skip to content

Commit

Permalink
Merge pull request #6 from pexels/collections/add-featured-endpoint
Browse files Browse the repository at this point in the history
Add new endpoint, update documentation and version accordingly
  • Loading branch information
Kassandre Pedro authored Aug 17, 2021
2 parents 1a852d0 + 320d95a commit fe7fd68
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions lib/pexels/client/collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion lib/pexels/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Pexels
VERSION = '0.3.0'
VERSION = '0.4.0'
end
19 changes: 19 additions & 0 deletions test/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe7fd68

Please sign in to comment.