add URL option with -u
This commit is contained in:
parent
de9fb1cd47
commit
94dc286d2e
10
pushover.pl
10
pushover.pl
@ -27,16 +27,18 @@ GetOptions(
|
||||
"message=s" => \(my $MESSAGE),
|
||||
"title=s" => \(my $TITLE = "Notification"),
|
||||
"priority=i" => \(my $PRIORITY = 0),
|
||||
"config=s" => \(my $CONFIG),
|
||||
"url=s" => \(my $URL),
|
||||
"application=s" => \(my $APPLICATION = '_'),
|
||||
"config=s" => \(my $CONFIG),
|
||||
);
|
||||
|
||||
my $USAGE = <<"END_USAGE";
|
||||
Usage: $0 -m message [-t title] [-p priority] [-a application] [-c config]
|
||||
Usage: $0 -m message [-t title] [-p priority] [-u url] [-a application] [-c config]
|
||||
Options:
|
||||
-m | --message text
|
||||
-t | --title text | (default: Notification)
|
||||
-p | --priority [0|1] (default: 0)
|
||||
-u | --url text (no default)
|
||||
-a | --application text (default: root property of config)
|
||||
-c | --config text (no default)
|
||||
END_USAGE
|
||||
@ -51,6 +53,8 @@ my $http = HTTP::Tiny->new;
|
||||
my %HEADERS = ("Content-Type" => "application/json");
|
||||
my $uri = "https://api.pushover.net/1/messages.json";
|
||||
my $request = HTTP::Tiny->new('default_headers' => \%HEADERS);
|
||||
my $body = JSON::PP->new->encode({token => "$TOKEN", user => "$USER", title => "$TITLE", message => "$MESSAGE", priority => "$PRIORITY"});
|
||||
my $json = {token => "$TOKEN", user => "$USER", title => "$TITLE", message => "$MESSAGE", priority => "$PRIORITY"};
|
||||
$json->{'url'} = $URL if $URL;
|
||||
my $body = JSON::PP->new->encode($json);
|
||||
my $response = $request->post($uri, {'content' => $body});
|
||||
print "Pushover: $response->{'status'} $response->{'reason'}\n";
|
||||
|
Loading…
Reference in New Issue
Block a user