blib/lib/LibreDTE/SDK.pm

filter: Statementstmt 49.0% 25 / 51 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 3 totaltotal 47.6% 31 / 65 CC 2 SCAR 7.9
CC
2
Cov
47%
post
6.0
new
2.0
get
2.0
CRAP 2.2
↑ Summary
1 #
2 # LibreDTE
3 # Copyright (C) SASCO SpA (https://sasco.cl)
4 #
5 # Este programa es software libre: usted puede redistribuirlo y/o modificarlo
6 # bajo los términos de la GNU Lesser General Public License (LGPL) publicada
7 # por la Fundación para el Software Libre, ya sea la versión 3 de la Licencia,
8 # o (a su elección) cualquier versión posterior de la misma.
9 #
10 # Este programa se distribuye con la esperanza de que sea útil, pero SIN
11 # GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD
12 # PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la GNU Lesser General
13 # Public License (LGPL) para obtener una información más detallada.
14 #
15 # Debería haber recibido una copia de la GNU Lesser General Public License
16 # (LGPL) junto a este programa. En caso contrario, consulte
17 # <http://www.gnu.org/licenses/lgpl.html>.
18 #
19  
20 #
21 # SDK para conectar una aplicación en Perl con LibreDTE
22 # @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
23 # @version 2017-02-20
24 #
25  
26 package LibreDTE::SDK;
27  
28 1 ▶use 5.024001;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use REST::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 require Exporter;
36  
37 1 our @ISA = qw(Exporter);
38  
39 # Items to export into callers namespace by default. Note: do not export
40 # names by default without a very good reason. Use EXPORT_OK instead.
41 # Do not simply export all your public functions/methods/constants.
42  
43 # This allows declaration use LibreDTE::SDK ':all';
44 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
45 # will save memory.
46 1 our %EXPORT_TAGS = ( 'all' => [ qw(
47
48 ) ] );
49  
50 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
51  
52 1 our @EXPORT = qw(
53
54 );
55  
56 1 our $VERSION = '0.03';
57  
58 # Constructor de la clase principal del SDK
59 # @param hash Hash de autenticación del usuario
60 # @param host Host con la dirección web base de LibreDTE
61 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $class = shift;
63 0 my $hash = shift;
64 0 my $host = shift;
65 0 my $self = {};
66 0 bless($self, $class);
67 0 $self->{hash} = $hash;
68 0 $self->{host} = $host;
69 0 $self->{rest} = REST::Client->new();
70 0 $self->{rest}->setFollow(1);
71 0 $self->{rest}->addHeader('Authorization', 'Basic '.encode_base64($hash.':X'));
72 0 return $self;
73 }
74  
75 # Método que consume un servicio web de LibreDTE a través de POST
76 # @param api Recurso de la API
77 # @param data Datos que se enviarán por POST
78 0 ▶sub post {
Subroutine post: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my $self = shift;
80 0 my $api = shift;
81 0 my $data = shift;
82 0 my $data_json;
83 0 ▶ if (ref($data) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 0 0 0
84 0 $data_json = encode_json($data);
85 } else {
86 0 $data_json = $data;
87 }
88 0 $self->{rest}->POST($self->{host}.'/api'.$api, $data_json);
89 my %response = (
90 code => $self->{rest}->responseCode(),
91 body => $self->{rest}->responseContent()
92 0 );
93 0 return \%response;
94 }
95  
96 # Método que consume un servicio web de LibreDTE a través de GET
97 # @param api Recurso de la API
98 # @todo Armar query por GET con parámetro 'data'
99 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
100 0 my $self = shift;
101 0 my $api = shift;
102 0 $self->{rest}->GET($self->{host}.'/api'.$api);
103 my %response = (
104 code => $self->{rest}->responseCode(),
105 body => $self->{rest}->responseContent()
106 0 );
107 0 return \%response;
108 }
109  
110 1 1;
111 __END__
↑ Summary