voodoojello
12/13/2010 - 3:18 AM

Simple Boxcar User Notification using Library for WWW in Perl (LWP)

Simple Boxcar User Notification using Library for WWW in Perl (LWP)

#!/usr/bin/perl -w
#
# Simple Boxcar User Notification using Library for WWW in Perl (LWP)
# Author: mark page [m.e.page@voodoojello.net]
# Modified: Sun Dec 12 21:16:43 CST 2010
#
# expects Boxcar user sign-up address, *not* push.boxcar.io address as $ARGV[0]
#
use strict;
use warnings;
use LWP::UserAgent;
use Digest::MD5 "md5_hex";

unless (@ARGV) { die "no email adddress provided!"; }
my $email_md5 = md5_hex($ARGV[0]);

my $api = {
	'key'    => 'xxxxxxxxxxxxxxxxxxxx',			# 20 Char Provider API Key
	'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',	# 40 Char Provider API Secret
	};

my $notification = {
	'from' => 'Boxcar LWP Test',
	'msg'  => 'This is a test: Boxcar User Token via Perl LWP at ' . localtime(time),
	'url'  => 'http://boxcar.io/devices/providers/' . $api->{key} . '/notifications',
	};

my $browser  = LWP::UserAgent->new;
my $response = $browser->post (
	$notification->{url}, [
		'email'                                => $email_md5,
		'secret'                               => $api->{secret},
		'notification[from_screen_name]'       => $notification->{from},
		'notification[message]'                => $notification->{msg},
		'notification[from_remote_service_id]' => time, # Just a unique placeholder
		'notification[redirect_payload]'       => $email_md5,
		'notification[source_url]'             => 'http://your.url.here',
		'notification[icon_url]'               => 'http://your.url.to/image.here',
		],
	);

for my $key (keys %{$response}) { print $key . ': ' . $response->{$key} . "\n"; }

exit;

__END__