Skip to content

Commit

Permalink
Add user collections method
Browse files Browse the repository at this point in the history
  • Loading branch information
naoufal committed Apr 13, 2016
1 parent 5fe909b commit 6299635
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import Unsplash from 'unsplash-js/native';
Generate an authentication url with the scopes your app requires.

```js
let authenticationUrl = unsplash.auth.getAuthenticationUrl([
const authenticationUrl = unsplash.auth.getAuthenticationUrl([
"public",
"read_user",
"write_user",
Expand Down Expand Up @@ -133,7 +133,7 @@ __Arguments__

__Example__
```js
let authenticationUrl = unsplash.auth.getAuthenticationUrl([
const authenticationUrl = unsplash.auth.getAuthenticationUrl([
"public",
"read_user",
"write_user",
Expand Down Expand Up @@ -289,6 +289,27 @@ unsplash.users.likes("naoufal", 2, 15, "popular")
```
---

### users.collections(username, page, perPage)
Get a list of photos liked by a user.

__Arguments__

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

__Example__
```js
unsplash.users.collections("naoufal", 2, 15)
.then(toJson)
.then(json => {
// Your code
});
```
---

<div id="photos" />

### photos.listPhotos(page, perPage)
Expand Down Expand Up @@ -760,7 +781,7 @@ __Example__
```js
import Unsplash, { toJson } from "unsplash-js";

let unsplash = new Unsplash({
const unsplash = new Unsplash({
applicationId: "{YOUR_APPLICATION_ID}",
secret: "{YOUR_SECRET_KEY}",
callbackUrl: "{YOUR_CALLBACK_URL}"
Expand Down
14 changes: 14 additions & 0 deletions src/methods/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ export default function users(): Object {
order_by: orderBy
};

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

collections: (username: string, page: number = 1, perPage: number = 10) => {
const url = `/users/${username}/collections`;
const query = {
page,
per_page: perPage
};

return this.request({
url,
method: "GET",
Expand Down
17 changes: 17 additions & 0 deletions test/unsplash-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,23 @@ describe("Unsplash", () => {
}]);
});
});

describe("collections", () => {
it("should make a GET request to /users/{username}/collections", () => {
let spy = spyOn(unsplash, "request");
unsplash.users.collections("naoufal");

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

describe("photos", () => {
Expand Down

0 comments on commit 6299635

Please sign in to comment.