line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pikeo::API::User; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2251
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use base qw( Pikeo::API::Base ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
157
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
80
|
|
9
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
10
|
1
|
|
|
1
|
|
599
|
use Pikeo::API::Album; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3405
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Pikeo::API::User - Abstraction of a pikeo user/person |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
|
|
sub _info_fields { qw( username profile_url avatar_url location ) } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Pikeo::API; |
23
|
|
|
|
|
|
|
use Pikeo::API::User; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# create an API object to maintain you session |
26
|
|
|
|
|
|
|
# trough out the diferent calls |
27
|
|
|
|
|
|
|
my $api = Pikeo::API->new({api_secret=>'asd', api_key=>'asdas'}); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Get a user by id... |
30
|
|
|
|
|
|
|
my $user1 = Pikeo::API::User->new({ api => $api, id=>1 }); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# .. or get a user by username |
33
|
|
|
|
|
|
|
my $user2 = Pikeo::API::User->new({ api => $api, username=>'foo' }); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#get the public photos |
36
|
|
|
|
|
|
|
my $photos = $user2->getPublicPhotos(); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 FUNCTIONS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 CONSTRUCTORS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head3 new( \%args ) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Returns a Pikeo::API::User object. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Required args are: |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over 4 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item * api |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Pikeo::API object |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item * username or id |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Id or username of the user. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new { |
61
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
62
|
0
|
|
|
|
|
|
my $params = shift; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($params); |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ( $params->{id} ) { |
|
|
0
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->{id} = $params->{id}; |
68
|
0
|
|
|
|
|
|
$self->{_init} = 0; |
69
|
0
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif ($params->{username}){ |
72
|
0
|
|
|
|
|
|
my $doc = $self->api->request_parsed('pikeo.people.findByUsername', |
73
|
|
|
|
|
|
|
{ username => $params->{username} } |
74
|
|
|
|
|
|
|
); |
75
|
0
|
|
0
|
|
|
|
$self->{id} = $doc->findvalue("//value") || croak "unkown user"; |
76
|
0
|
|
|
|
|
|
$self->{_init} = 0; |
77
|
0
|
|
|
|
|
|
return $self; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
croak "Need an id or a username"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=back |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 INSTANCE METHODS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head3 getPublicPhotos(\%args) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Return a list of Pikeo::API::Photo owned by the user |
91
|
|
|
|
|
|
|
and marked as public. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub getPublicPhotos { |
96
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
my $params = shift; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $req_params = { |
100
|
|
|
|
|
|
|
user_id => $self->id, |
101
|
|
|
|
|
|
|
}; |
102
|
0
|
0
|
|
|
|
|
if ( $params->{'num_items'} ) { |
103
|
0
|
|
|
|
|
|
$req_params->{'num_items'} = $params->{'num_items'}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $doc = $self->api->request_parsed( 'pikeo.people.getPublicPhotos', $req_params ); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $self->_photos_from_xml({ xml => [$doc->findnodes('//photo')] }); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head3 getContactsPublicPhotos(\%args) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Return a list of Pikeo::API::Photo owned by contacts |
114
|
|
|
|
|
|
|
of the user and marked as public |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub getContactsPublicPhotos { |
119
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
120
|
0
|
|
|
|
|
|
my $params = shift; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $req_params = { |
123
|
|
|
|
|
|
|
user_id => $self->id, |
124
|
|
|
|
|
|
|
}; |
125
|
0
|
0
|
|
|
|
|
if ( $params->{'num_items'} ) { |
126
|
0
|
|
|
|
|
|
$req_params->{'num_items'} = $params->{'num_items'}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my $doc = $self->api->request_parsed( 'pikeo.photos.getContactsPublicPhotos', $req_params ); |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $self->_photos_from_xml({ xml => [$doc->findnodes('//photo')] }); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head3 getUserPhotos(\%args) |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Return a list of Pikeo::API::Photo containing all the |
138
|
|
|
|
|
|
|
photos of the user. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
sub getUserPhotos { |
142
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
143
|
0
|
|
|
|
|
|
my $params = shift; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my $req_params = { |
146
|
|
|
|
|
|
|
user_id => $self->id, |
147
|
|
|
|
|
|
|
}; |
148
|
0
|
0
|
|
|
|
|
if ( $params->{'num_items'} ) { |
149
|
0
|
|
|
|
|
|
$req_params->{'num_items'} = $params->{'num_items'}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $doc = $self->api->request_parsed( 'pikeo.photos.getUserPhotos', $req_params ); |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
return $self->_photos_from_xml({ xml => [$doc->findnodes('//photo')] }); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head3 getAlbumsList() |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Return a list of Pikeo::API::Album owned by the user |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
sub getAlbumsList { |
163
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
164
|
0
|
|
|
|
|
|
my $params = {}; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $albums = $self->api->request_parsed( 'pikeo.people.getInfo', |
167
|
|
|
|
|
|
|
{ |
168
|
|
|
|
|
|
|
'user_id' => $self->id, |
169
|
|
|
|
|
|
|
} ); |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
my @a = (); |
172
|
0
|
|
|
|
|
|
for my $album_xml ( @{$albums->findnodes("//album")} ) { |
|
0
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
push @a, Pikeo::API::Album->new({ api=>$self->api, |
174
|
|
|
|
|
|
|
from_xml => $album_xml }); |
175
|
|
|
|
|
|
|
} |
176
|
0
|
|
|
|
|
|
return \@a; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head3 username() |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns the user username |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head3 profile_url() |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Returns the user profile url |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head3 avatar_url() |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Returns the user avatar url |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head3 location() |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Returns the user location |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head3 id() |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Returns the user id |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
0
|
1
|
|
sub id { return shift->{id} } |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub _init { |
205
|
0
|
|
|
0
|
|
|
my $self = shift; |
206
|
0
|
|
|
|
|
|
my $doc = $self->api->request_parsed( 'pikeo.people.getInfo', { |
207
|
|
|
|
|
|
|
'user_id' => $self->id, |
208
|
|
|
|
|
|
|
} ); |
209
|
0
|
|
|
|
|
|
$self->_init_from_xml( [$doc->findnodes("response/person/*")] ); |
210
|
0
|
|
|
|
|
|
$self->{_init} = 1; |
211
|
0
|
|
|
|
|
|
$self->{_dirty} = 0; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub _init_from_xml { |
215
|
0
|
|
|
0
|
|
|
my $self = shift; |
216
|
0
|
|
|
|
|
|
my $nodes = shift; |
217
|
0
|
|
|
|
|
|
for ( @$nodes ) { |
218
|
0
|
0
|
|
|
|
|
$self->{$_->nodeName} = ( $_->to_literal eq 'null' ? undef : $_->to_literal ); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
1; |