| 1 | package Net::Moip::V2::Endpoint; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use IO::Socket::SSL; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use MIME::Base64; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Furl; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | my $JSON = JSON::MaybeXS->new->utf8; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | has 'path', is => 'ro', required => 1; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | has 'api_url', is => 'ro',required => 1; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 2 | has 'ua', is => 'ro', required => 1; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | has 'token', is => 'ro', required => 1; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 2 | has 'key', is => 'ro', required => 1; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 2 | has 'client_id', is => 'ro'; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 2 | has 'client_secret', is => 'ro'; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | has 'access_token', is => 'ro'; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | has '_basic_auth_token', is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||||
| 29 | 5 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 5 | 'Basic '.MIME::Base64::encode_base64( $self->token .':'. $self->key, ''); | |||||||||||||||||||
| 31 | 2 | }; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | has 'url', is => 'ro', init_arg => undef, default => sub { | ||||||||||||||||||||
| 34 | 8 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 8 | join '/', $self->api_url, $self->path; | |||||||||||||||||||
| 36 | 2 | }; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | sub _authorization_string { | ||||||||||||||||||||
| 39 | 6 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_authorization_string: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 40 | 6 | ▶ | if ($self->{is_oauth}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 2 | ▶ | my $access_token = $self->access_token | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | or die "Can't build OAuth authorization. access_token is missing."; | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | return "OAuth $access_token"; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 4 | $self->_basic_auth_token; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | sub get { | ||||||||||||||||||||
| 52 | 5 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 5 | ▶ | my $url = join '/', $self->url, $id || (); | ||||||||||||||||||
|
Condition66%2/3
$id || ()
MC/DC0%0/2
$id || ()
$id
()
Truth table66%2/3
A || B
A= $idB= ()
| |||||||||||||||||||||
| 55 | 5 | $self->ua->get($url, [ | |||||||||||||||||||
| 56 | 'Content-Type' => 'application/json', | ||||||||||||||||||||
| 57 | 'Authorization' => $self->_authorization_string | ||||||||||||||||||||
| 58 | ]); | ||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub post { | ||||||||||||||||||||
| 62 | 1 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||
|
Subroutine
post: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 1 | $self->ua->post($self->url, [ | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 'Content-Type' => 'application/json', | ||||||||||||||||||||
| 67 | 'Authorization' => $self->_authorization_string | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | ], $JSON->encode($data) ); | ||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | sub oauth_get { | ||||||||||||||||||||
| 73 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
oauth_get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 74 | 2 | local $self->{is_oauth} = 1; | |||||||||||||||||||
| 75 | 2 | $self->get(@_); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | sub oauth_post { | ||||||||||||||||||||
| 79 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
oauth_post: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 80 | 0 | local $self->{is_oauth} = 1; | |||||||||||||||||||
| 81 | 0 | $self->post(@_); | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub decode_json { | ||||||||||||||||||||
| 86 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
decode_json: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | $JSON->decode($_[0]); | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 2 | 1; | |||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||