| 1 | package WebService::Technorati::BloginfoApiQuery; | ||
| 2 | use strict; | ||
| 3 | use utf8; | ||
| 4 | |||
| 5 | use WebService::Technorati::ApiQuery; | ||
| 6 | use WebService::Technorati::BlogLink; | ||
| 7 | use WebService::Technorati::Exception; | ||
| 8 | use base 'WebService::Technorati::ApiQuery'; | ||
| 9 | |||
| 10 | use constant API_URI => '/cosmos'; | ||
| 11 | |||
| 12 | BEGIN { | ||
| 13 | use vars qw ($VERSION $DEBUG); | ||
| 14 | $VERSION = 0.04; | ||
| 15 | $DEBUG = 0; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub new { | ||
| 19 | my ($class, %params) = @_; | ||
| 20 | if (! exists $params{'key'}) { | ||
| 21 | WebService::Technorati::InstantiationException->throw( | ||
| 22 | "WebService::Technorati::BloginfoApiQuery must be " . | ||
| 23 | "instantiated with at least 'key => theverylongkeystring'"); | ||
| 24 | } | ||
| 25 | my $data = {}; | ||
| 26 | if (! exists $params{'url'}) { | ||
| 27 | $data->{'needs_url'}++; | ||
| 28 | } | ||
| 29 | for my $k (keys %params) { | ||
| 30 | $data->{'args'}{$k} = $params{$k}; | ||
| 31 | } | ||
| 32 | my $self = bless ($data, ref ($class) || $class); | ||
| 33 | return $self; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub url { | ||
| 37 | my $self = shift; | ||
| 38 | my $url = shift; | ||
| 39 | if ($url) { | ||
| 40 | $self->{'url'} = $url; | ||
| 41 | delete($self->{'needs_url'}); | ||
| 42 | } | ||
| 43 | return $self->{'url'}; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub execute { | ||
| 47 | my $self = shift; | ||
| 48 | my $apiUrl = $self->apiHostUrl() . API_URI; | ||
| 49 | if (exists $self->{'needs_url'}) { | ||
| 50 | WebService::Technorati::StateValidationException->throw( | ||
| 51 | "WebService::Technorati::AuthorinfoApiQuery must have a " . | ||
| 52 | "'url' attribute set prior to query execution"); | ||
| 53 | } | ||
| 54 | $self->SUPER::execute($apiUrl,$self->{'args'}); | ||
| 55 | } | ||
| 56 | |||
| 57 | sub readResults { | ||
| 58 | my $self = shift; | ||
| 59 | my $result_xp = shift; | ||
| 60 | my $error = $result_xp->find('/tapi/document/result/error'); | ||
| 61 | if ($error) { | ||
| 62 | WebService::Technorati::DataException->throw($error); | ||
| 63 | } | ||
| 64 | my $nodeset = $result_xp->find("/tapi/document/result/weblog"); | ||
| 65 | my $node = $nodeset->shift; | ||
| 66 | my $blog = WebService::Technorati::Blog->new_from_node($node); | ||
| 67 | |||
| 68 | $self->{'blog'} = $blog; | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | =head2 getSubjectBlog | ||
| 73 | |||
| 74 | Usage : getSubjectBlog(); | ||
| 75 | Purpose : | ||
| 76 | Returns : a scalar WebService::Technorati::Blog instance | ||
| 77 | Argument : none | ||
| 78 | Throws : none | ||
| 79 | Comments : the URL subject (blog or not) is returned with what | ||
| 80 | Technorati knows about it | ||
| 81 | See Also : WebService::Technorati | ||
| 82 | |||
| 83 | =cut | ||
| 84 | |||
| 85 | sub getSubjectBlog { | ||
| 86 | my $self = shift; | ||
| 87 | return $self->{'blog'}; | ||
| 88 | } | ||
| 89 | |||
| 90 | 1; |