line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Suffit::Client; |
2
|
4
|
|
|
4
|
|
140605
|
use warnings; |
|
4
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
137
|
|
3
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
85
|
|
4
|
4
|
|
|
4
|
|
1262
|
use utf8; |
|
4
|
|
|
|
|
33
|
|
|
4
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=encoding utf-8 |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
WWW::Suffit::Client - The Suffit API client library |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 1.01 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use WWW::Suffit::Client; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $clinet = WWW::Suffit::Client->new( |
21
|
|
|
|
|
|
|
url => "https://localhost", |
22
|
|
|
|
|
|
|
username => "username", # optional |
23
|
|
|
|
|
|
|
password => "password", # optional |
24
|
|
|
|
|
|
|
max_redirects => 2, # Default: 10 |
25
|
|
|
|
|
|
|
connect_timeout => 3, # Default: 10 sec |
26
|
|
|
|
|
|
|
inactivity_timeout => 5, # Default: 30 sec |
27
|
|
|
|
|
|
|
request_timeout => 10, # Default: 5 min (300 sec) |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
my $status = $client->check(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ($status) { |
32
|
|
|
|
|
|
|
print STDOUT $client->res->body; |
33
|
|
|
|
|
|
|
} else { |
34
|
|
|
|
|
|
|
print STDERR $clinet->error; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This library provides methods for access to Suffit API servers |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 API METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
List of predefined the Suffit API methods |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 api_check |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $status = $client->api_check; |
48
|
|
|
|
|
|
|
my $status = $client->api_check( URLorPath ); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Returns API check-status. 0 - Error; 1 - Ok |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 api_data |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $status = $client->api_data; |
55
|
|
|
|
|
|
|
my $status = $client->api_data( URLorPath ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Gets API data |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 api_token |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $status = $client->api_token; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Gets API token |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 authorize |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $status = $client->authorize($username, $password, { |
68
|
|
|
|
|
|
|
encrypted => \0, |
69
|
|
|
|
|
|
|
foo => \1, |
70
|
|
|
|
|
|
|
}); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Performs authorization on the server and returns access token. |
73
|
|
|
|
|
|
|
This is private method! |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
L, L |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 TO DO |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
See C file |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SEE ALSO |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
L, L |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 COPYRIGHT |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Copyright (C) 1998-2023 D&D Corporation. All Rights Reserved |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 LICENSE |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
98
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
See C file and L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
105
|
|
|
|
|
|
|
|
106
|
4
|
|
|
4
|
|
1151
|
use parent qw/ WWW::Suffit::UserAgent /; |
|
4
|
|
|
|
|
647
|
|
|
4
|
|
|
|
|
21
|
|
107
|
|
|
|
|
|
|
|
108
|
4
|
|
|
4
|
|
2025710
|
use WWW::Suffit::Const qw/ :MIME /; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
1553
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
## SUFFIT API COMMON METHODS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub api_check { |
113
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
114
|
0
|
|
0
|
|
|
|
my $url = shift || 'check'; # URL or String (e.g.: api/check) |
115
|
0
|
|
|
|
|
|
my $status = $self->request(GET => $self->str2url($url), |
116
|
|
|
|
|
|
|
{ # Headers |
117
|
|
|
|
|
|
|
Accept => CONTENT_TYPE_JSON, # "*/*" |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
); |
120
|
0
|
0
|
|
|
|
|
return 0 unless $status; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Check API status |
123
|
0
|
0
|
|
|
|
|
return 0 unless $self->res->json("/status"); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Check code |
126
|
0
|
|
0
|
|
|
|
my $error_code = $self->res->json("/code") || 'E0000'; |
127
|
0
|
0
|
|
|
|
|
return 0 unless $error_code eq 'E0000'; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return $status; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
sub api_data { |
132
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
133
|
0
|
|
0
|
|
|
|
my $url = shift || ''; # URL or String (e.g.: api) |
134
|
0
|
|
|
|
|
|
return $self->request(GET => $self->str2url($url), |
135
|
|
|
|
|
|
|
{ # Headers |
136
|
|
|
|
|
|
|
Accept => CONTENT_TYPE_JSON, # "*/*" |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
sub api_token { |
141
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
142
|
0
|
|
|
|
|
|
return $self->request(POST => $self->str2url("user/token"), # e.g.: api/user/token |
143
|
|
|
|
|
|
|
{ # Headers |
144
|
|
|
|
|
|
|
Accept => CONTENT_TYPE_JSON, # "*/*" |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
sub authorize { # System authorization, NO USER PUBLIC method! |
149
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
150
|
0
|
|
|
|
|
|
my $username = shift; |
151
|
0
|
|
|
|
|
|
my $password = shift; |
152
|
0
|
|
0
|
|
|
|
my $options = shift || {}; |
153
|
0
|
0
|
|
|
|
|
$options = {} unless ref $options eq 'HASH'; |
154
|
0
|
0
|
|
|
|
|
$options->{username} = $username if defined $username; |
155
|
0
|
0
|
|
|
|
|
$options->{password} = $password if defined $password; |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return $self->request(POST => $self->str2url("/authorize"), |
158
|
|
|
|
|
|
|
{ # Headers |
159
|
|
|
|
|
|
|
Accept => CONTENT_TYPE_JSON, # "*/*" |
160
|
|
|
|
|
|
|
}, |
161
|
|
|
|
|
|
|
json => $options, |
162
|
|
|
|
|
|
|
); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |