line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::TinyERP::NotaFiscalServicos; |
2
|
3
|
|
|
3
|
|
24
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
93
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
73
|
|
4
|
3
|
|
|
3
|
|
15
|
use IO::Socket::SSL; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
22
|
|
5
|
3
|
|
|
3
|
|
403
|
use Scalar::Util (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
73
|
|
6
|
3
|
|
|
3
|
|
16
|
use Furl; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
67
|
|
7
|
3
|
|
|
3
|
|
39
|
use JSON::MaybeXS qw( decode_json encode_json ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1971
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
0
|
3
|
my ($class, $parent) = @_; |
11
|
1
|
|
|
|
|
2
|
my $token = \$parent->{token}; |
12
|
1
|
|
|
|
|
6
|
Scalar::Util::weaken($token); |
13
|
1
|
|
|
|
|
7
|
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
|
3735
|
my ($self, $params) = @_; |
43
|
4
|
100
|
100
|
|
|
54
|
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.servico.pesquisa.php', $params); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub obter { |
50
|
3
|
|
|
3
|
1
|
2687
|
my ($self, $id) = @_; |
51
|
3
|
100
|
100
|
|
|
39
|
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.servico.obter.php', { |
55
|
|
|
|
|
|
|
id => $id, |
56
|
|
|
|
|
|
|
}); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub consultar { |
60
|
3
|
|
|
3
|
1
|
2673
|
my ($self, $params) = @_; |
61
|
3
|
50
|
|
|
|
10
|
if (!ref $params) { |
62
|
3
|
|
|
|
|
10
|
$params = { id => $params, enviarEmail => 'N' }; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
die 'obter() precisa de argumento "id" numérico' |
65
|
3
|
100
|
100
|
|
|
37
|
unless ($params->{id} && $params->{id} =~ /\A\d+\z/s); |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
5
|
return $self->_post('https://api.tiny.com.br/api2/nota.servico.consultar.php', |
68
|
|
|
|
|
|
|
$params, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub incluir { |
73
|
4
|
|
|
4
|
1
|
3336
|
my ($self, $params) = @_; |
74
|
4
|
100
|
100
|
|
|
48
|
die 'incluir() precisa de HASHREF como argumento' |
|
|
|
100
|
|
|
|
|
75
|
|
|
|
|
|
|
unless $params and ref $params and ref $params eq 'HASH'; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
13
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.servico.incluir.php', { |
78
|
|
|
|
|
|
|
nota => encode_json({ nota_servico => $params }), |
79
|
|
|
|
|
|
|
}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub emitir { |
84
|
3
|
|
|
3
|
1
|
2634
|
my ($self, $params) = @_; |
85
|
3
|
50
|
|
|
|
9
|
if (!ref $params) { |
86
|
3
|
|
|
|
|
12
|
$params = { id => $params, enviarEmail => 'N' }; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
die 'emitir() precisa de numero de identificação da nota de serviço no Tiny' |
89
|
3
|
100
|
100
|
|
|
37
|
unless ($params->{id} && $params->{id} =~ /\A\d+\z/s); |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
5
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.servico.enviar.php', |
92
|
|
|
|
|
|
|
$params |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
__END__ |