1package WebService::Technorati::OutboundApiQuery; 2use strict; 3use utf8; 4 5use WebService::Technorati::ApiQuery; 6use WebService::Technorati::LinkQuerySubject; 7use WebService::Technorati::BlogLink; 8use WebService::Technorati::Exception; 9use base 'WebService::Technorati::ApiQuery'; 10 11BEGIN { 12 use vars qw ($VERSION $DEBUG); 13 $VERSION = 0.04; 14 $DEBUG = 0; 15} 16 17use constant API_URI => '/cosmos'; 18 19sub new { 20 my ($class, %params) = @_; 21 if (! exists $params{'key'}) { 22 WebService::Technorati::InstantiationException->throw( 23 "WebService::Technorati::OutboundApiQuery must be " . 24 "instantiated with at least 'key => theverylongkeystring'"); 25 } 26 my $data = {}; 27 if (! exists $params{'url'}) { 28 $data->{'needs_url'}++; 29 } 30 for my $k (keys %params) { 31 $data->{'args'}{$k} = $params{$k}; 32 } 33 my $self = bless ($data, ref ($class) || $class); 34 return $self; 35} 36 37sub url { 38 my $self = shift; 39 my $url = shift; 40 if ($url) { 41 $self->{'url'} = $url; 42 delete($self->{'needs_url'}); 43 } 44 return $self->{'url'}; 45} 46 47sub execute { 48 my $self = shift; 49 my $apiUrl = $self->apiHostUrl() . API_URI; 50 if (exists $self->{'needs_url'}) { 51 WebService::Technorati::StateValidationException->throw( 52 "WebService::Technorati::AuthorinfoApiQuery must have a " . 53 "'url' attribute set prior to query execution"); 54 } 55 $self->SUPER::execute($apiUrl,$self->{'args'}); 56} 57 58sub readResults { 59 my $self = shift; 60 my $result_xp = shift; 61 my $error = $result_xp->find('/tapi/document/result/error'); 62 if ($error) { 63 WebService::Technorati::DataException->throw($error); 64 } 65 my $nodeset = $result_xp->find("/tapi/document/result"); 66 my $node = $nodeset->shift; 67 my $blogSubject = WebService::Technorati::LinkQuerySubject->new_from_node($node); 68 $nodeset = $result_xp->find('/tapi/document/item'); 69 my @links = (); 70 for my $node ($nodeset->get_nodelist) { 71 my $blogLink = WebService::Technorati::BlogLink->new_from_node($node); 72 push(@links, $blogLink); 73 } 74 $self->{'subject'} = $blogSubject; 75 $self->{'links'} = \@links; 76 77} 78 79 80=head2 getLinkQuerySubject 81 82 Usage : getLinkQuerySubject(); 83 Purpose : 84 Returns : a scalar WebService::Technorati::LinkQuerySubject instance 85 Argument : none 86 Throws : none 87 Comments : the URL subject (blog or not) is returned with what 88 Technorati knows about it 89See Also : WebService::Technorati 90 91=cut 92 93sub getLinkQuerySubject { 94 my $self = shift; 95 return $self->{'subject'}; 96} 97 98 99=head2 getOutboundLinks 100 101 Usage : getOutboundLinks(); 102 Purpose : 103 Returns : an array of WebService::Technorati::BlogLink instances 104 Argument : none 105 Throws : none 106 Comments : the list of outbound links are returned with what Technorati knows 107 about them 108See Also : WebService::Technorati 109 110=cut 111 112 113sub getOutboundLinks { 114 my $self = shift; 115 return (wantarray) ? @{$self->{'links'}} : $self->{'links'}; 116} 117 1181; 119