| 1 | package Net::FS::Flickr::Access; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Flickr::Upload; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use base qw(Flickr::Upload); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | Net::FS::Flickr::Access - a sub class of Flickr::Upload with some convenience methods for Net::FS::Flickr | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 METHODS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head2 get_token <frob> | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Given a frob get an auth token back | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub get_token { | ||||||||||||||||||||||||||
|
Subroutine
get_token: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 0 | my $frob = shift; | |||||||||||||||||||||||||||
| 22 | 0 | my $r = $self->execute_method("flickr.auth.getToken", { 'frob' => $frob } ); | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | return undef unless defined $r and $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $r and $r->{"success"}
MC/DC0%0/2
defined $r and $r->{"success"}
defined $r
$r->{"success"}
Truth table0%0/3
A and B
A= defined $rB= $r->{"success"}
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # FIXME: error checking, please. | ||||||||||||||||||||||||||||
| 26 | 0 | return $r->{tree}->{children}->[1]->{children}->[1]->{children}->[0]->{content}; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head2 get_frob | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Get a frob. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub get_frob { | ||||||||||||||||||||||||||
|
Subroutine
get_frob: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $r = $self->execute_method("flickr.auth.getFrob"); | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | return undef unless defined $r and $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $r and $r->{"success"}
MC/DC0%0/2
defined $r and $r->{"success"}
defined $r
$r->{"success"}
Truth table0%0/3
A and B
A= defined $rB= $r->{"success"}
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # FIXME: error checking, please. At least look for the node named 'frob'. | ||||||||||||||||||||||||||||
| 44 | 0 | return $r->{tree}->{children}->[1]->{children}->[0]->{content}; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 get_nsid <name or email> | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Given a name or an email, return a nsid | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub get_nsid { | ||||||||||||||||||||||||||
|
Subroutine
get_nsid: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 57 | 0 | my $nsid; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($name =~ m!\@N\d+$!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $nsid = $name; | |||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||
| 61 | 0 | my $r; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($name =~ m!@!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | $r = $self->execute_method('flickr.people.findByEmail', { find_email => $name }); | |||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 0 | $r = $self->execute_method('flickr.people.findByUserName', { username => $name }); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return unless defined $r && $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $r and $r->{"success"}
MC/DC0%0/2
defined $r and $r->{"success"}
defined $r
$r->{"success"}
Truth table0%0/3
A and B
A= defined $rB= $r->{"success"}
| |||||||||||||||||||||||||||||
| 69 | 0 | for (@{$r->{tree}->{children}}) { | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | next unless defined $_->{name} && $_->{name} eq "user"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_->{"name"} and $_->{"name"} eq "user"
MC/DC0%0/2
defined $_->{"name"} and $_->{"name"} eq "user"
defined $_->{"name"}
$_->{"name"} eq "user"
Truth table0%0/3
A and B
A= defined $_->{"name"}B= $_->{"name"} eq "user"
| |||||||||||||||||||||||||||||
| 71 | 0 | $nsid = $_->{attributes}->{nsid}; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | return $nsid; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head2 get_photo <id> | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Given an id, get some info about a photo | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub get_photo { | ||||||||||||||||||||||||||
|
Subroutine
get_photo: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 0 | my $id = shift; | |||||||||||||||||||||||||||
| 87 | 0 | my $token = $self->{auth}; | |||||||||||||||||||||||||||
| 88 | 0 | my $r = $self->execute_method('flickr.photos.getInfo', { auth_token => $token, photo_id => $id }); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | die "No such photo\n" unless $r && $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$r and $r->{"success"}
MC/DC0%0/2
$r and $r->{"success"}
$r
$r->{"success"}
Truth table0%0/3
A and B
A= $rB= $r->{"success"}
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my ($photo) = grep { defined $_->{name} && $_->{name} eq 'photo' } @{$r->{tree}->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photo'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photo'
defined $_->{'name'}
$_->{'name'} eq 'photo'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photo'
| |||||||||||||||||||||||||||||
| 91 | 0 | return $photo; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head2 get_nsid_from_token [token] | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | Given an auth token (either passed as an argument or via C<set_auth>) return an nsid | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub get_nsid_from_token { | ||||||||||||||||||||||||||
|
Subroutine
get_nsid_from_token: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $token = shift || $self->{auth}; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $self->{'auth'}
MC/DC0%0/2
shift() || $self->{'auth'}
shift()
$self->{'auth'}
Truth table0%0/3
A || B
A= shift()B= $self->{'auth'}
| |||||||||||||||||||||||||||||
| 103 | 0 | my $r = $self->execute_method('flickr.auth.checkToken', { auth_token => $token }); | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | die "No such nsid\n" unless $r && $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$r and $r->{"success"}
MC/DC0%0/2
$r and $r->{"success"}
$r
$r->{"success"}
Truth table0%0/3
A and B
A= $rB= $r->{"success"}
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my ($nsid) = map { $_->{attributes}->{nsid} } | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | grep { defined $_->{name} && $_->{name} eq 'user' } | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'user'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'user'
defined $_->{'name'}
$_->{'name'} eq 'user'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'user'
| |||||||||||||||||||||||||||||
| 108 | 0 | map { @{ $_->{children} } } | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | grep { defined $_->{name} && $_->{name} eq 'auth' } | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'auth'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'auth'
defined $_->{'name'}
$_->{'name'} eq 'auth'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'auth'
| |||||||||||||||||||||||||||||
| 110 | 0 | @{$r->{tree}->{children}}; | |||||||||||||||||||||||||||
| 111 | 0 | return $nsid; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head2 get_photos <nsid> | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Get all the photos from a given nsid | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | ▶ | use constant PER_PAGE => 500; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub get_photos { | ||||||||||||||||||||||||||
|
Subroutine
get_photos: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | 0 | my $nsid = shift; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my $count = $self->get_count($nsid); | |||||||||||||||||||||||||||
| 126 | 0 | ▶ | return () unless $count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $pages = int($count/PER_PAGE) + 1; | |||||||||||||||||||||||||||
| 129 | 0 | my @photos; | |||||||||||||||||||||||||||
| 130 | 0 | for my $page (1..$pages) { | |||||||||||||||||||||||||||
| 131 | # if we try and move get_page into the loop only the first call succeeds | ||||||||||||||||||||||||||||
| 132 | # subsequent ones mutter about invalid signature. I blame scoping. | ||||||||||||||||||||||||||||
| 133 | 0 | my @tmp = $self->get_page($nsid, $page); | |||||||||||||||||||||||||||
| 134 | 0 | push @photos, @tmp; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 0 | return @photos; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub get_page { | ||||||||||||||||||||||||||
|
Subroutine
get_page: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 143 | 0 | my $nsid = shift; | |||||||||||||||||||||||||||
| 144 | 0 | my $page = shift; | |||||||||||||||||||||||||||
| 145 | 0 | my $auth = $self->{auth}; | |||||||||||||||||||||||||||
| 146 | 0 | my $secret = $self->{api_secret}; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | my $params = { extras => 'date_upload', user_id => $nsid, auth_token => $auth, secret => $secret, page => $page, per_page => PER_PAGE }; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | my $r = $self->execute_method('flickr.photos.search', $params); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my @tmp = map { $_->{attributes} } grep { defined $_->{name} && $_->{name} eq 'photo' } | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photo'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photo'
defined $_->{'name'}
$_->{'name'} eq 'photo'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photo'
| |||||||||||||||||||||||||||||
| 153 | 0 | map { @{ $_->{children} } } | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | grep { defined $_->{name} && $_->{name} eq 'photos' } @{$r->{tree}->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photos'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photos'
defined $_->{'name'}
$_->{'name'} eq 'photos'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photos'
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | return @tmp; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head2 get_count <nsid> | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Get the number of photos that an nsid has | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub get_count { | ||||||||||||||||||||||||||
|
Subroutine
get_count: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | 0 | my $nsid = shift; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | my $person = $self->get_person($nsid); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my ($photos) = grep { defined $_->{name} && $_->{name} eq 'photos' } @{$person->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photos'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photos'
defined $_->{'name'}
$_->{'name'} eq 'photos'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photos'
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | my ($count) = grep { defined $_->{name} && $_->{name} eq 'count' } @{$photos->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'count'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'count'
defined $_->{'name'}
$_->{'name'} eq 'count'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'count'
| |||||||||||||||||||||||||||||
| 173 | 0 | return $count->{children}->[0]->{content}; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head2 get_person <nsid> | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | Given a person, get info about them | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub get_person { | ||||||||||||||||||||||||||
|
Subroutine
get_person: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 184 | 0 | my $nsid = shift; | |||||||||||||||||||||||||||
| 185 | 0 | my $r = $self->execute_method('flickr.people.getInfo', { user_id => $nsid, auth_token => $self->{auth} }); | |||||||||||||||||||||||||||
| 186 | 0 | ▶ | return undef unless defined $r && $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $r and $r->{"success"}
MC/DC0%0/2
defined $r and $r->{"success"}
defined $r
$r->{"success"}
Truth table0%0/3
A and B
A= defined $rB= $r->{"success"}
| |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ($person) = grep { defined $_->{name} && $_->{name} eq 'person'} @{$r->{tree}->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'person'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'person'
defined $_->{'name'}
$_->{'name'} eq 'person'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'person'
| |||||||||||||||||||||||||||||
| 188 | 0 | return $person; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =head2 new_set <name> <photo id> | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | Create a new set with the given name and the given photo as the primary | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub new_set { | ||||||||||||||||||||||||||
|
Subroutine
new_set: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 198 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 199 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 200 | 0 | my $pri_id = shift; | |||||||||||||||||||||||||||
| 201 | 0 | my $r = $self->execute_method('flickr.photosets.create', { title => "$name", auth_token => $self->{auth}, primary_photo_id => $pri_id }); | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | die "Couldn't create set" unless defined $r; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | die "Couldn't create set - ".$r->{error_message} unless $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my ($set) = grep { defined $_->{name} && $_->{name} eq 'photoset'} @{$r->{tree}->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photoset'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photoset'
defined $_->{'name'}
$_->{'name'} eq 'photoset'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photoset'
| |||||||||||||||||||||||||||||
| 205 | 0 | return $set->{attributes}->{id}; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =head2 list_sets | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | Return all the sets that the current auth key has | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | Returns a list of hash refs with the id and title as keys. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | sub list_sets { | ||||||||||||||||||||||||||
|
Subroutine
list_sets: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 217 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 218 | 0 | my $r = $self->execute_method('flickr.photosets.getList', { auth_token => $self->{auth} }); | |||||||||||||||||||||||||||
| 219 | 0 | ▶ | die "Couldn't get sets" unless defined $r; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | die "Couldn't get sets - ".$r->{error_message} unless $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | my @sets = grep { defined $_->{name} && $_->{name} eq 'photoset' } | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photoset'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photoset'
defined $_->{'name'}
$_->{'name'} eq 'photoset'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photoset'
| |||||||||||||||||||||||||||||
| 222 | 0 | map { @{$_->{children}} } | |||||||||||||||||||||||||||
| 223 | 0 | ▶ | grep { defined $_->{name} && $_->{name} eq 'photosets'} @{$r->{tree}->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photosets'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photosets'
defined $_->{'name'}
$_->{'name'} eq 'photosets'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photosets'
| |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | my @rets; | |||||||||||||||||||||||||||
| 226 | 0 | foreach my $set (@sets) { | |||||||||||||||||||||||||||
| 227 | 0 | my $id = $set->{attributes}->{id}; | |||||||||||||||||||||||||||
| 228 | 0 | ▶ | my ($t) = grep { defined $_->{name} && $_->{name} eq 'title'} @{$set->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'title'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'title'
defined $_->{'name'}
$_->{'name'} eq 'title'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'title'
| |||||||||||||||||||||||||||||
| 229 | 0 | my $title = $t->{children}->[0]->{content}; | |||||||||||||||||||||||||||
| 230 | 0 | push @rets, { id => $id, title => $title }; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | 0 | return @rets; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =head2 add_to_set <set id> <photo id> | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | Add a photo to a set | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | =cut | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub add_to_set { | ||||||||||||||||||||||||||
|
Subroutine
add_to_set: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 244 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 245 | 0 | my $set = shift; | |||||||||||||||||||||||||||
| 246 | 0 | my $photo = shift; | |||||||||||||||||||||||||||
| 247 | 0 | my $r = $self->execute_method('flickr.photosets.create', { auth_token => $self->{auth}, photoset_id => $set, photo_id => $photo }); | |||||||||||||||||||||||||||
| 248 | 0 | ▶ | die "Couldn't add photo to set" unless defined $r; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | die "Couldn't add photo to set - ".$r->{error_message} unless $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =head2 get_set_photos <set id> | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | Return a list of photos from a set | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | Returns a hashref with the server, secret, id and timestamp as keys | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | =cut | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub get_set_photos { | ||||||||||||||||||||||||||
|
Subroutine
get_set_photos: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 261 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 262 | 0 | my $set = shift; | |||||||||||||||||||||||||||
| 263 | 0 | my $r = $self->execute_method('flickr.photosets.getPhotos', { auth_token => $self->{auth}, photoset_id => $set, extras => 'date_upload' }); | |||||||||||||||||||||||||||
| 264 | 0 | ▶ | die "Couldn't add photo to set" unless defined $r; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | ▶ | die "Couldn't add photo to set - ".$r->{error_message} unless $r->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my @photos = grep { defined $_->{name} && $_->{name} eq 'photo' } map { @{$_->{children}} } | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photo'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photo'
defined $_->{'name'}
$_->{'name'} eq 'photo'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photo'
| |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | grep { defined $_->{name} && $_->{name} eq 'photoset' } @{$r->{tree}->{children}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'photoset'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'photoset'
defined $_->{'name'}
$_->{'name'} eq 'photoset'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'photoset'
| |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | my @ret; | |||||||||||||||||||||||||||
| 270 | 0 | foreach my $p (@photos) { | |||||||||||||||||||||||||||
| 271 | 0 | $p = $p->{attributes}; | |||||||||||||||||||||||||||
| 272 | 0 | my $timestamp = scalar(localtime($p->{dateupload})); | |||||||||||||||||||||||||||
| 273 | 0 | push @ret, { server => $p->{server}, secret => $p->{secret}, id => $p->{id}, timestamp => $timestamp }; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | 0 | return sort { $b->{timestamp} <=> $a->{timestamp} } @ret; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | Simon Wistow <simon@thegestalt.org> | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | Copyright 2006, Simon Wistow | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =cut | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 1 | 1; | |||||||||||||||||||||||||||