| 1 | package OAuth::Simple; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | require LWP::UserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | require JSON; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '1.03'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $self = bless {@_}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | Carp::croak("app_id, secret and postback required for this action") | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | unless ($self->{app_id} && $self->{secret} && $self->{postback}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"app_id"} and $self->{"secret"} and $self->{"postback"}
$self->{"app_id"} and $self->{"secret"}
MC/DC0%0/3
$self->{"app_id"} and $self->{"secret"} and $self->{"postback"}
$self->{"app_id"}
$self->{"secret"}
$self->{"postback"}
Truth table0%0/4
A and B and C
A= $self->{"app_id"}B= $self->{"secret"}C= $self->{"postback"}
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $self->{ua} ||= LWP::UserAgent->new(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"ua"} ||= "LWP::UserAgent"->new
MC/DC0%0/2
$self->{"ua"} ||= "LWP::UserAgent"->new
$self->{"ua"}
"LWP::UserAgent"->new
Truth table0%0/3
A ||= B
A= $self->{"ua"}B= "LWP::UserAgent"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $self->{json} ||= JSON->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"json"} ||= "JSON"->new
MC/DC0%0/2
$self->{"json"} ||= "JSON"->new
$self->{"json"}
"JSON"->new
Truth table0%0/3
A ||= B
A= $self->{"json"}B= "JSON"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub authorize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authorize: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my %params; %params = %$params if $params && %$params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params and %$params
MC/DC0%0/2
$params and %$params
$params
%$params
Truth table0%0/3
A and B
A= $paramsB= %$params
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $url = delete $params{url}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | Carp::croak("Authorize method URL required for this action") unless ($url); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $url = URI->new($url); | |||||||||||||||||||||||||||||||||||||||||
| 37 | $url->query_form( | ||||||||||||||||||||||||||||||||||||||||||
| 38 | client_id => $self->{app_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | redirect_uri => $self->{postback}, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | %params, | |||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return $url; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub request_access_token { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_access_token: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my %params; %params = %$params if $params && %$params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params and %$params
MC/DC0%0/2
$params and %$params
$params
%$params
Truth table0%0/3
A and B
A= $paramsB= %$params
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my ( $url, $code, $raw, $http_method ) = delete @params{ qw(url code raw http_method) }; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | Carp::croak("code and url required for this action") unless $code && $url; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$code and $url
MC/DC0%0/2
$code and $url
$code
$url
Truth table0%0/3
A and B
A= $codeB= $url
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | my $response = $self->{ua}->request($self->prepare_http_request( | ||||||||||||||||||||||||||||||||||||||||||
| 55 | url => $url, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | http_method => $http_method, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | params => { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | client_secret => $self->{secret}, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | client_id => $self->{app_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | redirect_uri => $self->{postback}, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | %params, | |||||||||||||||||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $response->decoded_content unless $response->is_success; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return $response->content if $raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $self->{json}->decode($response->content); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub request_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_data: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my %params; %params = %$params if $params && %$params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params and %$params
MC/DC0%0/2
$params and %$params
$params
%$params
Truth table0%0/3
A and B
A= $paramsB= %$params
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | my ( $url, $access_token, $raw, $http_method, $token_name ) = | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | delete @params{ qw(url access_token raw http_method token_name) }; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | Carp::croak("url required for this action") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | unless ($url); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | Carp::croak("access_token required for this action") | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | unless ($access_token || $self->{no_token}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$access_token or $self->{"no_token"}
MC/DC0%0/2
$access_token or $self->{"no_token"}
$access_token
$self->{"no_token"}
Truth table0%0/3
A or B
A= $access_tokenB= $self->{"no_token"}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | my $response = $self->{ua}->request($self->prepare_http_request( | ||||||||||||||||||||||||||||||||||||||||||
| 85 | url => $url, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | http_method => $http_method, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | params => { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $self->{no_token} ? () : ( ($token_name || 'access_token') => $access_token ), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$token_name or "access_token"
MC/DC0%0/1
$token_name or "access_token"
$token_name
Truth table0%0/2
A
A= $token_name
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | %params | ||||||||||||||||||||||||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return 0 unless $response->is_success; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return $response->content if $raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return $self->{json}->decode($response->content); | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub prepare_http_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_http_request: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ( $self, %params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $params{http_method} ||= 'GET'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params{"http_method"} ||= "GET"
MC/DC0%0/1
$params{"http_method"} ||= "GET"
$params{"http_method"}
Truth table0%0/2
A
A= $params{"http_method"}
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $req; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($params{http_method} eq 'GET') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $url = URI->new($params{url}); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $url->query_form( %{$params{params}} ) if $params{params}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $req = GET $url; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | $req = POST $params{url}, | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->{headers} && %{ $self->{headers} } ? %{ $self->{headers} } : (), | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | Content => $params{params}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"headers"} and %{$self->{"headers"};}
MC/DC0%0/2
$self->{"headers"} and %{$self->{"headers"};}
$self->{"headers"}
%{$self->{"headers"};}
Truth table0%0/3
A and B
A= $self->{"headers"}B= %{$self->{"headers"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $req; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||||||||||||||||