From fed839f1f787523ce470bf8db93bec3b851ad6b3 Mon Sep 17 00:00:00 2001 From: Sharl Morlaroll Date: Thu, 5 Apr 2012 18:25:39 +0900 Subject: [PATCH] Support from stdin. Support default icon URL environment variable. --- README | 14 ++++++++++---- boxcar-growl | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/README b/README index f5c9406..a365fff 100644 --- a/README +++ b/README @@ -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 @@ -7,7 +7,7 @@ Copyright(C) Sharl Morlaroll * Installation 1. Join Boxcar (http://boxcar.io/) -2. Install Boxcar +2. Install Boxcar to device 3. Add Boxcar service "Growl" 4. Write to ~/.netrc @@ -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://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://sharl.hauN.org/puppet.png + $ BOXCAR_GROWL_ICON=http://sharl.hauN.org/puppet.png boxcar-growl sharl "This is default icon setting." + + Standard icon size is 57x57. diff --git a/boxcar-growl b/boxcar-growl index de53412..ec63cc4 100755 --- a/boxcar-growl +++ b/boxcar-growl @@ -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 <] [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 = ; + $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]);