Net-FS-Flickr

 view release on metacpan or  search on metacpan

lib/Net/FS/Flickr.pm  view on Meta::CPAN

package Net::FS::Flickr;
use Data::Dumper;
use LWP::Simple;
use Acme::Steganography::Image::Png;
use File::Temp qw/tempdir/;
use Cwd qw(cwd);
use Net::FS::Flickr::Access;
use Net::FS::Flickr::DefaultImage;

use strict;
our $VERSION           = "0.1";
our $FILESTORE_VERSION = "0.1"; # this way we can track different revisions of filestore format


=head1 NAME

Net::FS::Flickr - store and retrieve files on Flickr

=head1 SYNOPSIS

    my $fs = Net::FS::Flickr->new( key => $key, secret => $secret );

    $fs->set_auth($auth_key); # see API KEYS AND AUTH KEY section
    $fs->store("file.txt");
    $fs->store("piccy.jpg", "renamed_piccy.jpg");

    open (FILE, ">output.jpg") || die "Couldn't write to file: $!\n";
    binmode (FILE);
    print FILE $fs->retrieve("renamed_piccy.jpg");
    close (FILE);

=head1 API KEYS AND AUTH KEY

You will need to sign up for an API key and then get the corresponding
secret key. You can do that from here

http://www.flickr.com/services/api/key.gne

Finally you will need to get an auth key. As described here 

http://www.flickr.com/services/api/auth.howto.desktop.html

the helper script C<flickrfs> supplied with this distribution can help with that.

=head1 METHODS

=cut

=head2 new

Takes a valid API key and a valid secret key

=cut

sub new {
    my $class = shift;
    my %opts  = @_;
	my $flickr = Net::FS::Flickr::Access->new({ key => $opts{key}, secret => $opts{secret} });
    my $writer = Acme::Steganography::Image::Png::RGB::556FS->new();
    my $self = { _flickr => $flickr, _writer => $writer };
    return bless $self, $class;
}

=head2 files [nsid, email or username]

Get a list of all the files on the system

Given an nsid, username or email, use that. Otherwise use the nsid from 
the auth token.

=cut

sub files {
    my $self = shift;
	my $nsid = shift;
	if (!defined $nsid) {
		$nsid = $self->get_nsid_from_token();
	} else {
		$nsid = $self->{_flickr}->get_nsid($nsid);
	}

    my %files;
	foreach my $s ($self->{_flickr}->list_sets()) {
		next unless $s->{title} =~ m!^FlickrStore v[\d.]+ !;
		$files{$'}++;
	}
	return keys %files;
}

=head2 versions <filename> [nsid, email or username]

Returns a list of all the versions of a file

Each item on the list is a hashref containing the date the file was saved
and the id of that version using the keys I<timestamp> and I<id> respectively.

The list is sorted, latest version first.

Because of the way Flickr stores sets, timestamp will always be 0;

Given an nsid, username or email, use that. Otherwise use the nsid from 
the auth token.

=cut

sub versions {
    my $self = shift;
    my $file = shift;
    my $nsid = shift;
    if (!defined $nsid) {
        $nsid = $self->get_nsid_from_token();
    } else {
        $nsid = $self->{_flickr}->get_nsid($nsid);
    }

    my @versions;
    foreach my $s ($self->{_flickr}->list_sets()) {
        next unless $s->{title} =~ m!^FlickrStore v[\d.]+ $file$!;
		my $id        = $s->{id};



( run in 2.465 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )