rufbit
v1.0.2
Published
Rufbit is a service that helps you to stay on top of what is going on in all of your projects at all times.
Downloads
2
Readme
rufbit nodejs
Getting Started
Rufbit helps you to stay on top of what is going on in all of your projects at all times. This documentation will help you integrate rufbit into your projects and get you started as fast as possible.
Overview
This package provides user-friendly access to the rufbit API from nodejs applications. It includes pre-defined classes and methods that dynamically communicate with the rufbit API and thereby allow a simple integration.
Installation
If you don't have an account yet, make sure to sign up first.
To install the rufbit package simply run:
npm install rufbit
Alternatively you can also use our API if you prefer that or if your platform is not supported yet.
Usage
First of all you need to require the rufbit package. This can be achieved by adding the following line:
const { Rufbit, RufbitState } = require('./node_modules/rufbit');
In order to use the package, you will first need to set the API-key. This key is specific to your project and can be found in your project configuration (Projects -> [Project] -> Configuration).
The API-key can be set with the following code:
Rufbit.setApiKey("YOUR API-KEY HERE");
Sending notifications
In order to send notifications, simply call the Rufbit.send(..)
function and pass the parameters title
, data
, state
and callback
.
Rufbit.send(title, data, state, callback);
|Param|Type|Details| |-----|----|-------| |title|string|The title of your notification| |data|object|A json object that contains your data| |state|integer|Indicates the notification type. For further details see notification object| |callback|function|Callback function, returns the result
Example 1: Send Notification
Rufbit.send("Foobar just subscribed!", { plan: "premium" }, RufbitState.SUCCESS, function(result)
{
// handle result here
});
The state of the notification can take the values success
, error
, warning
, info
and other
.
Make sure you are passing a valid JSON object to the data -attribute. A possible JSON-object might look like this:
{
"email": "[email protected]",
"username": "foobar",
"subscription": "premium",
"paid": true
}
Error Handling:
Rufbit will respond with a result object. If the request completed sucessfully the response will look like this:
{
"success": true
}
In case a request could not be completed successfully for some reason, rufbit will respond with:
{
"success": false,
"error_msg": "error message"
}
This can happen due to many reasons such as a wrong API-key or invalid parameters.
Full Example
const { Rufbit, RufbitState } = require('./node_modules/rufbit');
Rufbit.setApiKey("YOUR API-KEY HERE");
Rufbit.send("title", { data: "example" }, RufbitState.SUCCESS, function(result)
{
if(result["success"] == true)
{
console.log("Successful");
}
else
{
console.log("Error: " + result["error_msg"])
}
});