Crates.io | rqpush |
lib.rs | rqpush |
version | 0.4.9 |
source | src |
created_at | 2019-10-14 06:08:13.538102 |
updated_at | 2019-12-02 12:40:07.788729 |
description | A library to assist with pushing notifications to RQueue. |
homepage | https://github.com/jeremyandrews/rqpush |
repository | https://github.com/jeremyandrews/rqpush |
max_upload_size | |
id | 172347 |
size | 108,746 |
A library to assist with pushing notifications to RQueue.
RQPush is only useful as a library for pushing notifications into RQueue. For this purpose, it provides the following functionality:
Notifications require the following three fields:
app
: application nametitle
: the title of the notification, for example used as an email subjectshort_text
: the body of the notificationThe following fields can optionally be defined as well:
url
: ie, the URL of the project generating the notification, or a URL to view more informationtagline
: a description of the project generating the notificationcategory
: allows arbitrary categorization of notifications, primarily used for filtering and routinglang
: two letter language code, defaults to "en"short_text_template
: allows handlebar variable replacement, for example {{foo}}
short_html
: html version of short_textshort_html_template
: allows handlebar variable replacement and wraps in appropriate HTML tagslong_text
: optional extended version of short_text
long_html_template
: allows handlebar variable replacement and wraps in appropriate HTML tagsvalues
: key-value pairs for handlebars-style templatingNotifications are created as follows:
use rqpush::Notification;
let mut notification: Notification = Notification::init("app name", "title", "short text");
This is enough to generate a basic notification, however additional customization is possible. For example, to set a project URL on a notification that was created per the earlier example:
notification.set_title("https://github.com/jeremyandrews/rqpush");
And finally, a notification can be sent as follows:
notification.send("127.0.0.1:8000", 42, 0, None);
In this example, we send the notification to port 8000 on localhost, with a priority of 42. We don't set a TTL so the notification or a shared secret.
The following example shows a real-world example, sending a notification with Netgrasp.
use rqpush::Notification;
let mut notification: Notification = Notification::init("Netgrasp", "[netgrasp] new device: {{device}}", "A new device joined your network: {{device}}");
notification.set_category("first_seen_device");
@TODO: Finish:
{
"app": "Netgrasp",
"category": "first_seen_device",
"lang": "en",
"title": "[netgrasp] new device: iPhone",
"short_text": "A new device joined your network: iPhone",
"short_html": "<P>A new device joined your network: <EM>iPhone</EM></P>",
"long_text": "A new device joined your network:
* iPhone
* ip: 10.202.14.37 [ff:ff:ff:ff:ff:ff]
* previously seen: never
* first seen: now
In the past 24 hours this device talked to 1 device:
* Gateway: 10.202.14.1
Email generated by Netgrasp passive network observation tool.",
"long_html": "<P><UL>
<LI>iPhone</LI>
<LI>ip: 10.202.14.37 [ff:ff:ff:ff:ff:ff]</LI>
<LI>previously seen: never</LI>
<LI>first seen: now</LI>
</UL>
In the past 24 hours this device talked to 1 device:
<UL>
<LI>Gateway: 10.202.14.1</LI>
</UL></P>
<DIV ID="footer">
<P><SMALL><EM>Email generated by Netgrasp passive network observation tool.</EM></SMALL></P>
</DIV>",
}