-
Notifications
You must be signed in to change notification settings - Fork 131
Items Pushbullet
See original
This module allows MisterHouse to push notification to Pushbullet.com devices. See https://pushbullet.com/ for details of the service and API.
Pushbullet is similar to, but slightly simpler than Pushover. The Pushbullet clients are free.
Configure the required pushbullet settings in your mh.ini file:
Pushbullet_token = <API token from Pushbullet.net registration>
Pushbullet_title = "MisterHouse" Default title for notes if none provided
Pushbullet_disable = 1 Disable notifications. Messages will still be logged
Create a pushbullet instance in the .mht file, or in user code:
#
CODE, require Pushbullet; #noloop
CODE, $push = new Pushbullet(); #noloop
A user code file overriding parameters normally specified in mh.ini. All of the parameters are optional if properly configured in the ini file.
my $push = new Pushbullet( {token => '1234qwer1234qewr1234qwer',
title => 'Home Notification',
});
The following example shows how to push a note in the user code. The only required parameter is the first, the note text. Any of the parameters provided when initializing the Pushbullet instance may also be provided on the note push. They will be merged with and override the default values provided on initialization. See the method documentation for below more details.
my $iden = $push->push_note( "Some important message", { title => 'Security Alert' });
The returned $iden
is the pushed message identification hash. In the future this can be used to delete and possibly modify a push.
The parameter device_iden
is by default left blank, thus causing the push to be sent to all of your devices. If you specify a device_iden
, the push will be sent to that device only. Alternatively, if you specify an email address, the push will be sent to that user.
The Pushbullet instance establishes the defaults for pushes.
Data::Dumper: Used for error reporting and debugging
LWP::UserAgent: Implements HTTPS for interaction with Pushbullet.com
JSON: Decodes responses from Pushbullet.com
Method | Description |
---|---|
new(p_self, p_parameter_hash) | Creates a new Pushbullet object. The parameter hash is optional. Defaults will be taken from the mh.ini file or are hardcoded. |
Ecample
my $push = Pushbullet->new( {
title => "Some title", # Set default title for messages
token => "xxxx...", # Set the API Token
server => "...", # Override the Pushbullet server URL. Defaults to the public pushbullet server
speak => 0 # Speak acknowledgments
});
Any of these parameters may be specified in mh.ini by prefixing them with "Pushbullet_"
The various push_note, push_link, push_address ... functions are designed to be user friendly. Each function takes the required parameters as scalar values. The last parameter is an optional hash, that can be used to pass additional optional parameters to pushbullet.
The optional parameter hash can be used to override defaults, or specify additional information for the notification. Additional parameters will be passed as part of the JSON content to Pushbullet.com. This allows support of any API parameter as defined at http://docs.pushbullet.com, even those that do not exist yet.
A user friendly interface to push a note. The note title and text, p_title p_body, are the only mandatory parameters.
The following is an example of the push_note function. The other functions work similarly.
$push->push_note("MisterHouse Title", "Some urgent message", {
token => "xxxx...", # Override the API Token - probably not useful
device_iden => "xxxx..." # The device to which the note should be sent to
});
By default, the device_iden
is left blank, which causes the notes to be sent to all devices on your account.
A user friendly interface to push a url. The url title and address, p_title p_url, are the only mandatory parameters.
The url push can optionally include a message in the body. It can be passed to the function as follows:
$push->push_link("MisterHouse Docs", "http://misterhouse.net", {
body => "If you have questions about MisterHouse please go here."
});
### `push_address(p_self, p_name, p_address, p_paramater_hash)`
A user friendly interface to push a geographic address. The address name and address, p_name p_address, are the only mandatory parameters.
### `push_list(p_self, p_title, p_item_array_ref, p_paramater_hash)`
A user friendly interface to push a list of items. The list title and items, p_title p_item_array_ref, are the only mandatory parameters.
`p_item_array_ref` must be passed as an array referrence. Such as:
```perl
$push->push_list("Grocery List", "http://misterhouse.net",
['apple', 'banana', 'orange']
);
A user friendly interface to push a file. The file name, type, and url are required parameters.
p_type
is a mime type, such as "image/jpeg"
An optional body message can be passed as body on the parameter hash.
Pushbullet offers a storage service that can be used to upload and store files for pushing. Currently, this feature is not enabled in MisterHouse.
This is routine provides direct raw access to the push process. It is not as user friendly as the simpler push_note .... routines.
The parameter hash is required, and the required keys must be used such as type.
Other keys can override defaults, or specify additional information for the push. The list is not exclusive. Additional parameters will be passed in the POST to Pushbullet.com. This allows support of any API parameter as defined at http://docs.pushbullet.com
$push->push_hash( {
type => "note",
body => "Note text",
title => "Some title", # Override title of message
token => "xxxx...", # Override the API Token - probably not useful
device_iden => "xxxx...", # The device to which the note should be sent to
action => "POST", # The request type to use (GET, POST, DELETE)
path => "v2/pushes" # This is the general path, some functions use slightly diff paths
});
By default, the device_iden
is left blank, which causes the pushes to be sent to all devices on your account.
This can be used to delete a push. The only required parameter is the p_push_iden. This is the hash identification which is returned by the push_ functions.
For example, you may only want a notification to last an hour:
$push_timer = new Timer;
my $push_iden = $push->push_note("MisterHouse", "Good morning");
set $push_timer 60*60, "get_object_by_name('push')->delete_push('$push_iden');";
The above code will require that you have registered the object by name using register_object_by_name.
Kevin Robert Keegan (based on template from Pushover.pm by George Clark)