blib/lib/Net/FattureInCloud.pm

filter: Statementstmt 63.8% 30 / 47 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 2 totaltotal 49.3% 38 / 77 CC 9 SCAR 26.5
CC
9
Cov
49%
crequest
42.0
BUILD
12.0
_validate_method
6.0
CRAP 14.2
↑ Summary
1 1 package Net::FattureInCloud {
2 1 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶ use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use Mojo::Util qw/url_escape url_unescape/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = qv("v0.1.2");
12  
13 0 ▶ has endpoint_uri => ( is => 'ro', default => sub { 'https://api-v2.fattureincloud.it/' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
14 1 has token => ( is => 'ro' );
15 1 has company_id => ( is => 'ro' );
16 0 ▶ has ua => ( is => 'ro', lazy => 1, default => sub { Mojo::UserAgent->new() } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
17  
18 sub BUILD {
19 0 ▶ my ($self, $args) = @_;
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod undocumented
20  
21 0 ▶ croak 'Please provide token' if !exists $args->{token};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"token"} 0 0 0
22 0 ▶ croak 'Please provide company_id' if !exists $args->{company_id};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $args->{"company_id"} 0 0 0
23 }
24  
25 # sub request($self, $request, $method, $args = {}) {
26 # croak 'Please provide request' if !defined $request;
27 # croak 'Invalid request' if $request !~ m/\w+/xs;
28 # $method = $self->_validate_method($method);
29  
30 # my $reqargs = {
31 # %$args,
32 # };
33  
34 # my $res = $self->ua->post( $self->endpoint_uri . "$request/$method"
35 # => {Accept => '*/*'},
36 # json => $reqargs
37 # )->result;
38 # croak $res->message if !$res->is_success;
39  
40 # return $res->json;
41 # }
42  
43 0 ▶ sub crequest($self, $path, $method, $args = {}) {
Subroutine crequest: not called CC=6 SCAR=37.4
Pod undocumented
44 0 ▶ croak 'Please provide path' if !defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
45 0 ▶ croak 'Invalid path' if $path !~ m/\w+/xs;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /\w+/sux 0 0 0
46 0 $method = $self->_validate_method($method);
47  
48 0 my $reqargs = {
49 %$args,
50 };
51  
52 0 ▶ my $datatransport = $method eq 'GET' ? 'form' : 'json';
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'GET' ? : 0 0 0
53  
54 0 my $res = $self->ua->$method( $self->endpoint_uri . 'c/' . $self->company_id . "/$path" =>
55 { Authorization => 'Bearer ' . $self->token },
56 $datatransport => $reqargs
57 )->result;
58 0 ▶ croak $res->message .': ' . $res->body if !$res->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
59  
60 0 return $res->json;
61 }
62  
63 ▶ sub _validate_method($self, $method) {
Subroutine _validate_method: not called CC=2 SCAR=17.9
64 0 ▶ confess 'Invalid-method' if !defined first { $_ eq uc($method) } qw/GET POST PUT DEL/;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined &first(sub { $_ eq uc $method; } , "GET", "POST", "PUT", "DEL") 0 0 0
65 0 return lc $method;
66 }
67 }
68  
69 1 1;
70  
71 =head1 NAME
72  
73 Net::FattureInCloud - Perl library with MINIMAL interface to use FattureInCloud (FIC) API version 2.
74  
75 =head1 SYNOPSIS
76  
77 use Net::FattureInCloud;
78  
79 # TODO
80  
81 =head1 DESCRIPTION
82  
83 This is HIGHLY EXPERIMENTAL and in the works, do not use for now.
84  
85 =head1 AUTHOR
86  
87 Michele Beltrame, C<mb@blendgroup.it>
88  
89 =head1 LICENSE
90  
91 This library is free software under the Artistic License 2.0.
92  
93 =cut
↑ Summary