diff --git a/index.js b/index.js index eaa2bce..c7cef1b 100644 --- a/index.js +++ b/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); } } }); diff --git a/readme.md b/readme.md index 64e64cd..a52c9d5 100644 --- a/readme.md +++ b/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) \ No newline at end of file