2016-04-27 20:06:24 +01:00
|
|
|
# random-puppy [![Build Status](https://travis-ci.org/dylang/random-puppy.svg?branch=master)](https://travis-ci.org/dylang/random-puppy)
|
|
|
|
|
|
|
|
> Get a random puppy image url.
|
|
|
|
|
|
|
|
<img src="http://i.imgur.com/0zZ8m6B.jpg" width="300px">
|
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
```
|
|
|
|
$ npm install --save random-puppy
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```js
|
|
|
|
const randomPuppy = require('random-puppy');
|
|
|
|
|
|
|
|
randomPuppy()
|
|
|
|
.then(url => {
|
|
|
|
console.log(url);
|
|
|
|
})
|
|
|
|
|
|
|
|
//=> 'http://imgur.com/IoI8uS5'
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## API
|
|
|
|
|
2016-04-29 03:23:21 +01:00
|
|
|
### `randomPuppy()`
|
2016-04-27 20:06:24 +01:00
|
|
|
|
2016-04-27 20:12:06 +01:00
|
|
|
Returns a `promise` for a random puppy image url from http://imgur.com/ from https://www.reddit.com/r/puppy
|
2016-04-27 20:06:24 +01:00
|
|
|
|
2016-04-29 03:23:21 +01:00
|
|
|
### `randomPuppy(subreddit)`
|
2016-04-27 20:06:24 +01:00
|
|
|
|
2016-04-27 20:12:06 +01:00
|
|
|
Returns a `promise` for a random image url from the selected subreddit. *Warning: We cannot promise it will be a image of a puppy!*
|
|
|
|
|
2016-04-29 03:23:21 +01:00
|
|
|
### `randomPuppy.all(subreddit)`
|
|
|
|
|
|
|
|
Returns an `eventemitter` for getting all random images for a subreddit.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const event = randomPuppy.all(subreddit);
|
|
|
|
event.on('data', url => console.log(url));
|
|
|
|
```
|
|
|
|
|
|
|
|
Or:
|
|
|
|
```js
|
|
|
|
const event = randomPuppy.all('puppies');
|
|
|
|
|
|
|
|
Observable.fromEvent(event, 'data')
|
|
|
|
.subscribe(data => {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2016-04-27 20:12:06 +01:00
|
|
|
## Notes
|
|
|
|
|
|
|
|
* Node 4 or newer.
|
|
|
|
* Caches results from imgur in memory.
|
|
|
|
* Created for the purpose of using in a training exercise on different ways to do async in JavaScript at [Opower](https://opower.com/).
|
2016-04-27 20:06:24 +01:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
MIT © [Dylan Greene](https://github.com/dylang)
|