| 1 | package Flickr::API::Upload; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::OAuth; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Encode qw(encode_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use parent qw(HTTP::Request); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '1.28'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 20 | 0 | my $self; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my @params = ( | |||||||||||||||||||||||||||
| 23 | "title", | ||||||||||||||||||||||||||||
| 24 | "description", | ||||||||||||||||||||||||||||
| 25 | "tags", | ||||||||||||||||||||||||||||
| 26 | "is_public", | ||||||||||||||||||||||||||||
| 27 | "is_friend", | ||||||||||||||||||||||||||||
| 28 | "is_family", | ||||||||||||||||||||||||||||
| 29 | "safety_level", | ||||||||||||||||||||||||||||
| 30 | "content_type", | ||||||||||||||||||||||||||||
| 31 | "hidden" | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $photo = {}; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | unless ( -f $args->{photo}->{photo} && -r $args->{photo}->{photo} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $args->{"photo"}{"photo"} and -r $args->{"photo"}{"photo"}
MC/DC0%0/2
-f $args->{"photo"}{"photo"} and -r $args->{"photo"}{"photo"}
-f $args->{"photo"}{"photo"}
-r $args->{"photo"}{"photo"}
Truth table0%0/3
A and B
A= -f $args->{"photo"}{"photo"}B= -r $args->{"photo"}{"photo"}
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | carp "\nPhoto: ",$args->{photo}->{photo},", is not a readable file.\n"; | |||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||
| 44 | # make hashref of valid arguments for an upload, ignore extraneous | ||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||
| 46 | 0 | $photo->{photo} = $args->{photo}->{photo}; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | $photo->{async} = $args->{photo}->{async} || '0'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'photo'}{'async'} || '0'
MC/DC0%0/1
$args->{'photo'}{'async'} || '0'
$args->{'photo'}{'async'}
Truth table0%0/2
A
A= $args->{'photo'}{'async'}
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | for my $param (@params) { | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (defined($args->{photo}->{$param})) { $photo->{$param} = $args->{photo}->{$param}; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | chomp $photo->{'description'}; | |||||||||||||||||||||||||||
| 56 | 0 | delete($args->{photo}); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $args->{api}->{request_method} = 'POST'; # required to be POST | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (($args->{api_type} || '') eq 'oauth') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$args->{'api_type'} || ''
MC/DC0%0/1
$args->{'api_type'} || ''
$args->{'api_type'}
Truth table0%0/2
A
A= $args->{'api_type'}
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | $args->{api}->{extra_params} = $photo; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $orequest = Net::OAuth->request('protected resource')->new(%{$args->{api}}); | |||||||||||||||||||||||||||
| 67 | 0 | $orequest->sign(); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $buzo = $orequest->to_hash(); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my @msgarr; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | for my $param (sort keys %{$buzo}) { | |||||||||||||||||||||||||||
| 74 | 0 | push(@msgarr,$param); | |||||||||||||||||||||||||||
| 75 | 0 | push(@msgarr,$buzo->{$param}); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | push(@msgarr,'photo'); | |||||||||||||||||||||||||||
| 79 | 0 | push(@msgarr, [$photo->{photo}]); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | $self = POST $args->{api}->{request_url}, | ||||||||||||||||||||||||||||
| 82 | 0 | 'Content-Type' => 'form-data', | |||||||||||||||||||||||||||
| 83 | 'Content' => \@msgarr; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | } # if oauth | ||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | my $pixfile = $photo->{photo}; | |||||||||||||||||||||||||||
| 91 | 0 | delete $photo->{photo}; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | $photo->{api_key} = $args->{api}->{api_key}; | |||||||||||||||||||||||||||
| 94 | 0 | $photo->{auth_token} = $args->{api}->{token}; | |||||||||||||||||||||||||||
| 95 | 0 | my $sig = $args->{api}->{api_secret}; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | foreach my $key (sort {$a cmp $b} keys %{$photo}) { | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my $value = (defined($photo->{$key})) ? $photo->{$key} : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $sig .= $key . $value; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($args->{api}->{unicode}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | $photo->{api_sig} = md5_hex(encode_utf8($sig)); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | $photo->{api_sig} = md5_hex($sig); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | my @msgarr; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | for my $param (sort keys %{$photo}) { | |||||||||||||||||||||||||||
| 117 | 0 | push(@msgarr,$param); | |||||||||||||||||||||||||||
| 118 | 0 | push(@msgarr,$photo->{$param}); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | push(@msgarr,'photo'); | |||||||||||||||||||||||||||
| 121 | 0 | push(@msgarr, [$pixfile]); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | $self = POST $args->{api}->{request_url}, | ||||||||||||||||||||||||||||
| 124 | 0 | 'Content-Type' => 'form-data', | |||||||||||||||||||||||||||
| 125 | 'Content' => \@msgarr; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | } # else i'm flickr | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | return $self; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub encode_args { | ||||||||||||||||||||||||||
|
Subroutine
encode_args: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 138 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my $content; | |||||||||||||||||||||||||||
| 141 | 0 | my $url = URI->new('https:'); | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($self->{unicode}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | for my $k(keys %{$self->{api_args}}){ | |||||||||||||||||||||||||||
| 145 | 0 | $self->{api_args}->{$k} = encode_utf8($self->{api_args}->{$k}); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 0 | $url->query_form(%{$self->{api_args}}); | |||||||||||||||||||||||||||
| 149 | 0 | $content = $url->query; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | $self->header('Content-Type' => 'application/x-www-form-urlencoded'); | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | if (defined($content)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | $self->header('Content-Length' => length($content)); | |||||||||||||||||||||||||||
| 155 | 0 | $self->content($content); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 0 | return; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | 1; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||