line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::TinyERP::NotaFiscal; |
2
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
86
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
80
|
|
4
|
3
|
|
|
3
|
|
2565
|
use IO::Socket::SSL; |
|
3
|
|
|
|
|
267987
|
|
|
3
|
|
|
|
|
26
|
|
5
|
3
|
|
|
3
|
|
500
|
use Scalar::Util (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
103
|
|
6
|
3
|
|
|
3
|
|
1600
|
use Furl; |
|
3
|
|
|
|
|
68961
|
|
|
3
|
|
|
|
|
105
|
|
7
|
3
|
|
|
3
|
|
1525
|
use JSON::MaybeXS qw( decode_json encode_json ); |
|
3
|
|
|
|
|
17410
|
|
|
3
|
|
|
|
|
1982
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
0
|
4
|
my ($class, $parent) = @_; |
11
|
1
|
|
|
|
|
3
|
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
|
3800
|
my ($self, $params) = @_; |
43
|
4
|
100
|
100
|
|
|
53
|
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
|
2693
|
my ($self, $id) = @_; |
51
|
3
|
100
|
100
|
|
|
39
|
die 'obter() precisa de argumento "id" numérico' |
52
|
|
|
|
|
|
|
unless $id && $id =~ /^\d+$/; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
7
|
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
|
1378
|
die 'obter_xml() nao foi implementado'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub obter_link { |
64
|
3
|
|
|
3
|
1
|
2664
|
my ($self, $id) = @_; |
65
|
3
|
100
|
100
|
|
|
39
|
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
|
3356
|
my ($self, $params) = @_; |
75
|
4
|
100
|
100
|
|
|
49
|
die 'incluir() precisa de HASHREF como argumento' |
|
|
|
100
|
|
|
|
|
76
|
|
|
|
|
|
|
unless $params and ref $params and ref $params eq 'HASH'; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
14
|
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
|
3034
|
my ($self, $params) = @_; |
85
|
3
|
50
|
|
|
|
11
|
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
|
|
|
|
|
5
|
my $id = $params; |
94
|
3
|
100
|
100
|
|
|
36
|
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
|
|
|
|
|
5
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.fiscal.emitir.php', |
100
|
|
|
|
|
|
|
$params |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
__END__ |