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