WWW-Phanfare-API
view release on metacpan or search on metacpan
VERSION
Version 0.09
SYNOPSIS
Create agent. Developer API keys required.
use WWW::Phanfare::API;
my $api = WWW::Phanfare::API->new(
api_key => 'xxx',
private_key => 'yyy',
);
Authentication with account:
my $session = $api->Authenticate(
email_address => 'my@email',
password => 'zzz',
)
die "Cannot authenticate: $session->{code_value}"
unless $session->{'stat'} eq 'ok';
my $image = $api->geturl( $url );
DESCRIPTION
Perl wrapper the Phanfare API. A developer API key is required for using
this module.
SUBROUTINES/METHODS
Refer to methods and required parameters are listed on
http://help.phanfare.com/index.php/API .
api_key and private_key is only required for the constructor, not for
individual methods.
Methods return hash references. The value of the 'stat' key will be 'ok'
if the call succeeded. Value of 'code_value' key has error message.
new
Create a new API agent.
geturl
Load data from URL.
lib/WWW/Phanfare/API.pm view on Meta::CPAN
sub AUTOLOAD {
my $self = shift;
croak "$self is not an object" unless ref($self);
my $method = $AUTOLOAD;
$method =~ s/.*://; # strip fully-qualified portion
croak "method not defined" unless $method;
# Verify keys are defined
croak 'api_key not defined' unless $self->{api_key};
croak 'private_key not defined' unless $self->{private_key};
my %param = @_;
# Is POST content included
delete $param{content} if my $content = $param{content};
# Build signature request string
my $req = join '&',
sprintf('%s=%s', 'api_key', $self->{api_key}),
sprintf('%s=%s', 'method', $method),
map { sprintf '%s=%s', $_, (defined $param{$_} ? $param{$_} : '') } keys %param;
# Sign request string
my $sig = md5_hex( $req . $self->{private_key} );
# Build URL escaped request string
$req = join '&',
sprintf('%s=%s', 'api_key', $self->{api_key}),
sprintf('%s=%s', 'method', $method),
map { sprintf '%s=%s', $_, uri_escape( defined $param{$_} ? $param{$_} : '' ) } keys %param;
$req .= sprintf '&%s=%s', 'sig', $sig;
return XML::Simple::XMLin $self->geturl( $site.$req, $content );
}
lib/WWW/Phanfare/API.pm view on Meta::CPAN
# Make sure not caught by AUTOLOAD
sub DESTROY {}
=head1 SYNOPSIS
Create agent. Developer API keys required.
use WWW::Phanfare::API;
my $api = WWW::Phanfare::API->new(
api_key => 'xxx',
private_key => 'yyy',
);
Authentication with account:
my $session = $api->Authenticate(
email_address => 'my@email',
password => 'zzz',
)
die "Cannot authenticate: $session->{code_value}"
unless $session->{'stat'} eq 'ok';
lib/WWW/Phanfare/API.pm view on Meta::CPAN
=head1 DESCRIPTION
Perl wrapper the Phanfare API. A developer API key is required for using
this module.
=head1 SUBROUTINES/METHODS
Refer to methods and required parameters are listed on
http://help.phanfare.com/index.php/API .
api_key and private_key is only required for the constructor,
not for individual methods.
Methods return hash references.
The value of the 'stat' key will be 'ok' if the call succeeded.
Value of 'code_value' key has error message.
=head2 new
Create a new API agent.
# If a .phanfarerc file exist, use it for authentication
# File format:
# api_key xxx
# private_key yyy
# email_address my@email
# password zzz
#
use Test::More;
eval 'use File::HomeDir; use Config::General; use WWW::Phanfare::API';
plan skip_all => "Required modules for album testing not available: $@" if $@;
my $rcfile = File::HomeDir->my_home . "/.phanfarerc";
#unless ( -r $rcfile ) { diag "Cannot read $rcfile"; done_testing; exit; }
plan skip_all => "Cannot read $rcfile" unless -r $rcfile;
my $conf = new_ok( Config::General => [ $rcfile ] );
unless ( $conf ) { diag "Cannot read $rcfile"; done_testing; exit; }
my %config = $conf->getall;
ok( $config{api_key} and $config{private_key} and $config{email_address} and $config{password} );
unless ( $config{api_key} and $config{private_key} and $config{email_address} and $config{password} ) {
diag "Cannot test authentiction without api_key, private_key, email_address and password defined in .phanfarerc";
done_testing;
exit;
}
my $api = new_ok ( 'WWW::Phanfare::API' => [
api_key => $config{api_key},
private_key => $config{private_key},
] );
unless ( $api ) { diag "Cannot create Phanfare agent"; done_testing; exit; }
my $user = $api->Authenticate(
email_address => $config{email_address},
password => $config{password},
);
ok ( $user->{'stat'} eq 'ok', "Could not authenticate" );
unless ( $user->{'stat'} eq 'ok' ) {
diag "Cannot continue without authentication: $user->{code_value}";
# Make sure we have the auth values to perform a test
#
my %config;
eval '
use Config::General;
use File::HomeDir;
use WWW::Phanfare::API;
my $rcfile = File::HomeDir->my_home . "/.phanfarerc";
%config = Config::General->new( $rcfile )->getall;
die unless $config{api_key} and $config{private_key}
and $config{email_address} and $config{password};
';
plan skip_all => "Modules or config not found: $@" if $@;
# Create agent
#
my $api = new_ok ( 'WWW::Phanfare::API' => [
api_key => $config{api_key},
private_key => $config{private_key},
] );
# Login
#
my $session = $api->Authenticate(
email_address => $config{email_address},
password => $config{password},
);
ok ( $session->{'stat'} eq 'ok', 'Authenticate: ' . ( $session->{code_value} || '' ) );
ok ( $session->{session}{uid}, 'Get target_uid: ' . ( $session->{code_value} || '' ) );
( run in 0.252 second using v1.01-cache-2.11-cpan-4d50c553e7e )