| 1 | package WWW::ORCID::MemberAPI; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.0401; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use JSON qw(decode_json encode_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | with 'WWW::ORCID::API'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | has read_limited_token => (is => 'lazy'); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub _build_read_limited_token { | ||||||||||||||||||||||||||||
| 17 | 0 | ▶ | $_[0]->access_token( | ||||||||||||||||||||||||||
|
Subroutine
_build_read_limited_token: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 18 | grant_type => 'client_credentials', | ||||||||||||||||||||||||||||
| 19 | scope => '/read-limited' | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub add { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | $self->_clear_last_error; | |||||||||||||||||||||||||||
| 26 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 27 | 0 | my $data = shift; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $opts = ref $_[0] ? $_[0] : {@_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | my $body = encode_json($data); | |||||||||||||||||||||||||||
| 30 | 0 | my $url = _url($self->api_url, $path, $opts); | |||||||||||||||||||||||||||
| 31 | 0 | my $res = $self->_t->post($url, $body, _headers($opts, 0, 1)); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ($res->[0] eq '201') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | my $loc = $res->[1]->{location}; | |||||||||||||||||||||||||||
| 34 | 0 | my ($put_code) = $loc =~ m|([^/]+)$|; | |||||||||||||||||||||||||||
| 35 | 0 | return $put_code; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | $self->_set_last_error($res); | |||||||||||||||||||||||||||
| 38 | 0 | return; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub update { | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 0 | $self->_clear_last_error; | |||||||||||||||||||||||||||
| 44 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 45 | 0 | my $data = shift; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $opts = ref $_[0] ? $_[0] : {@_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # put code needs to be in both path and body | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $data->{'put-code'} ||= $opts->{put_code} if $opts->{put_code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$data->{"put-code"} ||= $opts->{"put_code"}
MC/DC0%0/2
$data->{"put-code"} ||= $opts->{"put_code"}
$data->{"put-code"}
$opts->{"put_code"}
Truth table0%0/3
A ||= B
A= $data->{"put-code"}B= $opts->{"put_code"}
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $opts->{put_code} ||= $data->{'put-code'} if $data->{'put-code'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts->{"put_code"} ||= $data->{"put-code"}
MC/DC0%0/2
$opts->{"put_code"} ||= $data->{"put-code"}
$opts->{"put_code"}
$data->{"put-code"}
Truth table0%0/3
A ||= B
A= $opts->{"put_code"}B= $data->{"put-code"}
| |||||||||||||||||||||||||||||
| 51 | 0 | my $body = encode_json($data); | |||||||||||||||||||||||||||
| 52 | 0 | my $url = _url($self->api_url, $path, $opts); | |||||||||||||||||||||||||||
| 53 | 0 | my $res = $self->_t->put($url, $body, _headers($opts, 1, 1)); | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($res->[0] eq '200') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | return decode_json($res->[2]); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 0 | $self->_set_last_error($res); | |||||||||||||||||||||||||||
| 58 | 0 | return; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub delete { | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | $self->_clear_last_error; | |||||||||||||||||||||||||||
| 64 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $opts = ref $_[0] ? $_[0] : {@_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | my $url = _url($self->api_url, $path, $opts); | |||||||||||||||||||||||||||
| 67 | 0 | my $res = $self->_t->delete($url, undef, _headers($opts, 1)); | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($res->[0] eq '204') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | return 1; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | $self->_set_last_error($res); | |||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||