[libflickr-api-perl] 07/40: imported 0.06
Lucas Kanashiro
kanashiro-guest at moszumanska.debian.org
Sat Jul 25 21:12:16 UTC 2015
This is an automated email from the git hooks/post-receive script.
kanashiro-guest pushed a commit to tag 1.08
in repository libflickr-api-perl.
commit 2500fa102e95e37b3bbf2384345a71f634a73d41
Author: Cal Henderson <cal at iamcal.com>
Date: Wed Apr 23 05:49:40 2008 +0000
imported 0.06
---
lib/Flickr/API.pm | 19 +++++++++++++++----
test.pl | 16 ++++++++++++++--
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/lib/Flickr/API.pm b/lib/Flickr/API.pm
index 42f9bb3..9c85fd7 100644
--- a/lib/Flickr/API.pm
+++ b/lib/Flickr/API.pm
@@ -10,7 +10,7 @@ use Digest::MD5 qw(md5_hex);
our @ISA = qw(LWP::UserAgent);
-our $VERSION = '0.05';
+our $VERSION = '0.06';
sub new {
my $class = shift;
@@ -18,6 +18,9 @@ sub new {
my $self = new LWP::UserAgent;
$self->{api_key} = $options->{key};
$self->{api_secret} = $options->{secret};
+
+ warn "You must pass an API key to the constructor" unless defined $self->{api_key};
+
bless $self, $class;
return $self;
}
@@ -42,6 +45,8 @@ sub request_auth_url {
my $perms = shift;
my $frob = shift;
+ return undef unless defined $self->{api_secret} && length $self->{api_secret};
+
my %args = (
'api_key' => $self->{api_key},
'perms' => $perms
@@ -73,11 +78,14 @@ sub execute_request {
$request->{api_args}->{method} = $request->{api_method};
$request->{api_args}->{api_key} = $self->{api_key};
- $request->{api_args}->{api_sig} = $self->sign_args($request->{api_args});
+
+ if (defined($self->{api_secret}) && length($self->{api_secret})){
+
+ $request->{api_args}->{api_sig} = $self->sign_args($request->{api_args});
+ }
$request->encode_args();
- #print $request->as_string();
my $response = $self->request($request);
bless $response, 'Flickr::API::Response';
@@ -175,7 +183,8 @@ Constructs a C<Flickr::API::Request> object and executes it, returning a C<Flick
=item C<execute_request($request)>
-Executes a C<Flickr::API::Request> object, returning a C<Flickr::API::Response> object.
+Executes a C<Flickr::API::Request> object, returning a C<Flickr::API::Response> object. Calls are signed
+if a secret was specified when creating the C<Flickr::API> object.
=item C<request_auth_url($perms,$frob)>
@@ -184,6 +193,8 @@ an authentication token.
For web-based applications I<$frob> is an optional parameter.
+Returns undef if a secret was not specified when creating the C<Flickr::API> object.
+
=back
diff --git a/test.pl b/test.pl
index f27aace..500dfda 100644
--- a/test.pl
+++ b/test.pl
@@ -40,9 +40,21 @@ ok('f320caea573c1b74897a289f6919628c' eq $api->sign_args({'foo' => undef}));
# check the auth url generator is working
#
-my $uri = $api->request_auth_url('my_frob', 'r');
+my $uri = $api->request_auth_url('r', 'my_frob');
-ok($uri->query eq 'api_sig=3aa58af8dae8bbf2ac06237032d7de9c&perms=my_frob&frob=r&api_key=made_up_key');
+ok($uri->query eq 'api_sig=d749e3a7bd27da9c8af62a15f4c7b48f&perms=r&frob=my_frob&api_key=made_up_key');
ok($uri->path eq '/services/auth');
ok($uri->host eq 'flickr.com');
ok($uri->scheme eq 'http');
+
+
+##################################################
+#
+# check we can't generate a url without a secret
+#
+
+$api = new Flickr::API({'key' => 'key'});
+$uri = $api->request_auth_url('r', 'frob');
+
+ok(!defined $uri);
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libflickr-api-perl.git
More information about the Pkg-perl-cvs-commits
mailing list