A consumer for the notifications service that uses polling
Table of Contents
- Bower
If you are using Bower to manage all the frontend dependencies in your project you can use it to install this library:
bower install notifications-js-polling-consumer --saveIf you want to use the version available in the master branch you can use bower link.
- In this project's root:
bower link- In the project where you are using this lib run the following:
bower link notifications-js-polling-consumer- That's it, you are using the development version of this library
- Get a token from the notifications service (TODO)
- Include the library and create an instance of the consumer:
var notifications = new Notifications(token);Now you can start use several methods to handle notifications of a particular user
- Get last N notifications, where is N the limit of notifications you get.
notifications.getLastN(N, function(response) {
// 'response' contains an array of notifications objects
}, function(error) {
// Handle error
});- Get all unread notifications
notifications.unread(function(response) {
// 'response' contains an array of unread notifications
}, function(error) {
// Handle error
});- Get all notifications that were created after a given one
notifications.after(id, function(response) {
/* 'response' contains an array of all notifications
* that happened after the one with id 'id'
*/
}, function(error) {
// Handle error
});- Read a given notification
notifications.read(id, function(response) {
// Notification was successfully marked as read
}, function(error) {
// Handle error
});- Get all new notifications from time to time. This is pooling to give the illusion of a real time application.
notifications.poll(seconds, function(response) {
// 'response' contains an array of new notifications
// This callback is invoked at each 'seconds' interval
}, function(error) {
// Handle error
});To stop polling you can do the following:
notifications.stopPolling();- NodeJS
- NPM
- Bower
- Grunt CLI
First, clone this repo to have access to the library's source code.
Then, install all the dependencies using NPM:
npm installUse Grunt to generate the bundle file
gruntThe generated file is available at build/notifications.js.
To create the files to be included in the production environment you can use Grunt:
grunt distThe generated file is available at dist/notifications.js
You can also use Grunt to create a new release. It will generate the production ready file, increment the version number in both bower.json and package.json files, create a new tag in the repository and push all the changes.
grunt release