blib/lib/Net/FattureInCloud.pm

filter: Statementstmt 53.5% 30 / 56 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 53.3% 8 / 15 Podpod 0.0% 0 / 3 totaltotal 39.5% 38 / 96 CC 14 SCAR 30.0
CC
14
Cov
38%
request
42.0
crequest
42.0
BUILD
12.0
CRAP 20.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.2.1");
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 0 ▶ sub request($self, $path, $method, $args = {}) {
Subroutine request: not called CC=6 SCAR=37.4
Pod undocumented
26 0 ▶ croak 'Please provide path' if !defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
27 0 ▶ croak 'Invalid path' if $path !~ m/\w+/xs;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /\w+/sux 0 0 0
28 0 $method = $self->_validate_method($method);
29  
30 0 my $reqargs = {
31 %$args,
32 };
33  
34 0 ▶ my $datatransport = $method eq 'get' ? 'form' : 'json';
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'get' ? : 0 0 0
35  
36 0 my $res = $self->ua->$method( $self->endpoint_uri . "$path" =>
37 { Authorization => 'Bearer ' . $self->token },
38 $datatransport => $reqargs
39 )->result;
40 0 ▶ croak $res->message .': ' . $res->body if !$res->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
41  
42 0 return $res->json;
43 }
44  
45 0 ▶ sub crequest($self, $path, $method, $args = {}) {
Subroutine crequest: not called CC=6 SCAR=37.4
Pod undocumented
46 0 ▶ croak 'Please provide path' if !defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
47 0 ▶ croak 'Invalid path' if $path !~ m/\w+/xs;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /\w+/sux 0 0 0
48 0 $method = $self->_validate_method($method);
49  
50 0 my $reqargs = {
51 %$args,
52 };
53  
54 0 ▶ my $datatransport = $method eq 'get' ? 'form' : 'json';
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'get' ? : 0 0 0
55  
56 0 my $res = $self->ua->$method( $self->endpoint_uri . 'c/' . $self->company_id . "/$path" =>
57 { Authorization => 'Bearer ' . $self->token },
58 $datatransport => $reqargs
59 )->result;
60 0 ▶ croak $res->message .': ' . $res->body if !$res->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
61  
62 0 return $res->json;
63 }
64  
65 ▶ sub _validate_method($self, $method) {
Subroutine _validate_method: not called CC=2 SCAR=17.9
66 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
67 0 return lc $method;
68 }
69 }
70  
71 1 1;
72  
73 =head1 NAME
74  
75 Net::FattureInCloud - Perl library with MINIMAL interface to use FattureInCloud (FIC) API version 2.
76  
77 =head1 SYNOPSIS
78  
79 use Net::FattureInCloud;
80  
81 # TODO
82  
83 =head1 DESCRIPTION
84  
85 This is HIGHLY EXPERIMENTAL and in the works, do not use for now.
86  
87 =head1 AUTHOR
88  
89 Michele Beltrame, C<mb@blendgroup.it>
90  
91 =head1 LICENSE
92  
93 This library is free software under the Artistic License 2.0.
94  
95 =cut
↑ Summary