Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for html and device to API call #596

Merged
merged 1 commit into from
Jul 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions lib/Pushover.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Configure the required pushover settings in your mh.private.ini file:

Pushover_token = <API token from Pushover.net registration>
Pushover_user = <User or Group ID from Pushover.net registraton>
Pushover_device = <Default device or device list to sedn notifications to. List is comma-separated>
Pushover_priority = [-1 | 0 | 1 | 2] Default message priority, defaults to 0.
Pushover_html = [ 0 | 1 ] Support HTML messages, see https://pushover.net/api#html. Defaults to 0.
Pushover_title = "MisterHouse" Default title for messages if none provided
Pushover_disable = 1 Disable notifications. Messages will still be logged

Expand Down Expand Up @@ -39,6 +41,9 @@ values provided on initialization. See the method documentation for below more

$push->notify( "Some important message", { title => 'Security Alert', priority => 2 });

Or with HTML formmatting
$push->notify( "Some <b>important</b> message", { title => 'Security Alert', priority => 2, html => 1 });

=head2 DESCRIPTION

The Pushover instance establishes the defaults for messages and acts as a rudimentary rate limiter for notifications.
Expand Down Expand Up @@ -90,7 +95,8 @@ Creates a new Pushover object. The parameter hash is optional. Defaults will be
B<This must be excluded from the primary misterhouse loop, or the acknowledgment checking and duplicate message rate limiting will be lost>

my $push = Pushover->new( { priority => 0, # Set default Message priority, -1, 0, 1, 2
retry => 60, # Set default retry priority 2 notification every 60 seconds
html => 1, # Support HTML formatting of message ...see https://pushover.net/api#html
retry => 60, # Set default retry priority 2 notification every 60 seconds
expire => 3600, # Set default expration of the retry timer
title => "Some title", # Set default title for messages
token => "xxxx...", # Set the API Token
Expand Down Expand Up @@ -122,11 +128,12 @@ sub new {
$params = {} unless defined $params;

my $self = {};
$self->{priority} = 0; # Priority zero - honor quite times
$self->{speak} = 1; # Speak notifications and acknowledgments
$self->{priority} = 0; # Priority zero - honour quite times
$self->{speak} = 1; # Speak notifications and acknowledgements
$self->{html} = 0; # Default html off

# Merge the mh.private.ini defaults into the object
foreach (qw( token user priority title server retry expire speak disable)) {
foreach (qw( token user priority html title device server retry expire speak disable)) {
$self->{$_} = $params->{$_};
$self->{$_} = $::config_parms{"Pushover_$_"} unless defined $self->{$_};
}
Expand Down Expand Up @@ -163,11 +170,13 @@ information for the notification. The list is not exclusive. Additional parame
in the POST to Pushover.net. This allows support of any API parameter as defined at https://pushover.net/api

$push->notify("Some urgent message", { priority => 2, # Message priority, -1, 0, 1, 2
retry => 60, # Retry priority 2 notification every 60 seconds
expire => 3600, # Give up if not ack of priority 2 notify after 1 hour
title => "Some title", # Override title of message
token => "xxxx...", # Override the API Token - probably not useful
user => "xxxx...", # Override the target user/group
html => 1, # HTML formatting of message 0-off, 1-on ... see https://pushover.net/api#html
retry => 60, # Retry priority 2 notification every 60 seconds
expire => 3600, # Give up if not ack of priority 2 notify after 1 hour
title => "Some title", # Override title of message
device => "nexus5,iphone" # Device or device-list
token => "xxxx...", # Override the API Token - probably not useful
user => "xxxx...", # Override the target user/group
});

Notify will record the last message sent along with a timestamp. If the duplicate message is sent within
Expand Down Expand Up @@ -210,7 +219,7 @@ sub notify {
}

# Merge in the message defaults, They can be overridden
foreach (qw( token user priority title url url_title sound retry expire )) {
foreach (qw( token user priority html title device url url_title sound retry expire )) {
next unless ( defined $self->{$_} );
$callparms->{$_} = $self->{$_} unless defined $callparms->{$_};
}
Expand All @@ -225,6 +234,11 @@ sub notify {
$callparms->{expire} = 86400 if ( $callparms->{expire} > 86400 );
}

# remove html if off
if ( $callparms->{html} != 1 ) {
delete $callparms->{html};
}

&::print_log(
"[Pushover] Notify parameters: " . Data::Dumper::Dumper( \$callparms ) )
if TRACE;
Expand Down Expand Up @@ -354,6 +368,11 @@ sub _checkReceipt {

George Clark

=head2 MODIFICATIONS

2016/04/29 Marc [email protected]
Added html and device support on API call

=head2 SEE ALSO

http://Pushover.net/
Expand All @@ -368,3 +387,4 @@ You should have received a copy of the GNU General Public License along with thi

=cut