line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Social::Mapper::Persona::Flickr; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2856
|
use strict; |
|
4
|
|
|
|
|
44
|
|
|
4
|
|
|
|
|
184
|
|
4
|
4
|
|
|
4
|
|
24
|
use base qw(Net::Social::Mapper::Persona::Generic); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1446
|
|
5
|
4
|
|
|
4
|
|
32
|
use Feed::Find; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
84
|
|
6
|
4
|
|
|
4
|
|
19
|
use JSON::Any; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
34
|
|
7
|
4
|
|
|
4
|
|
537
|
use URI; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
70
|
|
8
|
4
|
|
|
4
|
|
6306
|
use Data::Dumper; |
|
4
|
|
|
|
|
26602
|
|
|
4
|
|
|
|
|
2642
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $FLICKR_API_KEY = 'efe286838b28127e10271d239dec10bf'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Net::Social::Mapper::Person::Flickr - the persona for a Flickr account |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head2 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
See C |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init { |
23
|
4
|
|
|
4
|
|
11
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Guess at a bunch of stuff |
26
|
4
|
|
|
|
|
37
|
$self = $self->SUPER::_init; |
27
|
|
|
|
|
|
|
|
28
|
4
|
100
|
|
|
|
23
|
if ($self->{user} =~ m!^\d+@.+!) { |
29
|
1
|
|
|
|
|
4
|
$self->{id} = delete $self->{user}; |
30
|
|
|
|
|
|
|
} else { |
31
|
3
|
|
50
|
|
|
14
|
$self->{id} = $self->_fetch_nsid($self->{user}) || return $self; |
32
|
|
|
|
|
|
|
} |
33
|
1
|
|
|
|
|
3
|
for my $format (qw(atom rss_200)) { |
34
|
2
|
|
|
|
|
2
|
push @{$self->{feeds}}, "http://api.flickr.com/services/feeds/photos_public.gne?id=$self->{id}&lang=en-us&format=${format}"; |
|
2
|
|
|
|
|
9
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Now try and get the actual values from flickr |
38
|
1
|
|
50
|
|
|
6
|
my $info = $self->_fetch_userinfo($self->{id}) || return $self; |
39
|
0
|
|
|
|
|
0
|
$self->{full_name} = $info->{realname}->{_content}; |
40
|
0
|
|
|
|
|
0
|
$self->{profile} = $info->{profileurl}->{_content}; |
41
|
0
|
|
|
|
|
0
|
$self->{homepage} = $info->{photosurl}->{_content}; |
42
|
0
|
0
|
|
|
|
0
|
($self->{user}) = ($self->{homepage} =~ m!/([^/]+)/?$!) unless defined $self->{user}; |
43
|
|
|
|
|
|
|
# See http://www.flickr.com/services/api/misc.buddyicons.html |
44
|
0
|
0
|
|
|
|
0
|
if ($info->{iconserver}>0) { |
45
|
0
|
|
|
|
|
0
|
my $farm = $info->{iconfarm}; |
46
|
0
|
|
|
|
|
0
|
my $serv = $info->{iconserver}; |
47
|
0
|
|
|
|
|
0
|
my $id = $self->{id}; |
48
|
0
|
|
|
|
|
0
|
$self->{photo} = "http://farm${farm}.static.flickr.com/${serv}/buddyicons/${id}.jpg" |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _fetch_nsid { |
56
|
3
|
|
|
3
|
|
7
|
my $self = shift; |
57
|
3
|
|
|
|
|
4
|
my $user = shift; |
58
|
3
|
|
50
|
|
|
17
|
my $info = $self->_do_flickr('flickr.urls.lookupUser', url => "http://flickr.com/photos/${user}/") || return; |
59
|
0
|
|
|
|
|
0
|
return $info->{user}->{id}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _fetch_userinfo { |
63
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
64
|
1
|
|
|
|
|
2
|
my $id = shift; |
65
|
1
|
|
33
|
|
|
5
|
my $key = $self->{_flickr_api_key} || $FLICKR_API_KEY; |
66
|
1
|
|
|
|
|
3
|
my $info = $self->_do_flickr('flickr.people.getInfo', user_id => $id ); |
67
|
1
|
|
|
|
|
52
|
return $info->{person}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _do_flickr { |
71
|
4
|
|
|
4
|
|
65
|
my $self = shift; |
72
|
4
|
|
|
|
|
9
|
my $method = shift; |
73
|
4
|
|
|
|
|
14
|
my %params = @_; |
74
|
4
|
|
|
|
|
10
|
$params{method} = $method; |
75
|
4
|
|
33
|
|
|
23
|
$params{api_key} = $self->{_flickr_api_key} || $FLICKR_API_KEY; |
76
|
4
|
|
|
|
|
9
|
$params{format} = 'json'; |
77
|
4
|
|
|
|
|
9
|
$params{nojsoncallback} = 1; |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
38
|
my $url = URI->new("http://www.flickr.com/services/rest/"); |
80
|
4
|
|
|
|
|
9915
|
$url->query_form(%params); |
81
|
4
|
|
50
|
|
|
1098
|
my $page = $self->mapper->get("$url") || return; |
82
|
0
|
|
|
|
|
|
return eval { $self->_json->decode($page) }; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|