blib/lib/Flickr/API.pm

filter: Statementstmt 53.5% 225 / 420 Branchbran 40.3% 54 / 134 Conditioncond 43.9% 40 / 91 MC/DCmcdc 19.6% 10 / 51 Subroutinesub 76.9% 30 / 39 Podpod 72.2% 13 / 18 totaltotal 49.4% 372 / 753 CC 105 SCAR 34.3
CC
105
Cov
49%
upload
90.0
oauth_request_token
56.0
new
53.6
CRAP 30.9
« blib/lib/Flickr/API/Upload.pm ↑ Summary blib/lib/Flickr/API/Reflection.pm »
1 package Flickr::API;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use XML::Parser::Lite::Tree;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use XML::LibXML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Flickr::API::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Flickr::API::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Net::OAuth;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Encode qw(encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use Storable qw(store_fd retrieve_fd);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 our @ISA = qw(LWP::UserAgent);
18  
19 15 our $VERSION = '1.29';
20  
21 8 ▶sub new {
Subroutine new: called CC=32 SCAR=39.8
Pod documented
22 8 my ($class, $args) = @_;
23  
24 8 my $self;
25 8 ▶ if ($args->{lwpobj}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"lwpobj"}) 0 8 8
26 0 my $lwpobj = $args->{lwpobj};
27 0 ▶ if (defined($lwpobj)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lwpobj) 0 0 0
28 0 my $lwpobjtype = Scalar::Util::blessed($lwpobj);
29 0 ▶ if (defined($lwpobjtype)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lwpobjtype) 0 0 0
30 0 $self = $lwpobj;
31 0 @ISA = ($lwpobjtype);
32 }
33 }
34 }
35 8 ▶ $self = LWP::UserAgent->new unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 8 0 8
36  
37 #
38 # If the args have consumer_key, handle as oauth
39 #
40 8 ▶ if (defined($args->{consumer_key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'consumer_key'}) { } 4 4 8
41  
42 4 $self->{api_type} = 'oauth';
43 4 ▶ $self->{rest_uri} = $args->{rest_uri} || 'https://api.flickr.com/services/rest/';
Condition50%1/2
$args->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
l!l
04
MC/DC0%0/1
$args->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
$args->{'rest_uri'}
Truth table50%1/2
A
A= $args->{'rest_uri'}
Aresult
11
00
44 4 ▶ $self->{auth_uri} = $args->{auth_uri} || 'https://api.flickr.com/services/oauth/authorize';
Condition50%1/2
$args->{'auth_uri'} || 'https://api.flickr.com/services/oauth/authorize'
l!l
04
MC/DC0%0/1
$args->{'auth_uri'} || 'https://api.flickr.com/services/oauth/authorize'
$args->{'auth_uri'}
Truth table50%1/2
A
A= $args->{'auth_uri'}
Aresult
11
00
45 4 ▶ $self->{upload_uri} = $args->{upload_uri} || 'https://api.flickr.com/services/upload/';
Condition50%1/2
$args->{'upload_uri'} || 'https://api.flickr.com/services/upload/'
l!l
04
MC/DC0%0/1
$args->{'upload_uri'} || 'https://api.flickr.com/services/upload/'
$args->{'upload_uri'}
Truth table50%1/2
A
A= $args->{'upload_uri'}
Aresult
11
00
46  
47 4 ▶ if (defined($args->{consumer_secret})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'consumer_secret'}) { } 4 0 4
48  
49 #
50 # for the flickr api object
51 #
52 4 $self->{oauth_request} = 'consumer';
53 4 $self->{consumer_key} = $args->{consumer_key};
54 4 $self->{consumer_secret} = $args->{consumer_secret};
55 4 ▶ $self->{unicode} = $args->{unicode} || 0;
Condition50%1/2
$args->{'unicode'} || 0
l!l
04
MC/DC0%0/1
$args->{'unicode'} || 0
$args->{'unicode'}
Truth table50%1/2
A
A= $args->{'unicode'}
Aresult
11
00
56 #
57 # for Net::OAuth Consumer Requests
58 #
59 4 ▶ $self->{oauth}->{request_method} = $args->{request_method} || 'GET';
Condition100%2/2
$args->{'request_method'} || 'GET'
l!l
13
MC/DC100%1/1
$args->{'request_method'} || 'GET'
$args->{'request_method'}
Truth table100%2/2
A
A= $args->{'request_method'}
Aresult
11
00
60 4 $self->{oauth}->{request_url} = $self->{rest_uri};
61 4 $self->{oauth}->{consumer_secret} = $args->{consumer_secret};
62 4 $self->{oauth}->{consumer_key} = $args->{consumer_key};
63 4 ▶ $self->{oauth}->{nonce} = $args->{nonce} || _make_nonce();
Condition66%2/3
$args->{'nonce'} || _make_nonce()
l!l&&r!l&&!r
130
MC/DC0%0/2
$args->{'nonce'} || _make_nonce()
$args->{'nonce'} _make_nonce()
Truth table66%2/3
A || B
A= $args->{'nonce'}B= _make_nonce()
ABresult
1X1
011
000
64 4 ▶ $self->{oauth}->{signature_method} = $args->{signature_method} ||'HMAC-SHA1';
Condition100%2/2
$args->{'signature_method'} || 'HMAC-SHA1'
l!l
13
MC/DC100%1/1
$args->{'signature_method'} || 'HMAC-SHA1'
$args->{'signature_method'}
Truth table100%2/2
A
A= $args->{'signature_method'}
Aresult
11
00
65 4 ▶ $self->{oauth}->{timestamp} = $args->{timestamp} || time;
Condition100%2/2
$args->{'timestamp'} || time
l!l
13
MC/DC100%1/1
$args->{'timestamp'} || time
$args->{'timestamp'}
Truth table100%2/2
A
A= $args->{'timestamp'}
Aresult
11
00
66 4 $self->{oauth}->{version} = '1.0';
67 4 $self->{oauth}->{callback} = $args->{callback};
68  
69 }
70 else {
71  
72 0 carp "OAuth calls must have at least a consumer_key and a consumer_secret";
73 0 $self->_set_status(0,"OAuth call without consumer_secret");
74  
75 }
76  
77 4 ▶ if (defined($args->{token}) && defined($args->{token_secret})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"token"} and defined $args->{"token_secret"}) 2 2 4
Condition66%2/3
defined $args->{"token"} and defined $args->{"token_secret"}
!ll&&!rl&&r
202
MC/DC50%1/2
defined $args->{"token"} and defined $args->{"token_secret"}
defined $args->{"token"} defined $args->{"token_secret"}
Truth table66%2/3
A and B
A= defined $args->{"token"}B= defined $args->{"token_secret"}
ABresult
0X0
100
111
78  
79 #
80 # If we have token/token secret then we are for protected resources
81 #
82 2 $self->{oauth}->{token_secret} = $args->{token_secret};
83 2 $self->{oauth}->{token} = $args->{token};
84 2 $self->{oauth_request} = 'protected resource';
85  
86 }
87  
88 #
89 # Preserve request and access tokens
90 #
91 4 ▶ if (defined($args->{request_token}) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"request_token"} and ref $args->{"request_token"} eq "Net::OAuth::V1_0A::RequestTokenResponse") 0 4 4
Condition33%1/3
defined $args->{"request_token"} and ref $args->{"request_token"} eq "Net::OAuth::V1_0A::RequestTokenResponse"
!ll&&!rl&&r
400
MC/DC0%0/2
defined $args->{"request_token"} and ref $args->{"request_token"} eq "Net::OAuth::V1_0A::RequestTokenResponse"
defined $args->{"request_token"} ref $args->{"request_token"} eq "Net::OAuth::V1_0A::RequestTokenResponse"
Truth table33%1/3
A and B
A= defined $args->{"request_token"}B= ref $args->{"request_token"} eq "Net::OAuth::V1_0A::RequestTokenResponse"
ABresult
0X0
100
111
92 ref($args->{request_token}) eq 'Net::OAuth::V1_0A::RequestTokenResponse') {
93  
94 0 $self->{oauth}->{request_token} = $args->{request_token};
95  
96 }
97 4 ▶ if (defined($args->{access_token}) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"access_token"} and ref $args->{"access_token"} eq "Net::OAuth::AccessTokenResponse") 0 4 4
Condition33%1/3
defined $args->{"access_token"} and ref $args->{"access_token"} eq "Net::OAuth::AccessTokenResponse"
!ll&&!rl&&r
400
MC/DC0%0/2
defined $args->{"access_token"} and ref $args->{"access_token"} eq "Net::OAuth::AccessTokenResponse"
defined $args->{"access_token"} ref $args->{"access_token"} eq "Net::OAuth::AccessTokenResponse"
Truth table33%1/3
A and B
A= defined $args->{"access_token"}B= ref $args->{"access_token"} eq "Net::OAuth::AccessTokenResponse"
ABresult
0X0
100
111
98 ref($args->{access_token}) eq 'Net::OAuth::AccessTokenResponse') {
99  
100 0 $self->{oauth}->{access_token} = $args->{access_token};
101  
102 }
103 }
104  
105 else {
106  
107 4 $self->{api_type} = 'flickr';
108 4 ▶ $self->{api_key} = $args->{api_key} || $args->{key};
Condition66%2/3
$args->{'api_key'} || $args->{'key'}
l!l&&r!l&&!r
130
MC/DC0%0/2
$args->{'api_key'} || $args->{'key'}
$args->{'api_key'} $args->{'key'}
Truth table66%2/3
A || B
A= $args->{'api_key'}B= $args->{'key'}
ABresult
1X1
011
000
109 4 ▶ $self->{api_secret} = $args->{api_secret} || $args->{secret};
Condition100%3/3
$args->{'api_secret'} || $args->{'secret'}
l!l&&r!l&&!r
211
MC/DC100%2/2
$args->{'api_secret'} || $args->{'secret'}
$args->{'api_secret'} $args->{'secret'}
Truth table100%3/3
A || B
A= $args->{'api_secret'}B= $args->{'secret'}
ABresult
1X1
011
000
110 4 ▶ $self->{rest_uri} = $args->{rest_uri} || 'https://api.flickr.com/services/rest/';
Condition50%1/2
$args->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
l!l
04
MC/DC0%0/1
$args->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
$args->{'rest_uri'}
Truth table50%1/2
A
A= $args->{'rest_uri'}
Aresult
11
00
111 4 ▶ $self->{auth_uri} = $args->{auth_uri} || 'https://api.flickr.com/services/auth/';
Condition50%1/2
$args->{'auth_uri'} || 'https://api.flickr.com/services/auth/'
l!l
04
MC/DC0%0/1
$args->{'auth_uri'} || 'https://api.flickr.com/services/auth/'
$args->{'auth_uri'}
Truth table50%1/2
A
A= $args->{'auth_uri'}
Aresult
11
00
112 4 ▶ $self->{upload_uri} = $args->{upload_uri} || 'https://api.flickr.com/services/upload/';
Condition50%1/2
$args->{'upload_uri'} || 'https://api.flickr.com/services/upload/'
l!l
04
MC/DC0%0/1
$args->{'upload_uri'} || 'https://api.flickr.com/services/upload/'
$args->{'upload_uri'}
Truth table50%1/2
A
A= $args->{'upload_uri'}
Aresult
11
00
113 4 ▶ $self->{unicode} = $args->{unicode} || 0;
Condition50%1/2
$args->{'unicode'} || 0
l!l
04
MC/DC0%0/1
$args->{'unicode'} || 0
$args->{'unicode'}
Truth table50%1/2
A
A= $args->{'unicode'}
Aresult
11
00
114  
115 4 ▶ if (defined($args->{key}) or defined ($self->{key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"key"} or defined $self->{"key"}) 3 1 4
Condition66%2/3
defined $args->{"key"} or defined $self->{"key"}
l!l&&r!l&&!r
301
MC/DC50%1/2
defined $args->{"key"} or defined $self->{"key"}
defined $args->{"key"} defined $self->{"key"}
Truth table66%2/3
A or B
A= defined $args->{"key"}B= defined $self->{"key"}
ABresult
1X1
011
000
116 3 delete $args->{key};
117 3 delete $self->{key};
118 # Silenty switch key to api_key until a later release
119 # carp "Argument 'key' is deprecated and has been changed to api_key";
120 }
121  
122 4 ▶ if (defined ($args->{secret}) or defined ($self->{secret})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"secret"} or defined $self->{"secret"}) 1 3 4
Condition66%2/3
defined $args->{"secret"} or defined $self->{"secret"}
l!l&&r!l&&!r
103
MC/DC50%1/2
defined $args->{"secret"} or defined $self->{"secret"}
defined $args->{"secret"} defined $self->{"secret"}
Truth table66%2/3
A or B
A= defined $args->{"secret"}B= defined $self->{"secret"}
ABresult
1X1
011
000
123 1 delete $args->{secret};
124 1 delete $self->{secret};
125 # Silenty switch secret to api_secret until a later release
126 # carp "Argument 'secret' is deprecated and has been changed to api_secret";
127 }
128  
129 4 $self->{fauth}->{frob} = $args->{frob};
130 4 $self->{fauth}->{api_key} = $self->{api_key};
131 4 $self->{fauth}->{api_secret} = $self->{api_secret};
132 4 $self->{fauth}->{token} = $args->{token};
133  
134 4 ▶ carp "You must pass an API key or a Consumer key to the constructor" unless defined $self->{api_key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"api_key"} 0 4 4
135  
136 }
137  
138 8 eval {
139 8 require Compress::Zlib;
140  
141 8 $self->default_header('Accept-Encoding' => 'gzip');
142 };
143  
144 8 bless $self, $class;
145 8 $self->_clear_status();
146 8 $self->_initialize();
147 8 return $self;
148 }
149  
150  
151  
152 #
153 # Execution Methods
154 #
155  
156 2 ▶sub execute_method {
Subroutine execute_method: called CC=7 SCAR=36.1
Pod documented
157 2 my ($self, $method, $args) = @_;
158 2 my $request;
159  
160 2 ▶ if ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_oauth) { } 0 2 2
161  
162 #
163 # Consumer Request Params
164 #
165 0 my $oauth = {};
166  
167 0 $oauth->{nonce} = _make_nonce();
168 0 $oauth->{consumer_key} = $self->{oauth}->{consumer_key};
169 0 $oauth->{consumer_secret} = $self->{oauth}->{consumer_secret};
170 0 $oauth->{timestamp} = time;
171 0 $oauth->{signature_method} = $self->{oauth}->{signature_method};
172 0 $oauth->{version} = $self->{oauth}->{version};
173  
174 0 ▶ if (defined($args->{'token'}) or defined($args->{'token_secret'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"token"} or defined $args->{"token_secret"}) 0 0 0
Condition0%0/3
defined $args->{"token"} or defined $args->{"token_secret"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $args->{"token"} or defined $args->{"token_secret"}
defined $args->{"token"} defined $args->{"token_secret"}
Truth table0%0/3
A or B
A= defined $args->{"token"}B= defined $args->{"token_secret"}
ABresult
1X1
011
000
175  
176 0 carp "\ntoken and token_secret must be specified in Flickr::API->new() and are being discarded\n";
177 0 undef $args->{'token'};
178 0 undef $args->{'token_secret'};
179 }
180  
181 0 ▶ if (defined($args->{'consumer_key'}) or defined($args->{'consumer_secret'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"consumer_key"} or defined $args->{"consumer_secret"}) 0 0 0
Condition0%0/3
defined $args->{"consumer_key"} or defined $args->{"consumer_secret"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $args->{"consumer_key"} or defined $args->{"consumer_secret"}
defined $args->{"consumer_key"} defined $args->{"consumer_secret"}
Truth table0%0/3
A or B
A= defined $args->{"consumer_key"}B= defined $args->{"consumer_secret"}
ABresult
1X1
011
000
182  
183 0 carp "\nconsumer_key and consumer_secret must be specified in Flickr::API->new() and are being discarded\n";
184 0 undef $args->{'consumer_key'};
185 0 undef $args->{'consumer_secret'};
186 }
187  
188  
189 0 $oauth->{extra_params} = $args;
190 0 $oauth->{extra_params}->{method} = $method;
191  
192 #
193 # Protected resource params
194 #
195 0 ▶ if (defined($self->{oauth}->{token})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"oauth"}{"token"}) 0 0 0
196  
197 0 $oauth->{token} = $self->{oauth}->{token};
198 0 $oauth->{token_secret} = $self->{oauth}->{token_secret};
199  
200 }
201  
202 $request = Flickr::API::Request->new({
203 'api_type' => 'oauth',
204 'method' => $method,
205 'args' => $oauth,
206 'rest_uri' => $self->{rest_uri},
207 'unicode' => $self->{unicode},
208 0 });
209 }
210 else {
211  
212 $request = Flickr::API::Request->new({
213 'api_type' => 'flickr',
214 'method' => $method,
215 'args' => $args,
216 'rest_uri' => $self->{rest_uri},
217 'unicode' => $self->{unicode},
218 2 });
219 }
220  
221 2 return $self->execute_request($request);
222  
223 }
224  
225 2 ▶sub execute_request {
Subroutine execute_request: called CC=12 SCAR=30.4
Pod documented
226 2 my ($self, $request) = @_;
227  
228 2 $request->{api_args}->{method} = $request->{api_method};
229  
230 2 ▶ unless ($self->is_oauth) { $request->{api_args}->{api_key} = $self->{api_key}; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_oauth) 2 0 2
231  
232 2 ▶ if (defined($self->{api_secret}) && length($self->{api_secret})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"api_secret"} and length $self->{"api_secret"}) 2 0 2
Condition33%1/3
defined $self->{"api_secret"} and length $self->{"api_secret"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->{"api_secret"} and length $self->{"api_secret"}
defined $self->{"api_secret"} length $self->{"api_secret"}
Truth table33%1/3
A and B
A= defined $self->{"api_secret"}B= length $self->{"api_secret"}
ABresult
0X0
100
111
233  
234 2 ▶ unless ($self->is_oauth) { $request->{api_args}->{api_sig} = $self->_sign_args($request->{api_args}); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_oauth) 2 0 2
235  
236 }
237  
238 2 ▶ unless ($self->is_oauth) { $request->encode_args(); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_oauth) 2 0 2
239  
240 2 my $response = $self->request($request);
241 2 bless $response, 'Flickr::API::Response';
242  
243 2 $response->init_flickr();
244  
245 2 ▶ if ($response->{_rc} != 200){
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"_rc"} != 200) 0 2 2
246 0 $response->set_fail(0, "API returned a non-200 status code ($response->{_rc})");
247 0 return $response;
248 }
249  
250 2 my $content = $response->decoded_content();
251 2 ▶ $content = $response->content() unless defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 2 2
252  
253 2 my $xls = XML::LibXML::Simple->new(ForceArray => 0);
254 2 my $tree = XML::Parser::Lite::Tree::instance()->parse($content);
255  
256 2 my $hashref = $xls->XMLin($content,KeyAttr => []);
257  
258 2 my $rsp_node = $self->_find_tag($tree->{children});
259  
260 2 ▶ if ($rsp_node->{name} ne 'rsp'){
Branch: 1 branch
BranchTrueFalseTotal
if ($rsp_node->{"name"} ne "rsp") 0 2 2
261 0 $response->set_fail(0, "API returned an invalid response");
262 0 return $response;
263 }
264  
265 2 ▶ if ($rsp_node->{attributes}->{stat} eq 'fail'){
Branch: 1 branch
BranchTrueFalseTotal
if ($rsp_node->{"attributes"}{"stat"} eq "fail") 2 0 2
266 2 my $fail_node = $self->_find_tag($rsp_node->{children});
267 2 ▶ if ($fail_node->{name} eq 'err'){
Branch: 1 branch
BranchTrueFalseTotal
if ($fail_node->{'name'} eq 'err') { } 2 0 2
268 2 $response->set_fail($fail_node->{attributes}->{code}, $fail_node->{attributes}->{msg});
269 }
270 else {
271 0 $response->set_fail(0, "Method failed but returned no error code");
272 }
273 2 return $response;
274 }
275  
276 0 ▶ if ($rsp_node->{attributes}->{stat} eq 'ok'){
Branch: 1 branch
BranchTrueFalseTotal
if ($rsp_node->{"attributes"}{"stat"} eq "ok") 0 0 0
277 0 $response->set_ok($rsp_node,$hashref);
278 0 return $response;
279 }
280  
281 0 $response->set_fail(0, "API returned an invalid status code");
282 0 return $response;
283 }
284  
285  
286  
287 0 ▶sub upload {
Subroutine upload: not called CC=9 SCAR=45.0
Pod undocumented
288 0 my ($self, $args) = @_;
289 0 my $upload;
290  
291 0 ▶ unless ($self->api_permissions() eq 'write' || $self->api_permissions() eq 'delete') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->api_permissions eq "write" or $self->api_permissions eq "delete") 0 0 0
Condition0%0/3
$self->api_permissions eq "write" or $self->api_permissions eq "delete"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->api_permissions eq "write" or $self->api_permissions eq "delete"
$self->api_permissions eq "write" $self->api_permissions eq "delete"
Truth table0%0/3
A or B
A= $self->api_permissions eq "write"B= $self->api_permissions eq "delete"
ABresult
1X1
011
000
292 0 croak "insufficient permission for upload";
293 }
294  
295 0 my %cfg = $self->export_config;
296 0 $cfg{'request_url'} = $self->{upload_uri};
297  
298 0 $upload = Flickr::API::Upload->new({
299 'photo' => $args,
300 'api' => \%cfg,
301 'api_type' => $self->api_type(),
302 });
303  
304 0 my $response = $self->request($upload);
305 0 bless $response, 'Flickr::API::Response';
306  
307 0 $response->init_flickr();
308  
309 0 ▶ if ($response->{_rc} != 200){
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"_rc"} != 200) 0 0 0
310 0 $response->set_fail(0, "Upload returned a non-200 status code ($response->{_rc})");
311 0 return $response;
312 }
313  
314 0 my $content = $response->decoded_content();
315 0 ▶ $content = $response->content() unless defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 0 0
316  
317 0 my $xls = XML::LibXML::Simple->new(ForceArray => 0);
318 0 my $tree = XML::Parser::Lite::Tree::instance()->parse($content);
319  
320 0 my $hashref = $xls->XMLin($content,KeyAttr => []);
321  
322 0 my $rsp_node = $self->_find_tag($tree->{children});
323  
324 0 ▶ if ($rsp_node->{name} ne 'rsp'){
Branch: 1 branch
BranchTrueFalseTotal
if ($rsp_node->{"name"} ne "rsp") 0 0 0
325 0 $response->set_fail(0, "Upload returned an invalid response");
326 0 return $response;
327 }
328  
329 0 ▶ if ($rsp_node->{attributes}->{stat} eq 'fail'){
Branch: 1 branch
BranchTrueFalseTotal
if ($rsp_node->{"attributes"}{"stat"} eq "fail") 0 0 0
330 0 my $fail_node = $self->_find_tag($rsp_node->{children});
331 0 ▶ if ($fail_node->{name} eq 'err'){
Branch: 1 branch
BranchTrueFalseTotal
if ($fail_node->{'name'} eq 'err') { } 0 0 0
332 0 $response->set_fail($fail_node->{attributes}->{code}, $fail_node->{attributes}->{msg});
333 }
334 else {
335 0 $response->set_fail(0, "Upload failed but returned no error code");
336 }
337 0 return $response;
338 }
339  
340 0 ▶ if ($rsp_node->{attributes}->{stat} eq 'ok'){
Branch: 1 branch
BranchTrueFalseTotal
if ($rsp_node->{"attributes"}{"stat"} eq "ok") 0 0 0
341 0 $response->set_ok($rsp_node,$hashref);
342 0 return $response;
343 }
344  
345 0 $response->set_fail(0, "API returned an invalid status code");
346  
347 0 return $response;
348  
349 }
350  
351 #
352 # Persistent config methods
353 #
354  
355  
356 #
357 # Method to return hash of important Flickr or OAuth parameters.
358 # OAuth can also export meaningful subsets of parameters based
359 # on OAuth message type.
360 #
361 7 ▶sub export_config {
Subroutine export_config: called CC=8 SCAR=20.9
Pod documented
362 7 my ($self, $type, $params) = @_;
363  
364 7 ▶ if ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_oauth) { } 5 2 7
365  
366 5 ▶ unless($params) { $params='do_it'; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($params) 1 4 5
367  
368 5 my %oauth;
369  
370 5 ▶ if (defined($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) { } 4 1 5
371 4 ▶ if ($params =~ m/^m.*/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($params =~ /^m.*/i) { } 2 2 4
elsif ($params =~ /^a.*/i) { } 2 0 2
372 2 %oauth = map { ($_) => undef } @{Net::OAuth->request($type)->all_message_params()};
373 }
374 elsif ($params =~ m/^a.*/i) {
375 2 %oauth = map { ($_) => undef } @{Net::OAuth->request($type)->all_api_params()};
376 }
377 else {
378 0 %oauth = map { ($_) => undef } @{Net::OAuth->request($type)->all_params()};
379 }
380 4 foreach my $param (keys %oauth) {
381 29 ▶ if (defined ($self->{oauth}->{$param})) { $oauth{$param} = $self->{oauth}->{$param}; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"oauth"}{$param}) 18 11 29
382 }
383 4 return %oauth;
384 }
385 else {
386 1 return %{$self->{oauth}};
387 }
388 }
389 else {
390 2 return %{$self->{fauth}};
391 }
392  
393 }
394  
395 #
396 # Use perl core Storable to save important parameters.
397 #
398 2 ▶sub export_storable_config {
Subroutine export_storable_config: called CC=2 SCAR=7.0
Pod documented
399 2 my ($self,$file) = @_;
400  
401 2 ▶ open my $EXPORT, '>', $file or croak "\nCannot open $file for write: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $EXPORT, ">", $file or croak("\nCannot open $file for write: $!\n") 2 0 2
402 2 my %config = $self->export_config();
403 2 store_fd(\%config, $EXPORT);
404 2 close $EXPORT;
405 2 return;
406 }
407  
408 #
409 # Use perl core Storable for re-vivifying an API object from saved parameters
410 #
411 2 ▶sub import_storable_config {
Subroutine import_storable_config: called CC=2 SCAR=7.0
Pod documented
412 2 my ($class,$file) = @_;
413  
414 2 ▶ open my $IMPORT, '<', $file or croak "\nCannot open $file for read: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $IMPORT, "<", $file or croak("\nCannot open $file for read: $!\n") 2 0 2
415 2 my $config_ref = retrieve_fd($IMPORT);
416 2 close $IMPORT;
417 2 my $api = $class->new($config_ref);
418 2 return $api;
419 }
420  
421  
422  
423 #
424 # Preauthorization Methods
425 #
426 # Handle request token requests (process: REQUEST TOKEN, authorize, access token)
427 #
428 0 ▶sub oauth_request_token {
Subroutine oauth_request_token: not called CC=7 SCAR=40.3
Pod documented
429 0 my ($self, $args) = @_;
430  
431 0 my %oauth = %{$self->{oauth}};
432  
433 0 ▶ unless ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_oauth) 0 0 0
434 0 carp "\noauth_request_token called for Non-OAuth Flickr::API object\n";
435 0 return;
436 }
437 0 ▶ unless ($self->get_oauth_request_type() eq 'consumer') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_oauth_request_type eq "consumer") 0 0 0
438 0 croak "\noauth_request_token called using protected resource Flickr::API object\n";
439 }
440  
441 0 $self->{oauth_request} = 'Request Token';
442 0 ▶ $oauth{request_url} = $args->{request_token_url} || 'https://api.flickr.com/services/oauth/request_token';
Condition0%0/2
$args->{'request_token_url'} || 'https://api.flickr.com/services/oauth/request_token'
l!l
00
MC/DC0%0/1
$args->{'request_token_url'} || 'https://api.flickr.com/services/oauth/request_token'
$args->{'request_token_url'}
Truth table0%0/2
A
A= $args->{'request_token_url'}
Aresult
11
00
443 0 ▶ $oauth{callback} = $args->{callback} || 'https://127.0.0.1';
Condition0%0/2
$args->{'callback'} || 'https://127.0.0.1'
l!l
00
MC/DC0%0/1
$args->{'callback'} || 'https://127.0.0.1'
$args->{'callback'}
Truth table0%0/2
A
A= $args->{'callback'}
Aresult
11
00
444  
445 0 $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
446  
447 0 my $orequest = Net::OAuth->request('Request Token')->new(%oauth);
448  
449 0 $orequest->sign;
450  
451 0 my $response = $self->get($orequest->to_url);
452  
453 0 my $content = $response->decoded_content();
454 0 ▶ $content = $response->content() unless defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 0 0
455  
456 0 ▶ if ($content =~ m/^oauth_problem=(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^oauth_problem=(.+)$/) 0 0 0
457  
458 0 carp "\nRequest token not granted: '",$1,"'\n";
459 0 $self->{oauth}->{request_token} = $1;
460 0 return $1;
461 }
462  
463 0 $self->{oauth}->{request_token} = Net::OAuth->response('request token')->from_post_body($content);
464 0 $self->{oauth}->{callback} = $oauth{callback};
465 0 return 'ok';
466 }
467  
468 #
469 # Participate in authorization (process: request token, AUTHORIZE, access token)
470 #
471 0 ▶sub oauth_authorize_uri {
Subroutine oauth_authorize_uri: not called CC=6 SCAR=37.4
Pod documented
472  
473 0 my ($self, $args) = @_;
474  
475 0 ▶ unless ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_oauth) 0 0 0
476 0 carp "oauth_authorize_uri called for Non-OAuth Flickr::API object";
477 0 return;
478 }
479 0 my %oauth = %{$self->{oauth}};
480  
481 0 $self->{oauth_request} = 'User Authentication';
482 0 ▶ $oauth{perms} = lc($args->{perms}) || 'read';
Condition0%0/2
lc $args->{'perms'} || 'read'
l!l
00
MC/DC0%0/1
lc $args->{'perms'} || 'read'
lc $args->{'perms'}
Truth table0%0/2
A
A= lc $args->{'perms'}
Aresult
11
00
483  
484 carp "\nThe 'perms' parameter must be one of: read, write, delete\n"
485 0 ▶ and return unless defined($oauth{perms}) && $oauth{perms} =~ /^(read|write|delete)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $oauth{"perms"} and $oauth{"perms"} =~ /^(read|write|delete)$/ 0 0 0
Condition0%0/8
defined $oauth{'perms'} && $oauth{'perms'} =~ /^(read|write|delete)$/ || carp("\nThe 'perms' parameter must be one of: read, write, delete\n") && (return)
l!l&&r!l&&!r
000
defined $oauth{"perms"} and $oauth{"perms"} =~ /^(read|write|delete)$/
!ll&&!rl&&r
000
carp("\nThe 'perms' parameter must be one of: read, write, delete\n") and return
!ll
00
MC/DC0%0/3
defined $oauth{'perms'} && $oauth{'perms'} =~ /^(read|write|delete)$/ || carp("\nThe 'perms' parameter must be one of: read, write, delete\n") && (return)
defined $oauth{"perms"} $oauth{"perms"} =~ /^(read|write|delete)$/ carp("\nThe 'perms' parameter must be one of: read, write, delete\n")
Truth table0%0/5
A and B || C
A= defined $oauth{"perms"}B= $oauth{"perms"} =~ /^(read|write|delete)$/C= carp("\nThe 'perms' parameter must be one of: read, write, delete\n")
ABCresult
11X1
0X11
1011
0X00
1000
486  
487 0 $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
488  
489 return $self->{auth_uri} .
490 '?oauth_token=' . $oauth{'request_token'}{'token'} .
491 0 '&perms=' . $oauth{perms};
492  
493 }
494  
495 #
496 # flickr preauthorization
497 #
498  
499 5 ▶sub request_auth_url {
Subroutine request_auth_url: called CC=8 SCAR=21.8
Pod documented
500 5 my ($self, $perms, $frob) = @_;
501  
502 5 ▶ if ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_oauth) 0 5 5
503  
504 0 carp "request_auth_url called for an OAuth instantiated Flickr::API";
505 0 return;
506  
507 }
508  
509 5 $perms = lc($perms);
510  
511 5 ▶ carp "\nThe 'perms' parameter must be one of: read, write, delete\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $perms and $perms =~ /^(read|write|delete)$/ 1 4 5
Condition62%5/8
defined $perms && $perms =~ /^(read|write|delete)$/ || carp("\nThe 'perms' parameter must be one of: read, write, delete\n") && (return)
l!l
410
defined $perms and $perms =~ /^(read|write|delete)$/
!ll&&!rl&&r
014
carp("\nThe 'perms' parameter must be one of: read, write, delete\n") and return
!ll
01
MC/DC0%0/3
defined $perms && $perms =~ /^(read|write|delete)$/ || carp("\nThe 'perms' parameter must be one of: read, write, delete\n") && (return)
defined $perms $perms =~ /^(read|write|delete)$/ carp("\nThe 'perms' parameter must be one of: read, write, delete\n")
Truth table20%1/5
A and B || C
A= defined $permsB= $perms =~ /^(read|write|delete)$/C= carp("\nThe 'perms' parameter must be one of: read, write, delete\n")
ABCresult
11X1
0X11
1011
0X00
1000
512 and return unless defined($perms) && $perms =~ /^(read|write|delete)$/;
513  
514 4 ▶ return unless defined $self->{api_secret} && length $self->{api_secret};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"api_secret"} and length $self->{"api_secret"} 1 3 4
Condition66%2/3
defined $self->{"api_secret"} and length $self->{"api_secret"}
!ll&&!rl&&r
103
MC/DC50%1/2
defined $self->{"api_secret"} and length $self->{"api_secret"}
defined $self->{"api_secret"} length $self->{"api_secret"}
Truth table66%2/3
A and B
A= defined $self->{"api_secret"}B= length $self->{"api_secret"}
ABresult
0X0
100
111
515  
516 my %fauth = (
517 'api_key' => $self->{api_key},
518 3 'perms' => $perms
519 );
520  
521 3 ▶ if ($frob) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frob) 3 0 3
522 3 $fauth{frob} = $frob;
523 }
524  
525 3 my $sig = $self->_sign_args(\%fauth);
526 3 $fauth{api_sig} = $sig;
527  
528 3 my $uri = URI->new($self->{auth_uri});
529 3 $uri->query_form(%fauth);
530  
531 3 return $uri;
532 }
533  
534  
535 #
536 # Access Token (post authorization) Methods
537 #
538 # Handle access token requests (process: request token, authorize, ACCESS TOKEN)
539 #
540 0 ▶sub oauth_access_token {
Subroutine oauth_access_token: not called CC=6 SCAR=37.4
Pod documented
541  
542 0 my ($self, $args) = @_;
543  
544 0 ▶ unless ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_oauth) 0 0 0
545 0 carp "oauth_access_token called for Non-OAuth Flickr::API object";
546 0 return;
547 }
548 0 ▶ if ($args->{token} ne $self->{oauth}->{request_token}->{token}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"token"} ne $self->{"oauth"}{"request_token"}{"token"}) 0 0 0
549  
550 0 carp "Request token in API does not match token for access token request";
551 0 return;
552  
553 }
554  
555 #
556 # Stuff the values for the Net::OAuth factory
557 #
558 0 $self->{oauth}->{verifier} = $args->{verifier};
559 0 $self->{oauth}->{token} = $args->{token};
560 0 $self->{oauth}->{token_secret} = $self->{oauth}->{request_token}->{token_secret};
561  
562 0 my %oauth = %{$self->{oauth}};
563  
564 0 ▶ $oauth{request_url} = $args->{access_token_url} || 'https://api.flickr.com/services/oauth/access_token';
Condition0%0/2
$args->{'access_token_url'} || 'https://api.flickr.com/services/oauth/access_token'
l!l
00
MC/DC0%0/1
$args->{'access_token_url'} || 'https://api.flickr.com/services/oauth/access_token'
$args->{'access_token_url'}
Truth table0%0/2
A
A= $args->{'access_token_url'}
Aresult
11
00
565  
566 0 $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
567  
568 0 my $request = Net::OAuth->request('Access Token')->new(%oauth);
569  
570 0 $request->sign;
571  
572 0 my $response = $self->get($request->to_url);
573  
574 0 my $content = $response->decoded_content();
575 0 ▶ $content = $response->content() unless defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 0 0
576  
577 0 ▶ if ($content =~ m/^oauth_problem=(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^oauth_problem=(.+)$/) 0 0 0
578  
579 0 carp "\nAccess token not granted: '",$1,"'\n";
580 0 $self->{oauth}->{access_token} = $1;
581  
582 0 delete $self->{oauth}->{token}; # Not saving problematic request token
583 0 delete $self->{oauth}->{token_secret}; # token secret
584 0 delete $self->{oauth}->{verifier}; # and verifier copies
585  
586 0 return $1;
587  
588 }
589  
590 0 $self->{oauth}->{access_token} = Net::OAuth->response('access token')->from_post_body($content);
591 0 $self->{oauth}->{token} = $self->{oauth}->{access_token}->token();
592 0 $self->{oauth}->{token_secret} = $self->{oauth}->{access_token}->token_secret();
593  
594 0 delete $self->{oauth}->{request_token}; #No longer valid, anyway
595 0 delete $self->{oauth}->{verifier};
596  
597 0 return 'ok';
598  
599 }
600  
601 0 ▶sub flickr_access_token {
Subroutine flickr_access_token: not called CC=1 SCAR=6.9
Pod documented
602 0 my ($self,$frob) = @_;
603  
604 0 my $rsp = $self->execute_method('flickr.auth.getToken', {api_key => $self->{api_key}, frob => $frob });
605 0 my $response_ref = $rsp->as_hash();
606  
607 0 $self->{fauth}->{frob} = $frob;
608  
609 0 $self->{token} = $response_ref->{auth}->{token};
610 0 $self->{fauth}->{token} = $response_ref->{auth}->{token};
611  
612 0 $self->{fauth}->{user} = $response_ref->{auth}->{user};
613  
614 0 return $response_ref->{stat};
615  
616 }
617  
618  
619 #
620 # Utility methods
621 #
622  
623  
624 32 ▶sub is_oauth {
Subroutine is_oauth: called CC=3 SCAR=11.0
Pod documented
625 32 my ($self) = @_;
626 32 ▶ if (defined $self->{api_type} and $self->{api_type} eq 'oauth') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'api_type'} and $self->{'api_type'} eq 'oauth') { } 7 25 32
Condition66%2/3
defined $self->{"api_type"} and $self->{"api_type"} eq "oauth"
!ll&&!rl&&r
0257
MC/DC50%1/2
defined $self->{"api_type"} and $self->{"api_type"} eq "oauth"
defined $self->{"api_type"} $self->{"api_type"} eq "oauth"
Truth table66%2/3
A and B
A= defined $self->{"api_type"}B= $self->{"api_type"} eq "oauth"
ABresult
0X0
100
111
627 7 return 1;
628 }
629 else {
630 25 return 0;
631 }
632 }
633  
634  
635 2 ▶sub get_oauth_request_type {
Subroutine get_oauth_request_type: called CC=3 SCAR=13.3
Pod documented
636 2 my ($self) = @_;
637  
638 2 ▶ if (defined $self->{api_type} and $self->{api_type} eq 'oauth') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'api_type'} and $self->{'api_type'} eq 'oauth') { } 2 0 2
Condition33%1/3
defined $self->{"api_type"} and $self->{"api_type"} eq "oauth"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->{"api_type"} and $self->{"api_type"} eq "oauth"
defined $self->{"api_type"} $self->{"api_type"} eq "oauth"
Truth table33%1/3
A and B
A= defined $self->{"api_type"}B= $self->{"api_type"} eq "oauth"
ABresult
0X0
100
111
639 2 return $self->{oauth_request};
640 }
641 else {
642 0 return;
643 }
644 }
645  
646 2 ▶sub api_type {
Subroutine api_type: called CC=1 SCAR=0.0
Pod undocumented
647 2 my ($self) = @_;
648  
649 2 return $self->{api_type};
650  
651 }
652  
653  
654 0 ▶sub api_success {
Subroutine api_success: not called CC=1 SCAR=6.9
Pod undocumented
655 0 my ($self) = @_;
656  
657 0 return $self->{flickr}->{status}->{api_success};
658  
659 }
660  
661  
662  
663  
664 0 ▶sub api_message {
Subroutine api_message: not called CC=1 SCAR=6.9
Pod undocumented
665 0 my ($self) = @_;
666  
667 0 return $self->{flickr}->{status}->{api_message};
668 }
669  
670  
671 0 ▶sub api_permissions {
Subroutine api_permissions: not called CC=6 SCAR=37.4
Pod undocumented
672 0 my ($self) = @_;
673 0 my $rsp;
674 my $check;
675 0 my $retval;
676  
677 0 ▶ if ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_oauth) { } 0 0 0
678  
679 0 ▶ if (defined($self->{oauth}->{perms})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'oauth'}{'perms'}) { } 0 0 0
680  
681 0 $self->_set_status(1,"Permissions retrieved from config.");
682  
683 }
684 else {
685  
686 0 $self->{oauth}->{perms} = 'none'; #preload no perms
687  
688 0 $rsp = $self->execute_method('flickr.auth.oauth.checkToken');
689  
690 0 ▶ if (!$rsp->success()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $rsp->success) { } 0 0 0
691  
692 0 $rsp->_propagate_status($self->{flickr}->{status});
693  
694 carp "\nUnable to validate OAuth token. Flickr error: ",
695 $self->{flickr}->{status}->{error_code}," - \"",
696 0 $self->{flickr}->{status}->{error_message},"\" \n";
697 0 delete $self->{oauth}->{perms};
698 0 $self->_set_status(0,"Unable to validate OAuth token, Flickr API call not successful.");
699  
700 }
701 else {
702  
703 0 $check = $rsp->as_hash();
704  
705 0 $self->{oauth}->{perms} = $check->{oauth}->{perms};
706 0 $self->_set_status(1,"Permissions retrieved from Flickr.");
707  
708 }
709 } # else not cached
710  
711 0 $retval = $self->{oauth}->{perms};
712  
713 } # is_oauth
714 else { # is_flickr
715  
716 0 ▶ if (defined($self->{fauth}->{perms})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'fauth'}{'perms'}) { } 0 0 0
717  
718 0 $self->_set_status(1,"Permissions retrieved from config.");
719  
720 }
721 else {
722  
723 0 $self->{fauth}->{perms} = 'none'; #preload no perms
724 0 $rsp = $self->execute_method('flickr.auth.checkToken',{'auth_token' => $self->{fauth}->{token}});
725  
726 0 ▶ if (!$rsp->success()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $rsp->success) { } 0 0 0
727  
728 0 $rsp->_propagate_status($self->{flickr}->{status});
729  
730 carp "\nUnable to validate Flickr token. Flickr error: ",
731 $self->{flickr}->{status}->{error_code}," - \"",
732 0 $self->{flickr}->{status}->{error_message},"\" \n";
733 0 delete $self->{fauth}->{perms};
734 0 $self->_set_status(0,"Unable to validate Flickr token, Flickr API call not successful.");
735  
736 }
737 else {
738  
739 0 $check = $rsp->as_hash();
740  
741 0 $self->{fauth}->{perms} = $check->{auth}->{perms};
742 0 $self->_set_status(1,"Permissions retrieved from Flickr.");
743 }
744 } # else not cached
745  
746 0 $retval = $self->{fauth}->{perms};
747  
748 } # else is_flickr
749  
750  
751 0 return $retval;
752  
753 }
754  
755  
756 #
757 # Private methods
758 #
759  
760 9 ▶sub _sign_args {
Subroutine _sign_args: called CC=5 SCAR=16.3
761 9 my ($self, $args) = @_;
762  
763 9 ▶ if ($self->is_oauth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_oauth) 0 9 9
764  
765 0 carp "_sign_args called for an OAuth instantiated Flickr::API";
766 0 return;
767  
768 }
769  
770 9 my $sig = $self->{api_secret};
771  
772 9 foreach my $key (sort {$a cmp $b} keys %{$args}) {
773  
774 18 ▶ my $value = (defined($args->{$key})) ? $args->{$key} : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{$key} ? : 17 1 18
775 18 $sig .= $key . $value;
776 }
777  
778 9 ▶ return md5_hex(encode_utf8($sig)) if $self->{unicode};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"unicode"} 4 5 9
779 5 return md5_hex($sig);
780 }
781  
782 4 ▶sub _find_tag {
Subroutine _find_tag: called CC=3 SCAR=11.1
783 4 my ($self, $children) = @_;
784 4 for my $child(@{$children}){
785 8 ▶ return $child if $child->{type} eq 'element';
Branch: 1 branch
BranchTrueFalseTotal
if $child->{"type"} eq "element" 4 4 8
786 }
787 0 return {};
788 }
789  
790 4 ▶sub _make_nonce {
Subroutine _make_nonce: called CC=1 SCAR=0.0
791  
792 4 return md5_hex(rand);
793  
794 }
795 1 ▶sub _export_api {
Subroutine _export_api: called CC=1 SCAR=0.0
796 1 my ($self) = @_;
797 1 my $api = {};
798  
799 1 $api->{oauth} = $self->{oauth};
800 1 $api->{fauth} = $self->{fauth};
801 1 $api->{flickr} = $self->{flickr};
802  
803 1 $api->{api_type} = $self->{api_type};
804 1 $api->{api_key} = $self->{api_key};
805 1 $api->{api_secret} = $self->{api_secret};
806 1 $api->{rest_uri} = $self->{rest_uri};
807 1 $api->{unicode} = $self->{unicode};
808 1 $api->{auth_uri} = $self->{auth_uri};
809 1 $api->{upload_uri} = $self->{upload_uri};
810  
811 1 return $api;
812 }
813  
814  
815 8 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
816  
817 8 my ($self) = @_;
818 8 $self->_set_status(1,'Base API initialized');
819 8 return;
820  
821 }
822  
823 0 ▶sub _full_status {
Subroutine _full_status: not called CC=1 SCAR=6.9
824  
825 0 my ($self) = @_;
826 0 return $self->{flickr}->{status};
827 }
828  
829 8 ▶sub _clear_status {
Subroutine _clear_status: called CC=1 SCAR=0.0
830  
831 8 my ($self) = @_;
832  
833 # the API status
834 8 $self->_set_status(1,'');
835 # the propagated response status
836 8 $self->{flickr}->{status}->{_rc} = 0;
837 8 $self->{flickr}->{status}->{success} = 1; # initialize as successful
838 8 $self->{flickr}->{status}->{error_code} = 0;
839 8 $self->{flickr}->{status}->{error_message} = '';
840  
841 8 return;
842  
843 }
844  
845 16 ▶sub _set_status {
Subroutine _set_status: called CC=2 SCAR=7.0
846  
847 16 my ($self, $good, $msg) = @_;
848  
849 16 ▶ if ($good != 0) { $good = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($good != 0) 16 0 16
850  
851 16 $self->{flickr}->{status}->{api_success} = $good;
852 16 $self->{flickr}->{status}->{api_message} = $msg;
853  
854 16 return;
855 }
856  
857  
858  
859 15 1;
860  
861 __END__
« blib/lib/Flickr/API/Upload.pm ↑ Summary blib/lib/Flickr/API/Reflection.pm »