Flickr::License - Represents the license of a photo from Flickr


Flickr-License documentation Contained in the Flickr-License distribution.

Index


Code Index:

NAME

Top

Flickr::License - Represents the license of a photo from Flickr

VERSION

Top

Version 0.02

SYNOPSIS

Top

        my $license=Flickr::License->new({api_key=>$APIKEY, id=>$license_number});
        if ($license->valid) {
            my $license_name = $license->name;
            my $license_url = $license->url;
        }

DESCRIPTION

Top

This class retrieves data about the currently available Flickr photo licenses and returns the details that Flickr does based on the license number passed in.

The license number can be obtained easily from the Flickr::Photo object using the ->license() call.

If the license number isn't recognised in the data structure that Flickr returns then the "valid" property of the class is set to 0 and the name is set to "Invalid License"

Behind the scenes it uses a singleton that holds the necessary license date, only refreshing itself if it thinks it needs to.

METHODS

Top

new

Sets up the license object.

my $license=Flickr::License->new({api_key => $APIKEY, id => $license_id});

id is optional and can be set using the ->id() setter/getter -> details of the license are only filled in once id is set.

id

my $id = $license->id; my $different_id = $license->id($a_different_id);

Returns the id. Also sets the id if an argument is passed in - it will always return the new id.

Will also populate the object with license information.

name

Returns the license name

url

Returns the license url

valid

Returns whether the license id was valid. 0=false, 1=true.

AUTHOR

Top

Billy Abbott, <billy@cowfish.org.uk>

COPYRIGHT & LICENSE

Top

SEE ALSO

Top

<http://www.flickr.com/>, Flickr::API, Flickr::Photo


Flickr-License documentation Contained in the Flickr-License distribution.
package Flickr::License;

use Carp;
use Flickr::License::Helper;
use strict;

our $VERSION = '0.02';

sub new {
    my $class = shift;
    my $params = shift;

    if (!exists $params->{api_key}) {
        croak("Can't create a license without an Flick API key")
    }

    my $me = { api_key => $params->{api_key} };
        
    my $self  = bless $me, $class;

    # init the license helper
    my $factory=Flickr::License::Helper->instance($self->{api_key});

    if (exists $params->{id}) {
        $self->{id}=$params->{id};
        $self->_init;
    }

    return $self;
}

#_init
#Function to grab the license information from the Flickr::License::Helper object for this object.
#Will croak if the license id is not set. That shouldn't happen as it is only called when the id is set.

sub _init {
    my $self=shift;

    if (!exists $self->{id}) {
        croak "Cannot get license information without a license id";
    }

    my $number=$self->{id};

    my $factory=Flickr::License::Helper->instance();

    my $licenses=$factory->licenses;
    if (exists $licenses->{$number}) {
        $self->{name}=$licenses->{$number}->{name};
        $self->{url}=$licenses->{$number}->{url};
        $self->{valid}=1;
    } else {
        $self->{name}="Invalid license";        
        $self->{url}="";
        $self->{valid}=0;
    }

}

sub id {
    my $self=shift;
    my $num=shift;
    
    if (defined $num) {
        $self->{id}=$num;
        $self->_init;
    }
    
    return $self->{id};
}

sub name {
    my $self=shift;
    return $self->{name};
}

sub url {
    my $self=shift;
    return $self->{url};
}

sub valid {
    my $self=shift;
    return $self->{valid};
}

1;