| 1 | package Flickr::API::Request; | ||||||||||||||||||||
| 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 HTTP::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 15 | ▶ | use Net::OAuth; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 15 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 15 | ▶ | use Encode qw(encode_utf8); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 15 | ▶ | use parent qw(HTTP::Request); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 15 | our $VERSION = '1.28'; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=30.1
Pod
documented
| |||||||||||||||||||||
| 15 | 2 | my $class = shift; | |||||||||||||||||||
| 16 | 2 | my $options = shift; | |||||||||||||||||||
| 17 | 2 | my $self; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | ▶ | if (($options->{api_type} || '') eq 'oauth') { | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$options->{'api_type'} || ''
MC/DC0%0/1
$options->{'api_type'} || ''
$options->{'api_type'}
Truth table50%1/2
A
A= $options->{'api_type'}
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | $options->{args}->{request_method}='POST'; | |||||||||||||||||||
| 22 | 0 | $options->{args}->{request_url}=$options->{rest_uri}; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | my $orequest; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | if (defined($options->{args}->{token})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | $orequest = Net::OAuth->request('protected resource')->new(%{$options->{args}}); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | $orequest = Net::OAuth->request('consumer')->new(%{$options->{args}}); | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 0 | $orequest->sign(); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | my $h = HTTP::Headers->new; | |||||||||||||||||||
| 42 | 0 | $h->header('Content-Type' => 'application/x-www-form-urlencoded'); | |||||||||||||||||||
| 43 | 0 | $h->header('Content-Length' => length($orequest->to_post_body)); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | $self = HTTP::Request->new( | ||||||||||||||||||||
| 46 | $options->{args}->{request_method}, | ||||||||||||||||||||
| 47 | $options->{rest_uri}, | ||||||||||||||||||||
| 48 | 0 | $h, | |||||||||||||||||||
| 49 | $orequest->to_post_body()); | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | $self->{api_method} = $options->{method}; | |||||||||||||||||||
| 52 | 0 | $self->{api_type} = $options->{api_type}; | |||||||||||||||||||
| 53 | 0 | ▶ | $self->{unicode} = $options->{unicode} || 0; | ||||||||||||||||||
|
Condition0%0/2
$options->{'unicode'} || 0
MC/DC0%0/1
$options->{'unicode'} || 0
$options->{'unicode'}
Truth table0%0/2
A
A= $options->{'unicode'}
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | $self = HTTP::Request->new; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 2 | $self->{api_method} = $options->{method}; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 2 | ▶ | $self->{api_type} = $options->{api_type} || 'flickr'; | ||||||||||||||||||
|
Condition50%1/2
$options->{'api_type'} || 'flickr'
MC/DC0%0/1
$options->{'api_type'} || 'flickr'
$options->{'api_type'}
Truth table50%1/2
A
A= $options->{'api_type'}
| |||||||||||||||||||||
| 63 | 2 | ▶ | $self->{unicode} = $options->{unicode} || 0; | ||||||||||||||||||
|
Condition50%1/2
$options->{'unicode'} || 0
MC/DC0%0/1
$options->{'unicode'} || 0
$options->{'unicode'}
Truth table50%1/2
A
A= $options->{'unicode'}
| |||||||||||||||||||||
| 64 | 2 | $self->{api_args} = $options->{args}; | |||||||||||||||||||
| 65 | 2 | ▶ | $self->{rest_uri} = $options->{rest_uri} || 'https://api.flickr.com/services/rest/'; | ||||||||||||||||||
|
Condition50%1/2
$options->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
MC/DC0%0/1
$options->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
$options->{'rest_uri'}
Truth table50%1/2
A
A= $options->{'rest_uri'}
| |||||||||||||||||||||
| 66 | 2 | $self->method('POST'); | |||||||||||||||||||
| 67 | 2 | $self->uri($self->{rest_uri}); | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 2 | bless $self, $class; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 2 | return $self; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 2 | ▶ | sub encode_args { | ||||||||||||||||||
|
Subroutine
encode_args: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||
| 77 | 2 | my ($self) = @_; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 2 | my $content; | |||||||||||||||||||
| 80 | 2 | my $url = URI->new('https:'); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 2 | ▶ | if ($self->{unicode}){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | for my $k(keys %{$self->{api_args}}){ | |||||||||||||||||||
| 84 | 0 | $self->{api_args}->{$k} = encode_utf8($self->{api_args}->{$k}); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | 2 | $url->query_form(%{$self->{api_args}}); | |||||||||||||||||||
| 88 | 2 | $content = $url->query; | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 2 | $self->header('Content-Type' => 'application/x-www-form-urlencoded'); | |||||||||||||||||||
| 92 | 2 | ▶ | if (defined($content)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 2 | $self->header('Content-Length' => length($content)); | |||||||||||||||||||
| 94 | 2 | $self->content($content); | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | 2 | return; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 15 | 1; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||