# (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 # # A getter which POSTs the JSONified metadata to a remote URL package videosite::HTTPJSONGetter; use videosite::GetterBase; @ISA = qw(videosite::GetterBase); use strict; use LWP::UserAgent; use JSON -support_by_pp; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'HTTPJSONGetter', _PARAMS => { URL => ['http://www.example.com/getjson.pl', "The URL to call in order to trigger a download. The JSON encoded information will be POSTed to this URL."] }, @_, ); return bless($self, $class); } sub get { my $self = shift; my $video = shift; my $j = JSON->new(); my $ua = LWP::UserAgent->new('agent' => 'Mozilla/5.0'); my $jdata; my $r; $jdata = $j->encode($video); $self->debug("Encoded metadata to %s", $jdata); $r = $ua->post($self->_getval('URL'), {'json' => $jdata}); unless ($r->is_success()) { $self->error("Error calling RPC: %s", $r->code()); return 0; } return 1; }