From 41e54978572a9e0814c128e5f7ab90325f14e761 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 20 May 2016 13:53:45 -0400 Subject: [PATCH] Added support for html and device to API call --- lib/Pushover.pm | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/Pushover.pm b/lib/Pushover.pm index 0f30cef37..0501be78d 100644 --- a/lib/Pushover.pm +++ b/lib/Pushover.pm @@ -11,7 +11,9 @@ Configure the required pushover settings in your mh.private.ini file: Pushover_token = Pushover_user = + Pushover_device = 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 @@ -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 important 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. @@ -90,7 +95,8 @@ Creates a new Pushover object. The parameter hash is optional. Defaults will be B 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 @@ -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->{$_}; } @@ -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 @@ -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->{$_}; } @@ -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; @@ -354,6 +368,11 @@ sub _checkReceipt { George Clark +=head2 MODIFICATIONS + +2016/04/29 Marc mhcoder@nowheremail.com + Added html and device support on API call + =head2 SEE ALSO http://Pushover.net/ @@ -368,3 +387,4 @@ You should have received a copy of the GNU General Public License along with thi =cut +