Correios/Token.pm

filter: Statementstmt 89.6% 26 / 29 Branchbran 60.0% 6 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 73.0% 38 / 52 CC 7 SCAR 18.1
CC
7
Cov
76%
autentica
9.8
BEGIN
1.0
BEGIN
1.0
CRAP 6.1
« Correios/Manifestacao.pm ↑ Summary Correios/Prazo.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::Correios::Token;
7  
8 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 4 my ($class, $parent) = @_;
10  
11 4 Scalar::Util::weaken($parent);
12 4 return bless { parent => $parent }, $class;
13 }
14  
15 4 ▶sub autentica {
Subroutine autentica: called CC=7 SCAR=22.8
Pod undocumented
16 4 my ($self, %args) = @_;
17 4 my $parent = $self->{parent};
18  
19 4 my $endpoint_url = $parent->{base_url} . 'token/v1/autentica';
20 4 my $json_body;
21 # TODO: precisamos entender quais endpoints funcionam com quais tokens.
22 # muito provavelmente precisaremos de ambos ao mesmo tempo.
23 4 ▶ if ($args{contrato}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'contrato'}) { } 0 4 4
elsif ($args{'cartao'}) { } 3 1 4
24 0 $endpoint_url .= '/contrato';
25 0 $json_body = JSON::encode_json({ numero => $args{contrato} });
26 }
27 elsif ($args{cartao}) {
28 3 $endpoint_url .= '/cartaopostagem';
29 3 $json_body = JSON::encode_json({ numero => $args{cartao} });
30 }
31  
32 my $res = $parent->{agent}->request(
33 'POST',
34 $endpoint_url,
35 {
36 headers => { 'Authorization' => 'Basic ' . $parent->{auth_basic} },
37 4 ▶ (defined $json_body? (content => $json_body) : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $json_body ? : 3 1 4
38 },
39 );
40 4 ▶ if ($parent->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->{"debug"}) 0 4 4
41 $parent->_debug(
42 "curl -X POST '$endpoint_url' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Basic $parent->{auth_basic}' " . ((defined $json_body && length($json_body)) ? ("-d '" . $json_body . "'") : ''),
43 "Response: " . $res->{status} . "\n" . $res->{content}
44 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $json_body && length $json_body ? : 0 0 0
Condition0%0/3
defined $json_body and length $json_body
!ll&&!rl&&r
000
MC/DC0%0/2
defined $json_body and length $json_body
defined $json_body length $json_body
Truth table0%0/3
A and B
A= defined $json_bodyB= length $json_body
ABresult
0X0
100
111
45 }
46 4 return $parent->parse_response($res);
47 }
48  
49 1 1;
« Correios/Manifestacao.pm ↑ Summary Correios/Prazo.pm »