From: Ralf Ertzinger Date: Fri, 27 May 2011 07:21:20 +0000 (+0200) Subject: Add HTTPJSONGetter X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=videosite.git;a=commitdiff_plain;h=1ecf932c3bc66f79608bc057184af51fe323bcb7 Add HTTPJSONGetter --- diff --git a/videosite/HTTPJSONGetter.pm b/videosite/HTTPJSONGetter.pm new file mode 100644 index 0000000..87a6d83 --- /dev/null +++ b/videosite/HTTPJSONGetter.pm @@ -0,0 +1,46 @@ +# (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(); + + $self->{'NAME'} = 'HTTPJSONGetter'; + $self->{'_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."]}; + + bless($self, $class); + $self->_prepare_parameters(); + + return $self; +} + +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; +}