File Coverage

blib/lib/WebService/ValidSign/API/Auth.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package WebService::ValidSign::API::Auth;
2             our $VERSION = '0.002';
3 2     2   2682 use Moo;
  2         4  
  2         16  
4              
5             # ABSTRACT: Implementation of the Authentication tokens for ValidSign
6              
7 2     2   764 use Types::Standard qw(Str);
  2         6  
  2         24  
8 2     2   1708 use namespace::autoclean;
  2         4  
  2         13  
9              
10             has action_endpoint => (
11             is => 'ro',
12             default => 'authenticationTokens'
13             );
14              
15             has token => (
16             is => 'rw',
17             isa => Str,
18             accessor => '_token',
19             predicate => 'has_token',
20             );
21              
22             sub token {
23 2     2 0 7642 my $self = shift;
24              
25 2 100       11 if ($self->has_token) {
26 1         17 return $self->_token;
27             }
28             else {
29 1         4 return $self->_get_user_token;
30             }
31             }
32              
33             sub _get_user_token {
34 1     1   2 my $self = shift;
35              
36 1         6 my $uri = $self->get_endpoint($self->action_endpoint, 'user');
37 1         10 my $request = HTTP::Request->new(
38             POST => $uri,
39             [
40             'Content-Type' => 'application/json',
41             Accept => 'application/json',
42             ]
43             );
44              
45 1         193 $request->header("Authorization", join(" ", "Basic", $self->secret));
46              
47 1         80 $self->_token($self->call_api($request)->{value});
48 1         268 return $self->_token;
49             }
50              
51             with "WebService::ValidSign::API";
52             has '+auth' => (required => 0);
53              
54             __PACKAGE__->meta->make_immutable;
55              
56             __END__
57              
58             =pod
59              
60             =encoding UTF-8
61              
62             =head1 NAME
63              
64             WebService::ValidSign::API::Auth - Implementation of the Authentication tokens for ValidSign
65              
66             =head1 VERSION
67              
68             version 0.002
69              
70             =head1 SYNOPSIS
71              
72             =head1 ATTRIBUTES
73              
74             =head1 METHODS
75              
76             =head1 AUTHOR
77              
78             Wesley Schwengle <waterkip@cpan.org>
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This software is Copyright (c) 2019 by Wesley Schwengle.
83              
84             This is free software, licensed under:
85              
86             The (three-clause) BSD License
87              
88             =cut