| 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
| |||||||||||
| 22 | 0 | ▶ | croak 'Please provide company_id' if !exists $args->{company_id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 27 | 0 | ▶ | croak 'Invalid path' if $path !~ m/\w+/xs; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 47 | 0 | ▶ | croak 'Invalid path' if $path !~ m/\w+/xs; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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 | ||||||||||