Skip to content

Instantly share code, notes, and snippets.

@voodoojello
Created December 13, 2010 03:18
Show Gist options
  • Save voodoojello/738612 to your computer and use it in GitHub Desktop.
Save voodoojello/738612 to your computer and use it in GitHub Desktop.
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 [[email protected]]
# 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__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment