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

Commit

Permalink
Add optional 'count' parameter for photos.getRandomPhoto (#39)
Browse files Browse the repository at this point in the history
* I added the missing optional parameter count for unsplash.photos.getRandomPhoto()

* I improved the function unsplash.photos.getRandomPhoto()
  • Loading branch information
MagicPoulp authored and Joshua Comeau committed Mar 13, 2017
1 parent 1c24fda commit 0bf3f3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,14 @@ unsplash.photos.getPhotoStats("mtNweauBsMQ")
### photos.getRandomPhoto({ width, height, query, username, featured, category })
Retrieve a single random photo, given optional filters.

The category parameter is deprecated and should not be used.

When using this function, It is recommended to double check the types of the parameters,
in particular for the parameters of type Array<number>.

__Arguments__

Argument 1:
_An Object containing the follow keys:_

| Argument | Type | Opt/Required |
Expand All @@ -432,7 +438,9 @@ _An Object containing the follow keys:_
|__`query`__|_string_|Optional|
|__`username`__|_string_|Optional|
|__`featured`__|_boolean_|Optional|
|__`category`__|_Array<number>_|Optional|
|__`category`__ *(deprecated)*|_Array<number>_|Optional|
|__`collections`__|_Array<number>_|Optional|
|__`count`__|_string_|Optional|

__Example__
```js
Expand All @@ -441,7 +449,9 @@ unsplash.photos.getRandomPhoto({ username: "naoufal" })
.then(json => {
// Your code
});

```

---

### photos.uploadPhoto(photo)
Expand Down
6 changes: 4 additions & 2 deletions src/methods/photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ export default function photos(): Object {

getRandomPhoto: (options = {}) => {
const url = "/photos/random";
const category = options.category || [];
const collections = options.collections || [];

const query = {
category: options.category,
featured: options.featured,
username: options.username,
orientation: options.orientation,
category: category.join(),
collections: collections.join(),
query: options.query,
w: options.width,
h: options.height,
c: options.cacheBuster || new Date().getTime() // Avoid ajax response caching
c: options.cacheBuster || new Date().getTime(), // Avoid ajax response caching
count: options.count
};

Object.keys(query).forEach(key => {
Expand Down

0 comments on commit 0bf3f3e

Please sign in to comment.