| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use Scalar::Util (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
13
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use JSON (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
267
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Correios::Token; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
|
9
|
1
|
|
|
1
|
0
|
3
|
my ($class, $parent) = @_; |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
4
|
Scalar::Util::weaken($parent); |
|
12
|
1
|
|
|
|
|
10
|
return bless { parent => $parent }, $class; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub autentica { |
|
16
|
1
|
|
|
1
|
0
|
344
|
my ($self, %args) = @_; |
|
17
|
1
|
|
|
|
|
3
|
my $parent = $self->{parent}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
2
|
my $endpoint_url = $parent->{base_url} . 'token/v1/autentica'; |
|
20
|
1
|
|
|
|
|
2
|
my $json_body; |
|
21
|
|
|
|
|
|
|
# TODO: precisamos entender quais endpoints funcionam com quais tokens. |
|
22
|
|
|
|
|
|
|
# muito provavelmente precisaremos de ambos ao mesmo tempo. |
|
23
|
1
|
50
|
|
|
|
6
|
if ($args{contrato}) { |
|
|
|
50
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
$endpoint_url .= '/contrato'; |
|
25
|
0
|
|
|
|
|
0
|
$json_body = JSON::encode_json({ numero => $args{contrato} }); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
elsif ($args{cartao}) { |
|
28
|
0
|
|
|
|
|
0
|
$endpoint_url .= '/cartaopostagem'; |
|
29
|
0
|
|
|
|
|
0
|
$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
|
1
|
50
|
|
|
|
7
|
(defined $json_body? (content => $json_body) : ()), |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
1
|
|
|
|
|
1856
|
return $parent->parse_response($res); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |