Merge branch 'develop' into 'master'
Random Bunny 1.1 See merge request Vylpes/random-bunny!6
This commit is contained in:
commit
5f52791f14
3 changed files with 1211 additions and 9 deletions
20
index.js
20
index.js
|
@ -33,13 +33,25 @@ function randomBunny(subreddit, sortBy, cb) {
|
|||
const random = getRandom(0, size - 1);
|
||||
|
||||
// Get variables from json to pass back
|
||||
const image = data[random].data['url'];
|
||||
const title = data[random].data['title'];
|
||||
const randomSelect = data[random].data;
|
||||
|
||||
// The json string to send back
|
||||
const json = {
|
||||
archived: randomSelect['archived'],
|
||||
downs: randomSelect['downs'],
|
||||
hidden: randomSelect['hidden'],
|
||||
permalink: randomSelect['permalink'],
|
||||
subreddit: randomSelect['subreddit'],
|
||||
subredditSubscribers: randomSelect['subreddit_subscribers'],
|
||||
title: randomSelect['title'],
|
||||
ups: randomSelect['ups'],
|
||||
url: randomSelect['url']
|
||||
};
|
||||
|
||||
// If the post is a .jpg, send back the data and stop looping
|
||||
if (image.includes('.jpg')) {
|
||||
if (json.url.includes('.jpg')) {
|
||||
found = true;
|
||||
cb(image, title);
|
||||
cb(json);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
1181
package-lock.json
generated
1181
package-lock.json
generated
File diff suppressed because it is too large
Load diff
19
readme.md
19
readme.md
|
@ -14,8 +14,8 @@ $ npm install --save random-bunny
|
|||
```js
|
||||
const randomBunny = require('random-bunny');
|
||||
|
||||
randomBunny('rabbits', 'new', (image, title) => {
|
||||
console.log(title + ": " + image);
|
||||
randomBunny('rabbits', 'new', res => {
|
||||
console.log(res.title + ": " + res.url);
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -24,7 +24,18 @@ randomBunny('rabbits', 'new', (image, title) => {
|
|||
|
||||
### `randomBunny()`
|
||||
|
||||
Returns a `url` and `title` for a random post to the `callback`. Accepts 3 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'), `callback(image, title)`
|
||||
Returns a `json string` for a random post to the `callback`. Accepts 3 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'), `callback(res)`
|
||||
|
||||
The json string which gets returned consists of:
|
||||
- archived
|
||||
- downs
|
||||
- hidden
|
||||
- permalink
|
||||
- subreddit
|
||||
- subredditSubscribers
|
||||
- title
|
||||
- ups
|
||||
- url
|
||||
|
||||
## Notes
|
||||
|
||||
|
@ -37,4 +48,4 @@ Returns a `url` and `title` for a random post to the `callback`. Accepts 3 argum
|
|||
|
||||
## License
|
||||
|
||||
MIT © [Vylpes](https://gitlab.vylpes.com/Vylpes);
|
||||
MIT © [Vylpes](https://gitlab.vylpes.com/Vylpes)
|
Loading…
Reference in a new issue