Skip to content

Commit

Permalink
Support from stdin.
Browse files Browse the repository at this point in the history
Support default icon URL environment variable.
  • Loading branch information
sharl committed Apr 5, 2012
1 parent 23f9d10 commit fed839f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
14 changes: 10 additions & 4 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
boxcar-growl - Push notification to Boxcar for iPhone/iPad
boxcar-growl - Push notification to Boxcar for iPhone/iPad/Mac

Copyright(C) Sharl Morlaroll <[email protected]>

Expand All @@ -7,7 +7,7 @@ Copyright(C) Sharl Morlaroll <[email protected]>
* Installation

1. Join Boxcar (http:https://boxcar.io/)
2. Install Boxcar
2. Install Boxcar to device
3. Add Boxcar service "Growl"

4. Write to ~/.netrc
Expand All @@ -19,6 +19,12 @@ machine boxcar.io
5. Let's try!

$ boxcar-growl test "push to boxcar by boxcar-growl"
$ boxcar-growl sharl "puppet icon notification test." --icon http:https://sharl.haun.org/puppet.png
$ echo foo bar | boxcar-growl qux
$ boxcar-growl "from stdin"
foo bar
^D

6. Done.
$ boxcar-growl sharl "puppet icon notification test." --icon http:https://sharl.hauN.org/puppet.png
$ BOXCAR_GROWL_ICON=http:https://sharl.hauN.org/puppet.png boxcar-growl sharl "This is default icon setting."

Standard icon size is 57x57.
35 changes: 30 additions & 5 deletions boxcar-growl
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
#!/usr/bin/perl

use strict;
use File::Basename;
use Net::Netrc;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use Getopt::Long;

my $script = basename($0);
my $icon_url = undef;
GetOptions(
"icon=s" => \$icon_url,
my $env_icon = uc($script) . '_ICON'; $env_icon =~ s/-/_/g;
my $r = GetOptions("icon=s" => \$icon_url
);
if (! $r or $#ARGV < 0) {
print <<EOF;
usage: $script [-i|--icon <icon URL>] <from screen name> [message]
-i|--icon URL specify icon URL
environment variable:
$env_icon specify default icon URL
Standard icon size is 57x57.
EOF
;
exit -1;
}

my $from_screen_name = shift @ARGV;
my $message = join(' ', @ARGV);
if (! $message) {
my @message = <STDIN>;
$message = join('', @message);
$message =~ s/[\r\n]/ /g;
}
$icon_url = $ENV{$env_icon} if (! $icon_url and $ENV{$env_icon});

my $BOXCAR_DOMAIN = 'boxcar.io';
my $netrc = Net::Netrc->lookup($BOXCAR_DOMAIN);

my %formdata = (
'notification[from_screen_name]' => $ARGV[0],
'notification[message]' => $ARGV[1],
'notification[from_screen_name]' => $from_screen_name,
'notification[message]' => $message,
'notification[icon_url]' => $icon_url,
'notification[from_remote_service_id]' => time,
'notification[from_remote_service_id]' => time . $$,
);
my $postURI = "https://$BOXCAR_DOMAIN/notifications";
my $req = POST($postURI, [%formdata]);
Expand Down

0 comments on commit fed839f

Please sign in to comment.