Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from unsplash/feature/featured-collections
Browse files Browse the repository at this point in the history
Add featured collections method.
  • Loading branch information
Naoufal Kadhom committed May 17, 2016
2 parents ef83fdf + a548f36 commit 5a63576
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,26 @@ unsplash.collections.listCuratedCollections(1, 10)
```
---

### collections.listFeaturedCollections(page, perPage)
Get a single page from the list of featured collections.

__Arguments__

| Argument | Type | Opt/Required |
|---|---|---|
|__`page`__|_number_|Optional|
|__`perPage`__|_number_|Optional|

__Example__
```js
unsplash.collections.listFeaturedCollections(1, 10)
.then(toJson)
.then(json => {
// Your code
});
```
---

### collections.getCollection(id)
Retrieve a single collection. To view a user’s private collections, the `read_collections` scope is required.

Expand Down
14 changes: 14 additions & 0 deletions src/methods/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ export default function collections(): Object {
});
},

listFeaturedCollections: (page: number = 1, perPage: number = 10) => {
const url = "/collections/featured";
const query = {
page,
per_page: perPage
};

return this.request({
url: url,
method: "GET",
query
});
},

getCollection: collection.bind(this, false),

getCuratedCollection: collection.bind(this, true),
Expand Down
17 changes: 17 additions & 0 deletions test/unsplash-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,23 @@ describe("Unsplash", () => {
});
});

describe("listFeaturedCollections", () => {
it("should make a GET request to /collections/featured", () => {
let spy = spyOn(unsplash, "request");
unsplash.collections.listFeaturedCollections(2, 15);

expect(spy.calls.length).toEqual(1);
expect(spy.calls[0].arguments).toEqual([{
method: "GET",
url: "/collections/featured",
query: {
page: 2,
per_page: 15
}
}]);
});
});

describe("getCollection", () => {
it("should make a GET request to /collections/{id}", () => {
let spy = spyOn(unsplash, "request");
Expand Down

0 comments on commit 5a63576

Please sign in to comment.