Technorati/AuthorinfoApiQuery.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 110 CC 7 SCAR 15.7
CC
7
Cov
0%
new
12.0
username
6.0
execute
6.0
CRAP 4.8
1 package WebService::Technorati::AuthorinfoApiQuery;
2 use strict;
3 use utf8;
4  
5 use WebService::Technorati::ApiQuery;
6 use WebService::Technorati::Author;
7 use WebService::Technorati::Blog;
8 use WebService::Technorati::Exception;
9 use base 'WebService::Technorati::ApiQuery';
10  
11 use constant API_URI => '/getinfo';
12  
13 BEGIN {
14 use vars qw ($VERSION $DEBUG);
15 $VERSION = 0.04;
16 $DEBUG = 0;
17 }
18  
19 sub 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  
37 sub 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  
47 sub 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  
58 sub 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
90 See Also : WebService::Technorati
91  
92 =cut
93  
94 sub 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
109 See Also : WebService::Technorati
110  
111 =cut
112  
113 sub getClaimedBlogs {
114 my $self = shift;
115 return (wantarray) ? @{$self->{'blogs'}} : $self->{'blogs'};
116 }
117  
118 1;