https://github.com/sidoshi/ghnp
Rx utilites for GitHub Notifications Polling
https://github.com/sidoshi/ghnp
github-notifications-polling rx-utilites
Last synced: about 2 months ago
JSON representation
Rx utilites for GitHub Notifications Polling
- Host: GitHub
- URL: https://github.com/sidoshi/ghnp
- Owner: sidoshi
- License: mit
- Created: 2018-05-09T07:57:21.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-09T14:38:03.000Z (about 7 years ago)
- Last Synced: 2025-04-01T14:21:13.958Z (about 2 months ago)
- Topics: github-notifications-polling, rx-utilites
- Language: JavaScript
- Size: 72.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# ghnp
[](https://travis-ci.org/sidoshi/ghnp) [](https://github.com/sidoshi/ghnp/issues) [](http://hits.dwyl.io/sidoshi/ghnp) [](https://www.npmjs.com/package/ghnp) [](https://www.npmjs.com/package/ghnp)
> Rx utilites for GitHub Notifications Polling
No knowledge of RxJs is required to use this lib.
## Install
```bash
npm install --save ghnp
```## Usage
```js
import GHNP from 'ghnp'// A Github token with `repo` and `notifications` scope
// https://developer.github.com/apps/building-oauth-apps/scopes-for-oauth-apps/
const token = 'GITHUB_TOKEN'const ghnp = GHNP(token)
const subscription = ghnp
.poll({
defaultInterval: 10000, // Interval to wait on polling, Default: 60000
params: { all: true }, // Optionally add params
})
.subscribe({
next: notification => console.log(notification),
error: err => console.log(err),
compelete: () => console.log('Done'),
})// At any point you can stop polling by calling
subscription.unsubscribe()
```Except token used to initialize `GHNP`, no other options are required.
```js
// No options are required
ghnp.poll().subscribe({
next: notification => console.log(notification),
error: err => console.log(err),
compelete: () => console.log('Done'),
})
````defaultInterval` does not gaurantee that the requests will be polled
at that interval. `X-Poll-Interval` header returned from Github is obeyed and
the highest interval from `defaultInterval` and `X-Poll-Interval` is used.As the raw notifications object is a bit cluttered, `parseNotifications` can be
used to extract all the usefull informations including the `html_url` which
can be used to directly visit the concerned page.```js
ghnp
.poll()
.pipe(ghnp.parseNotifications())
.subscribe({
next: notification => console.log(notification),
error: err => console.log(err),
compelete: () => console.log('Done'),
})
```See the schema of [raw notification](https://github.com/sidoshi/ghnp/blob/master/src/types.js#L7-L86) object and [parsed notification](https://github.com/sidoshi/ghnp/blob/master/src/types.js#L111-L117) objects.
## License
MIT © [Siddharth Doshi](https://sid.sh)