| 1 | #=============================================================================== | ||
| 2 | # FILE: ShowSearchRequest.pm | ||
| 3 | # AUTHOR: Kyle Brandt (mn), kyle@kbrandt.com , http://www.kbrandt.com | ||
| 4 | # COMPANY: Home | ||
| 5 | #=============================================================================== | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | |||
| 10 | package WebService::TVRage::ShowSearchRequest; | ||
| 11 | |||
| 12 | use Mouse; | ||
| 13 | use LWP::UserAgent; | ||
| 14 | use HTTP::Request::Common; | ||
| 15 | use XML::Simple; | ||
| 16 | use Data::Dumper; | ||
| 17 | use WebService::TVRage::ShowList; | ||
| 18 | has 'showTitle' => ( is => 'rw'); | ||
| 19 | has 'URL' => ( is => 'rw', | ||
| 20 | default => 'http://www.tvrage.com/feeds/search.php?show='); | ||
| 21 | |||
| 22 | sub search { | ||
| 23 | my $self = shift; | ||
| 24 | my $showTitle = shift; | ||
| 25 | $self->showTitle($showTitle); | ||
| 26 | my $uA = LWP::UserAgent->new( timeout => 20); | ||
| 27 | my $showSearchReq = HTTP::Request->new(GET => $self->URL . $self->showTitle); | ||
| 28 | my $showSearchResponse = $uA->request($showSearchReq); | ||
| 29 | print $showSearchResponse->error_as_HTML unless $showSearchResponse->is_success; | ||
| 30 | my $xml = new XML::Simple; | ||
| 31 | my $processedXML = $xml->XMLin( $showSearchResponse->decoded_content, (ForceArray => ['show'])); | ||
| 32 | return undef if $processedXML == 0; | ||
| 33 | my $object = WebService::TVRage::ShowList->new(); | ||
| 34 | $object->_showListHash($processedXML); | ||
| 35 | return $object; | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | =head1 NAME | ||
| 41 | |||
| 42 | WebService::TVRage::ShowSearchRequest - Requests A List of shows using TVRage's XML Service | ||
| 43 | |||
| 44 | =head1 SYNOPSIS | ||
| 45 | |||
| 46 | my $heroesSearch = WebService::TVRage::ShowSearchRequest->new( showTitle => 'Heroes' ); | ||
| 47 | $heroesSearch->search(); | ||
| 48 | |||
| 49 | =head1 Methods | ||
| 50 | |||
| 51 | =head2 new() | ||
| 52 | |||
| 53 | my $heroesSearch = WebService::TVRage::ShowSearchRequest->new( showTitle => 'Heroes' ); | ||
| 54 | |||
| 55 | Constructor object for creating a request to search for Shows by title. | ||
| 56 | |||
| 57 | =over 1 | ||
| 58 | |||
| 59 | =item showTitle | ||
| 60 | |||
| 61 | Set this to the title of the show you are searching for. | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =head2 search() | ||
| 66 | |||
| 67 | $heroes->search() | ||
| 68 | |||
| 69 | Sends a request to TVRage for which ever show you specified with the showTitle attribute and returns a WebService::TVRage::ShowList object | ||
| 70 | |||
| 71 | =head1 AUTHOR | ||
| 72 | |||
| 73 | Kyle Brandt, kyle@kbrandt.com | ||
| 74 | http://www.kbrandt.com | ||
| 75 | |||
| 76 | =cut |