1package WebService::Technorati::AuthorinfoApiQuery;
2use strict;
3use utf8;
4
5use WebService::Technorati::ApiQuery;
6use WebService::Technorati::Author;
7use WebService::Technorati::Blog;
8use WebService::Technorati::Exception;
9use base 'WebService::Technorati::ApiQuery';
10
11use constant API_URI => '/getinfo';
12
13BEGIN {
14    use vars qw ($VERSION $DEBUG);
15    $VERSION    = 0.04;
16    $DEBUG       = 0;
17}
18
19sub new {
20    my ($class, %params) = @_;
21    if (! exists $params{'key'}) {
22        WebService::Technorati::InstantiationException->throw(
23            "WebService::Technorati::AuthorinfoApiQuery must be " .
24            "instantiated with at least 'key => theverylongkeystring'");
25    }
26    my $data = {};
27    if (! exists $params{'username'}) {
28        $data->{'needs_username'}++;
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 username {
38    my $self = shift;
39    my $username = shift;
40    if ($username) {
41        $self->{'username'} = $username;
42        delete($self->{'needs_username'});
43    }
44    return $self->{'username'};
45}
46
47sub execute {
48    my $self = shift;
49    my $apiUrl = $self->apiHostUrl() . API_URI;
50    if (exists $self->{'needs_username'}) {
51        WebService::Technorati::StateValidationException->throw(
52            "WebService::Technorati::AuthorinfoApiQuery must have a " .
53            "'username' 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 $authorSubject = WebService::Technorati::Author->new_from_node($node);
68
69    $nodeset = $result_xp->find('/tapi/document/item/weblog');
70    my @blogs = ();
71    for my $node ($nodeset->get_nodelist) {
72        my $blog = WebService::Technorati::Blog->new_from_node($node);
73        push(@blogs, $blog);
74    }
75    $self->{'subject'} = $authorSubject;
76    $self->{'blogs'} = \@blogs;
77
78}
79
80
81=head2 getSubjectAuthor
82
83 Usage     : getSubjectAuthor();
84 Purpose   :
85 Returns   : a scalar WebService::Technorati::Author instance
86 Argument  : none
87 Throws    : none
88 Comments  : the member entity (author or not) is returned with what
89             Technorati knows about it
90See Also   : WebService::Technorati
91
92=cut
93
94sub getSubjectAuthor {
95    my $self = shift;
96    return $self->{'subject'};
97}
98
99
100=head2 getClaimedBlogs
101
102 Usage     : getClaimedBlogs();
103 Purpose   :
104 Returns   : an array of WebService::Technorati::Blog instances
105 Argument  : none
106 Throws    : none
107 Comments  : the claimed blogs are returned with what Technorati
108             knows about them
109See Also   : WebService::Technorati
110
111=cut
112
113sub getClaimedBlogs {
114    my $self = shift;
115    return (wantarray) ? @{$self->{'blogs'}} : $self->{'blogs'};
116}
117
1181;
119