-
Notifications
You must be signed in to change notification settings - Fork 3
/
boxcar-growl
executable file
·52 lines (43 loc) · 1.16 KB
/
boxcar-growl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
use Config::Tiny;
use LWP::UserAgent;
use Getopt::Long;
my $prog = basename($0);
my $conf = $ENV{HOME}.'/.'.$prog;
(my $source = $prog) =~ s/[_-]/ /g;
my $r = GetOptions(
'sound=s' => \my $sound,
);
if (! $r or $#ARGV < 0) {
print <<EOF;
usage: $prog [-s|--sound <sound name>] <title> [message]
-s|--sound <sound> specify sound name
sound name list:
https://boxcar.uservoice.com/knowledgebase/articles/306788-how-to-send-your-boxcar-account-a-notification
EOF
;
exit -1;
}
my $title = shift @ARGV;
my $message = join(' ', @ARGV);
if (! $message) {
my @message = <STDIN>;
$message = join('', @message);
}
my $ini = Config::Tiny->read($conf) || die Config::Tiny->errstr;
my %formdata = (
user_credentials => $ini->{_}{token},
'notification[title]' => $title,
'notification[long_message]' => $message,
'notification[sound]' => $sound || 'clanging',
'notification[source_name]' => $source,
);
my $res = LWP::UserAgent->new(timeout => 10)->post(
'https://new.boxcar.io/api/notifications',
\%formdata);
if (! $res->is_success) {
print $res->message . "\n";
}