Flickr-Upload-Dopplr
view release on metacpan or search on metacpan
lib/Flickr/Upload/Dopplr.pm view on Meta::CPAN
}
sub tagify_like_delicious {
my $self = shift;
my $tag = shift;
$tag =~ s/\s//g;
return lc($tag);
}
sub geonames_id_to_places_id {
my $self = shift;
my $geonames_id = shift;
if (exists($self->{'__places'}->{$geonames_id})){
return $self->{'__places'}->{$geonames_id};
}
# sort out error handling...not that important, really...
my $url = "http://ws.geonames.org/hierarchy?geonameId=" . $geonames_id;
my $gn_xml = get($url);
my $gn_xp = undef;
eval {
$gn_xp = XML::XPath->new('xml' => $gn_xml);
};
if ($@){
warn $@;
return undef;
}
my $locality = ($gn_xp->findnodes("*//geoname[fcode='PPL']"))[0];
my $region = ($gn_xp->findnodes("*//geoname[fcode='ADM1']"))[0];
my $country = ($gn_xp->findnodes("*//geoname[fcode='PCLI']"))[0];
my @parts = ();
foreach my $pl ($locality, $region, $country){
if ($pl){
push @parts, $pl->findvalue("name");
}
}
my $query = join(", ", @parts);
if (! $query){
return undef;
}
my $place_id = undef;
my $place_type = undef;
eval {
my $fl = Flickr::API->new({'key' => $self->{'api_key'}});
my $res = $fl->execute_method('flickr.places.find', {'query' => $query});
my $fl_xml = $res->decoded_content();
my $fl_xp = XML::XPath->new('xml' => $fl_xml);
# Wait to see if any more actual magic is required...
my @places = $fl_xp->findnodes("/rsp/places/place");
my $place = $places[0];
$place_id = $place->getAttribute("place_id");
$place_type = $place->getAttribute("place_type");
};
if ($@){
warn $@;
return undef;
}
$self->{'__places'}->{$geonames_id} = {'id' => $place_id, 'type' => $place_type};
return $self->{'__places'}->{$geonames_id};
}
sub flickr_api_call {
my $self = shift;
my $meth = shift;
my $args = shift;
my $res;
try {
$res = $self->execute_method($meth, $args);
}
catch Error with {
my $e = shift;
throw FlickrAPIException("API call $meth failed", 999, "Unknown API error");
};
if (! $res->{success}){
my $e = shift;
throw FlickrAPIException("API call $meth failed", $e, $res->{error_code}, $res->{error_message});
}
return $res;
}
=head1 VERSION
0.3
=head1 DATE
$Date: 2008/03/13 16:35:15 $
=head1 AUTHOR
Aaron Straup Cope <ascope@cpan.org>
=head1 SEE ALSO
L<Flickr::API>
( run in 2.381 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )