File Coverage

blib/lib/WWW/Suffit/Client/V1.pm
Criterion Covered Total %
statement 18 48 37.5
branch 0 22 0.0
condition 0 6 0.0
subroutine 6 8 75.0
pod 2 2 100.0
total 26 86 30.2


line stmt bran cond sub pod time code
1             package WWW::Suffit::Client::V1;
2 1     1   70207 use warnings;
  1         13  
  1         37  
3 1     1   6 use strict;
  1         2  
  1         33  
4 1     1   638 use utf8;
  1         15  
  1         5  
5              
6             =encoding utf-8
7              
8             =head1 NAME
9              
10             WWW::Suffit::Client::V1 - The Suffit API client library for V1 methods
11              
12             =head1 VERSION
13              
14             Version 1.00
15              
16             =head1 SYNOPSIS
17              
18             use WWW::Suffit::Client::V1;
19              
20             =head1 DESCRIPTION
21              
22             This library provides V1 methods for access to Suffit API servers
23              
24             =head1 API METHODS
25              
26             List of predefined the Suffit API methods
27              
28             =head2 authn
29              
30             my $status = $client->authn($username, $password);
31              
32             Performs user authentication on the OWL system
33              
34             =head2 authz
35              
36             my $status = $client->authz(GET => "https://bob@owl.localhost:8695/stuff");
37             my $status = $client->authz(GET => "https://owl.localhost:8695/stuff",
38             { # Options
39             verbose => \1,
40             username => "bob",
41             address => "127.0.0.1",
42             headers => { # Headers
43             Accept => "text/html,text/plain",
44             Connection => "keep-alive",
45             Host => "owl.localhost:8695",
46             },
47             },
48             );
49              
50             Performs user authorization on the OWL system
51              
52             =head1 DEPENDENCIES
53              
54             L, L
55              
56             =head1 TO DO
57              
58             See C file
59              
60             =head1 SEE ALSO
61              
62             L, L
63              
64             =head1 AUTHOR
65              
66             Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE
67              
68             =head1 COPYRIGHT
69              
70             Copyright (C) 1998-2023 D&D Corporation. All Rights Reserved
71              
72             =head1 LICENSE
73              
74             This program is free software; you can redistribute it and/or
75             modify it under the same terms as Perl itself.
76              
77             See C file and L
78              
79             =cut
80              
81             our $VERSION = '1.00';
82              
83 1     1   497 use parent qw/ WWW::Suffit::Client /;
  1         365  
  1         5  
84              
85 1     1   63 use WWW::Suffit::Const qw/ :MIME /;
  1         2  
  1         90  
86 1     1   622 use WWW::Suffit::RSA;
  1         5509  
  1         8  
87              
88             ## SUFFIT API V1 METHODS
89              
90             sub authn {
91 0     0 1   my $self = shift;
92 0           my $username = shift;
93 0           my $password = shift;
94 0           my $encrypted = 0;
95              
96 0 0         if (length($self->public_key)) {
97 0           my $rsa = WWW::Suffit::RSA->new(public_key => $self->public_key);
98 0           $password = $rsa->encrypt($password); # Encrypt password
99 0 0         if ($rsa->error) {
100 0           $self->error($rsa->error);
101 0           $self->status(0);
102 0           return 0;
103             }
104 0           $encrypted = 1;
105             }
106              
107 0           my %data = ();
108 0 0         $data{username} = $username if defined $username;
109 0 0         $data{password} = $password if defined $password;
110 0           $data{encrypted} = \$encrypted,
111              
112             # Request
113             return $self->request(POST => $self->str2url("v1/authn"),
114             { # Headers
115             Accept => CONTENT_TYPE_JSON, # "*/*"
116             },
117             json => {%data},
118             );
119             }
120             sub authz {
121 0     0 1   my $self = shift;
122 0   0       my $method = shift // '';
123 0   0       my $url = shift // '';
124 0   0       my $options = shift || {};
125 0 0         $options = {} unless ref($options) eq 'HASH';
126 0           my %data = ();
127 0 0         $data{method} = $method if length($method);
128 0 0         $data{url} = $url if length($url);
129 0 0         $data{username} = $options->{username} if exists $options->{username};
130 0 0         $data{verbose} = $options->{verbose} if exists $options->{verbose};
131 0 0         $data{address} = $options->{address} if exists $options->{address};
132 0           my $headers = $options->{headers};
133 0 0         $data{headers} = $headers if ref($headers) eq 'HASH';
134              
135             # Request
136 0           return $self->request(POST => $self->str2url("v1/authz"),
137             { # Headers
138             Accept => CONTENT_TYPE_JSON, # "*/*"
139             },
140             json => {%data},
141             );
142             }
143              
144             1;
145              
146             __END__