line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::TinyERP::NotaFiscal; |
2
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
1527
|
use IO::Socket::SSL; |
|
2
|
|
|
|
|
166091
|
|
|
2
|
|
|
|
|
17
|
|
5
|
2
|
|
|
2
|
|
344
|
use Scalar::Util (); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
41
|
|
6
|
2
|
|
|
2
|
|
978
|
use Furl; |
|
2
|
|
|
|
|
43097
|
|
|
2
|
|
|
|
|
75
|
|
7
|
2
|
|
|
2
|
|
857
|
use JSON::MaybeXS qw( decode_json encode_json ); |
|
2
|
|
|
|
|
10860
|
|
|
2
|
|
|
|
|
1324
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
0
|
4
|
my ($class, $parent) = @_; |
11
|
1
|
|
|
|
|
2
|
my $token = \$parent->{token}; |
12
|
1
|
|
|
|
|
6
|
Scalar::Util::weaken($token); |
13
|
1
|
|
|
|
|
9
|
bless { |
14
|
|
|
|
|
|
|
parent_token => $token, |
15
|
|
|
|
|
|
|
ua => Furl->new( |
16
|
|
|
|
|
|
|
timeout => 30, |
17
|
|
|
|
|
|
|
ssl_opts => { |
18
|
|
|
|
|
|
|
SSL_verify_mode => SSL_VERIFY_PEER(), |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
), |
21
|
|
|
|
|
|
|
}, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _post { |
25
|
0
|
|
|
0
|
|
0
|
my ($self, $url, $params) = @_; |
26
|
|
|
|
|
|
|
my $res = $self->{ua}->post($url, undef, { |
27
|
0
|
|
|
|
|
0
|
token => ${$self->{parent_token}}, |
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
formato => 'json', |
29
|
|
|
|
|
|
|
%$params, |
30
|
|
|
|
|
|
|
}); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
0
|
if ($res->is_success) { |
33
|
0
|
|
|
|
|
0
|
my $content = decode_json($res->decoded_content); |
34
|
0
|
|
|
|
|
0
|
return $content->{retorno}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
0
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub pesquisar { |
42
|
4
|
|
|
4
|
1
|
3665
|
my ($self, $params) = @_; |
43
|
4
|
100
|
100
|
|
|
51
|
die 'pesquisar() precisa de HASHREF como argumento' |
|
|
|
100
|
|
|
|
|
44
|
|
|
|
|
|
|
unless $params and ref $params and ref $params eq 'HASH'; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
4
|
return $self->_post('https://api.tiny.com.br/api2/notas.fiscais.pesquisa.php', $params); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub obter { |
50
|
3
|
|
|
3
|
1
|
2645
|
my ($self, $id) = @_; |
51
|
3
|
100
|
100
|
|
|
38
|
die 'obter() precisa de argumento "id" numérico' |
52
|
|
|
|
|
|
|
unless $id && $id =~ /^\d+$/; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
6
|
return $self->_post('https://api.tiny.com.br/api2/nota.fiscal.obter.php', { |
55
|
|
|
|
|
|
|
id => $id, |
56
|
|
|
|
|
|
|
}); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub obter_xml { |
60
|
1
|
|
|
1
|
1
|
1336
|
die 'obter_xml() nao foi implementado'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub obter_link { |
64
|
3
|
|
|
3
|
1
|
2642
|
my ($self, $id) = @_; |
65
|
3
|
100
|
100
|
|
|
36
|
die 'obter_link() precisa de argumento "id" numérico' |
66
|
|
|
|
|
|
|
unless $id && $id =~ /^\d+$/; |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
6
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.fiscal.obter.link.php', { |
69
|
|
|
|
|
|
|
id => $id, |
70
|
|
|
|
|
|
|
}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub incluir { |
74
|
4
|
|
|
4
|
1
|
3313
|
my ($self, $params) = @_; |
75
|
4
|
100
|
100
|
|
|
47
|
die 'incluir() precisa de HASHREF como argumento' |
|
|
|
100
|
|
|
|
|
76
|
|
|
|
|
|
|
unless $params and ref $params and ref $params eq 'HASH'; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
17
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.fiscal.incluir.php', { |
79
|
|
|
|
|
|
|
nota => encode_json({ nota_fiscal => $params }), |
80
|
|
|
|
|
|
|
}); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub emitir { |
84
|
3
|
|
|
3
|
1
|
2647
|
my ($self, $params) = @_; |
85
|
3
|
50
|
|
|
|
10
|
if (ref $params) { |
86
|
|
|
|
|
|
|
die 'emitir() precisa de id ou serie/numero da nota' |
87
|
|
|
|
|
|
|
unless ( |
88
|
|
|
|
|
|
|
($params->{id} && $params->{id} =~ /\A\d+\z/) |
89
|
|
|
|
|
|
|
|| ($params->{serie} && $params->{numero}) |
90
|
0
|
0
|
0
|
|
|
0
|
); |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
3
|
|
|
|
|
6
|
my $id = $params; |
94
|
3
|
100
|
100
|
|
|
39
|
die 'emitir() precisa de pelo menos um argumento "id" numérico' |
95
|
|
|
|
|
|
|
unless $id && $id =~ /^\d+$/; |
96
|
1
|
|
|
|
|
5
|
$params = { id => $id }; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
6
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.fiscal.emitir.php', |
100
|
|
|
|
|
|
|
$params |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
__END__ |