diff --git a/HISTORY.md b/HISTORY.md index d088294..a9493f2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,12 @@ +## [2.10.4](https://github.com/hexonet/perl-sdk/compare/v2.10.3...v2.10.4) (2022-06-10) + + +### Bug Fixes + +* **ci:** remove "." from cpanm args (duplicated by install property) ([322f9a3](https://github.com/hexonet/perl-sdk/commit/322f9a3ac0cac9ee3b4a5a4e1951abbc455ea0a3)) +* **ci:** switch release step to ubuntu image with better nodejs compatibility ([c9c04a5](https://github.com/hexonet/perl-sdk/commit/c9c04a58bfe0f7bd32aa56fa620bf19dd2f9caaa)) +* **dep-bump:** upgrade npm engines, node dependencies and reviewed gh workflow ([da06958](https://github.com/hexonet/perl-sdk/commit/da069585d2370f6a15290f3dce6bf3bdd82bd54c)) + ## [2.10.3](https://github.com/hexonet/perl-sdk/compare/v2.10.2...v2.10.3) (2022-03-23) diff --git a/WebService-Hexonet-Connector-latest.tar.gz b/WebService-Hexonet-Connector-latest.tar.gz index acb7d82..b4811f1 100644 Binary files a/WebService-Hexonet-Connector-latest.tar.gz and b/WebService-Hexonet-Connector-latest.tar.gz differ diff --git a/cover_db/blib-lib-WebService-Hexonet-Connector-APIClient-pm.html b/cover_db/blib-lib-WebService-Hexonet-Connector-APIClient-pm.html index b47fdff..6a5cb13 100644 --- a/cover_db/blib-lib-WebService-Hexonet-Connector-APIClient-pm.html +++ b/cover_db/blib-lib-WebService-Hexonet-Connector-APIClient-pm.html @@ -26,30 +26,30 @@
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::APIClient; | ||||||
2 | |||||||
3 | 1 1 | 8 2 | use 5.030; | ||||
4 | 1 1 1 | 2 1 8 | use strict; | ||||
5 | 1 1 1 | 2 1 17 | use warnings; | ||||
6 | 1 1 1 | 240 7 4 | use utf8; | ||||
7 | 1 1 1 | 291 2 19 | use WebService::Hexonet::Connector::Logger; | ||||
8 | 1 1 1 | 362 1 19 | use WebService::Hexonet::Connector::Response; | ||||
9 | 1 1 1 | 3 1 9 | use WebService::Hexonet::Connector::ResponseTemplateManager; | ||||
10 | 1 1 1 | 330 1 18 | use WebService::Hexonet::Connector::SocketConfig; | ||||
11 | 1 1 1 | 313 23027 20 | use LWP::UserAgent; | ||||
12 | 1 1 1 | 3 1 34 | use Carp; | ||||
13 | 1 1 1 | 2 1 17 | use Readonly; | ||||
14 | 1 1 1 | 2 2 13 | use Data::Dumper; | ||||
15 | 1 1 1 | 3 1 14 | use Config; | ||||
16 | 1 1 1 | 2 2 3 | use POSIX; | ||||
2 | |||||||
3 | 1 1 | 6 3 | use 5.030; | ||||
4 | 1 1 1 | 1 1 8 | use strict; | ||||
5 | 1 1 1 | 2 1 21 | use warnings; | ||||
6 | 1 1 1 | 177 114 2 | use utf8; | ||||
7 | 1 1 1 | 319 1 19 | use WebService::Hexonet::Connector::Logger; | ||||
8 | 1 1 1 | 369 2 22 | use WebService::Hexonet::Connector::Response; | ||||
9 | 1 1 1 | 3 1 11 | use WebService::Hexonet::Connector::ResponseTemplateManager; | ||||
10 | 1 1 1 | 343 2 16 | use WebService::Hexonet::Connector::SocketConfig; | ||||
11 | 1 1 1 | 321 24176 19 | use LWP::UserAgent; | ||||
12 | 1 1 1 | 4 1 37 | use Carp; | ||||
13 | 1 1 1 | 3 1 18 | use Readonly; | ||||
14 | 1 1 1 | 2 1 16 | use Data::Dumper; | ||||
15 | 1 1 1 | 2 1 17 | use Config; | ||||
16 | 1 1 1 | 2 1 4 | use POSIX; | ||||
17 | |||||||
18 | Readonly my $SOCKETTIMEOUT => 300; # 300s or 5 min | ||||||
19 | Readonly my $IDX4 => 4; # Index 4 constant | ||||||
20 | Readonly our $ISPAPI_CONNECTION_URL_OTE => 'https://api-ote.ispapi.net/api/call.cgi'; # OTE Connection Setup URL | ||||||
21 | Readonly our $ISPAPI_CONNECTION_URL_LIVE => 'https://api.ispapi.net/api/call.cgi'; # LIVE Connection Setup URL | ||||||
22 | Readonly our $ISPAPI_CONNECTION_URL_PROXY => 'http://127.0.0.1/api/call.cgi'; # High Speed Connection Setup URL | ||||||
23 | |||||||
24 | our $VERSION = 'v2.10.3'; | ||||||
23 | |||||||
24 | our $VERSION = 'v2.10.4'; | ||||||
25 | |||||||
26 | my $rtm = WebService::Hexonet::Connector::ResponseTemplateManager->getInstance(); | ||||||
27 | |||||||
28 | |||||||
29 | sub new { | ||||||
30 | 2 | 1 | 5 | my $class = shift; | |||
31 | 2 | 5 | my $self = bless { | ||||
30 | 2 | 1 | 4 | my $class = shift; | |||
31 | 2 | 6 | my $self = bless { | ||||
32 | socketURL => $ISPAPI_CONNECTION_URL_LIVE, | ||||||
33 | debugMode => 0, | ||||||
34 | socketConfig => WebService::Hexonet::Connector::SocketConfig->new(), | ||||||
36 | curlopts => {}, | ||||||
37 | logger => WebService::Hexonet::Connector::Logger->new() | ||||||
38 | }, $class; | ||||||
39 | 2 | 14 | $self->setURL($ISPAPI_CONNECTION_URL_LIVE); | ||||
40 | 2 | 4 | $self->useLIVESystem(); | ||||
39 | 2 | 17 | $self->setURL($ISPAPI_CONNECTION_URL_LIVE); | ||||
40 | 2 | 5 | $self->useLIVESystem(); | ||||
41 | 2 | 4 | $self->setDefaultLogger(); | ||||
42 | 2 | 3 | return $self; | ||||
43 | } | ||||||
44 | |||||||
45 | |||||||
46 | sub setDefaultLogger { | ||||||
47 | 2 | 0 | 1 | my $self = shift; | |||
48 | 2 | 3 | $self->{logger} = WebService::Hexonet::Connector::Logger->new(); | ||||
47 | 2 | 0 | 2 | my $self = shift; | |||
48 | 2 | 5 | $self->{logger} = WebService::Hexonet::Connector::Logger->new(); | ||||
49 | 2 | 2 | return $self; | ||||
50 | } | ||||||
51 | |||||||
52 | |||||||
53 | sub setCustomLogger { | ||||||
58 | 0 | 0 | return $self; | ||||
59 | } | ||||||
60 | |||||||
61 | |||||||
62 | sub enableDebugMode { | ||||||
63 | 2 | 1 | 275 | my $self = shift; | |||
64 | 2 | 4 | $self->{debugMode} = 1; | ||||
63 | 2 | 1 | 263 | my $self = shift; | |||
64 | 2 | 5 | $self->{debugMode} = 1; | ||||
65 | 2 | 3 | return $self; | ||||
66 | } | ||||||
67 | |||||||
68 | |||||||
69 | sub disableDebugMode { | ||||||
70 | 2 | 1 | 5 | my $self = shift; | |||
71 | 2 | 2 | $self->{debugMode} = 0; | ||||
72 | 2 | 3 | return $self; | ||||
70 | 2 | 1 | 4 | my $self = shift; | |||
71 | 2 | 3 | $self->{debugMode} = 0; | ||||
72 | 2 | 2 | return $self; | ||||
73 | } | ||||||
74 | |||||||
75 | |||||||
76 | sub getPOSTData { | ||||||
77 | 52 | 1 | 754 | my ( $self, $cmd, $secured ) = @_; | |||
78 | 52 | 104 | my $post = $self->{socketConfig}->getPOSTData(); | ||||
79 | 52 | 108 | if ( defined($secured) && $secured == 1 ) { | ||||
80 | 19 | 24 | $post->{s_pw} = '***'; | ||||
77 | 52 | 1 | 745 | my ( $self, $cmd, $secured ) = @_; | |||
78 | 52 | 116 | my $post = $self->{socketConfig}->getPOSTData(); | ||||
79 | 52 | 115 | if ( defined($secured) && $secured == 1 ) { | ||||
80 | 19 | 28 | $post->{s_pw} = '***'; | ||||
81 | } | ||||||
82 | 52 | 44 | my $tmp = q{}; | ||||
83 | 52 | 68 | if ( ( ref $cmd ) eq 'HASH' ) { | ||||
84 | 51 51 | 46 96 | foreach my $key ( sort keys %{$cmd} ) { | ||||
85 | 97 | 113 | if ( defined $cmd->{$key} ) { | ||||
86 | 96 | 93 | my $val = $cmd->{$key}; | ||||
87 | 96 | 98 | $val =~ s/[\r\n]//msx; | ||||
88 | 96 | 120 | $tmp .= "${key}=${val}\n"; | ||||
82 | 52 | 56 | my $tmp = q{}; | ||||
83 | 52 | 79 | if ( ( ref $cmd ) eq 'HASH' ) { | ||||
84 | 51 51 | 46 105 | foreach my $key ( sort keys %{$cmd} ) { | ||||
85 | 97 | 111 | if ( defined $cmd->{$key} ) { | ||||
86 | 96 | 91 | my $val = $cmd->{$key}; | ||||
87 | 96 | 110 | $val =~ s/[\r\n]//msx; | ||||
88 | 96 | 122 | $tmp .= "${key}=${val}\n"; | ||||
89 | } | ||||||
90 | } | ||||||
91 | } else { | ||||||
92 | 1 | 2 | $tmp = $cmd; | ||||
93 | } | ||||||
94 | 52 | 84 | if ( defined($secured) && $secured == 1 ) { | ||||
95 | 19 | 35 | $tmp =~ s/PASSWORD\=[^\n]+/PASSWORD=***/gmsx; | ||||
94 | 52 | 103 | if ( defined($secured) && $secured == 1 ) { | ||||
95 | 19 | 39 | $tmp =~ s/PASSWORD\=[^\n]+/PASSWORD=***/gmsx; | ||||
96 | } | ||||||
97 | 52 | 98 | $tmp =~ s/\n$//msx; | ||||
98 | 52 | 87 | if ( utf8::is_utf8($tmp) ) { | ||||
99 | 2 | 3 | utf8::encode($tmp); | ||||
97 | 52 | 116 | $tmp =~ s/\n$//msx; | ||||
98 | 52 | 90 | if ( utf8::is_utf8($tmp) ) { | ||||
99 | 2 | 4 | utf8::encode($tmp); | ||||
100 | } | ||||||
101 | 52 | 66 | $post->{'s_command'} = $tmp; | ||||
102 | 52 | 64 | return $post; | ||||
101 | 52 | 63 | $post->{'s_command'} = $tmp; | ||||
102 | 52 | 65 | return $post; | ||||
103 | } | ||||||
104 | |||||||
105 | |||||||
106 | sub getSession { | ||||||
107 | 2 | 1 | 4 | my $self = shift; | |||
108 | 2 | 4 | my $sessid = $self->{socketConfig}->getSession(); | ||||
109 | 2 | 3 | if ( length $sessid ) { | ||||
110 | 1 | 2 | return $sessid; | ||||
107 | 2 | 1 | 5 | my $self = shift; | |||
108 | 2 | 5 | my $sessid = $self->{socketConfig}->getSession(); | ||||
109 | 2 | 4 | if ( length $sessid ) { | ||||
110 | 1 | 3 | return $sessid; | ||||
111 | } | ||||||
112 | 1 | 2 | return; | ||||
112 | 1 | 1 | return; | ||||
113 | } | ||||||
114 | |||||||
115 | |||||||
116 | sub getURL { | ||||||
117 | 5 | 1 | 10 | my $self = shift; | |||
118 | 5 | 7 | return $self->{socketURL}; | ||||
117 | 5 | 1 | 49 | my $self = shift; | |||
118 | 5 | 10 | return $self->{socketURL}; | ||||
119 | } | ||||||
120 | |||||||
121 | |||||||
122 | sub getUserAgent { | ||||||
123 | 21 | 1 | 37 | my $self = shift; | |||
124 | 21 | 44 | if ( !( length $self->{ua} ) ) { | ||||
125 | 1 | 7 | my $arch = (POSIX::uname)[ $IDX4 ]; | ||||
126 | 1 | 6 | my $os = (POSIX::uname)[ 0 ]; | ||||
127 | 1 | 3 | my $rv = $self->getVersion(); | ||||
128 | 1 | 9 | $self->{ua} = "PERL-SDK ($os; $arch; rv:$rv) perl/$Config{version}"; | ||||
123 | 21 | 1 | 43 | my $self = shift; | |||
124 | 21 | 56 | if ( !( length $self->{ua} ) ) { | ||||
125 | 1 | 8 | my $arch = (POSIX::uname)[ $IDX4 ]; | ||||
126 | 1 | 7 | my $os = (POSIX::uname)[ 0 ]; | ||||
127 | 1 | 2 | my $rv = $self->getVersion(); | ||||
128 | 1 | 10 | $self->{ua} = "PERL-SDK ($os; $arch; rv:$rv) perl/$Config{version}"; | ||||
129 | } | ||||||
130 | 21 | 42 | return $self->{ua}; | ||||
130 | 21 | 46 | return $self->{ua}; | ||||
131 | } | ||||||
132 | |||||||
133 | |||||||
134 | sub setUserAgent { | ||||||
135 | 2 | 1 | 915 | my ( $self, $str, $rv, $modules ) = @_; | |||
136 | 2 | 7 | my $arch = (POSIX::uname)[ $IDX4 ]; | ||||
137 | 2 | 9 | my $os = (POSIX::uname)[ 0 ]; | ||||
135 | 2 | 1 | 969 | my ( $self, $str, $rv, $modules ) = @_; | |||
136 | 2 | 13 | my $arch = (POSIX::uname)[ $IDX4 ]; | ||||
137 | 2 | 10 | my $os = (POSIX::uname)[ 0 ]; | ||||
138 | 2 | 4 | my $rv2 = $self->getVersion(); | ||||
139 | 2 | 2 | my $mods = q{}; | ||||
140 | 2 | 8 | if ( defined $modules && length($modules) > 0 ) { | ||||
141 | 1 1 | 1 2 | $mods = q{ } . join q{ }, @{$modules}; | ||||
139 | 2 | 3 | my $mods = q{}; | ||||
140 | 2 | 7 | if ( defined $modules && length($modules) > 0 ) { | ||||
141 | 1 1 | 2 2 | $mods = q{ } . join q{ }, @{$modules}; | ||||
142 | } | ||||||
143 | 2 | 6 | $self->{ua} = "$str ($os; $arch; rv:$rv)$mods perl-sdk/$rv2 perl/$Config{version}"; | ||||
144 | 2 | 8 | return $self; | ||||
143 | 2 | 8 | $self->{ua} = "$str ($os; $arch; rv:$rv)$mods perl-sdk/$rv2 perl/$Config{version}"; | ||||
144 | 2 | 7 | return $self; | ||||
145 | } | ||||||
146 | |||||||
147 | |||||||
148 | sub getProxy { | ||||||
149 | 20 | 1 | 28 | my ($self) = @_; | |||
150 | 20 | 36 | if ( exists $self->{curlopts}->{'PROXY'} ) { | ||||
151 | 1 | 2 | return $self->{curlopts}->{'PROXY'}; | ||||
149 | 20 | 1 | 57 | my ($self) = @_; | |||
150 | 20 | 46 | if ( exists $self->{curlopts}->{'PROXY'} ) { | ||||
151 | 1 | 4 | return $self->{curlopts}->{'PROXY'}; | ||||
152 | } | ||||||
153 | 19 | 26 | return; | ||||
154 | } | ||||||
155 | |||||||
156 | |||||||
157 | sub setProxy { | ||||||
158 | 2 | 1 | 4 | my ( $self, $proxy ) = @_; | |||
159 | 2 | 3 | if ( length($proxy) == 0 ) { | ||||
160 | 1 | 2 | delete $self->{curlopts}->{'PROXY'}; | ||||
158 | 2 | 1 | 2 | my ( $self, $proxy ) = @_; | |||
159 | 2 | 5 | if ( length($proxy) == 0 ) { | ||||
160 | 1 | 1 | delete $self->{curlopts}->{'PROXY'}; | ||||
161 | } else { | ||||||
162 | 1 | 2 | $self->{curlopts}->{'PROXY'} = $proxy; | ||||
163 | } | ||||||
164 | 2 | 2 | return $self; | ||||
165 | } | ||||||
166 | |||||||
167 | |||||||
168 | sub getReferer { | ||||||
169 | 20 | 1 | 37 | my ($self) = @_; | |||
170 | 20 | 45 | if ( exists $self->{curlopts}->{'REFERER'} ) { | ||||
169 | 20 | 1 | 36 | my ($self) = @_; | |||
170 | 20 | 50 | if ( exists $self->{curlopts}->{'REFERER'} ) { | ||||
171 | 1 | 3 | return $self->{curlopts}->{'REFERER'}; | ||||
172 | } | ||||||
173 | 19 | 27 | return; | ||||
173 | 19 | 30 | return; | ||||
174 | } | ||||||
175 | |||||||
176 | |||||||
177 | sub setReferer { | ||||||
178 | 2 | 1 | 326 | my ( $self, $referer ) = @_; | |||
179 | 2 | 41 | if ( length($referer) == 0 ) { | ||||
178 | 2 | 1 | 342 | my ( $self, $referer ) = @_; | |||
179 | 2 | 4 | if ( length($referer) == 0 ) { | ||||
180 | 1 | 1 | delete $self->{curlopts}->{'REFERER'}; | ||||
181 | } else { | ||||||
182 | 1 | 2 | $self->{curlopts}->{'REFERER'} = $referer; | ||||
182 | 1 | 3 | $self->{curlopts}->{'REFERER'} = $referer; | ||||
183 | } | ||||||
184 | 2 | 3 | return $self; | ||||
185 | } | ||||||
186 | |||||||
187 | |||||||
188 | sub getVersion { | ||||||
189 | 4 | 1 | 11 | my $self = shift; | |||
189 | 4 | 1 | 15 | my $self = shift; | |||
190 | 4 | 7 | return $VERSION; | ||||
191 | } | ||||||
192 | |||||||
193 | |||||||
194 | sub saveSession { | ||||||
196 | $session->{socketcfg} = { | ||||||
197 | entity => $self->{socketConfig}->getSystemEntity(), | ||||||
198 | session => $self->{socketConfig}->getSession() | ||||||
199 | 1 | 2 | }; | ||||
199 | 1 | 3 | }; | ||||
200 | 1 | 2 | return $self; | ||||
201 | } | ||||||
202 | |||||||
203 | |||||||
204 | sub reuseSession { | ||||||
205 | 1 | 1 | 2 | my ( $self, $session ) = @_; | |||
206 | 1 | 4 | $self->{socketConfig}->setSystemEntity( $session->{socketcfg}->{entity} ); | ||||
207 | 1 | 2 | $self->setSession( $session->{socketcfg}->{session} ); | ||||
205 | 1 | 1 | 3 | my ( $self, $session ) = @_; | |||
206 | 1 | 2 | $self->{socketConfig}->setSystemEntity( $session->{socketcfg}->{entity} ); | ||||
207 | 1 | 3 | $self->setSession( $session->{socketcfg}->{session} ); | ||||
208 | 1 | 1 | return $self; | ||||
209 | } | ||||||
210 | |||||||
211 | |||||||
212 | sub setURL { | ||||||
213 | 11 | 1 | 284 | my ( $self, $value ) = @_; | |||
214 | 11 | 33 | $self->{socketURL} = $value; | ||||
215 | 11 | 10 | return $self; | ||||
213 | 11 | 1 | 302 | my ( $self, $value ) = @_; | |||
214 | 11 | 30 | $self->{socketURL} = $value; | ||||
215 | 11 | 14 | return $self; | ||||
216 | } | ||||||
217 | |||||||
218 | |||||||
219 | sub setOTP { | ||||||
220 | 7 | 1 | 351 | my ( $self, $value ) = @_; | |||
221 | 7 | 17 | $self->{socketConfig}->setOTP($value); | ||||
222 | 7 | 6 | return $self; | ||||
220 | 7 | 1 | 340 | my ( $self, $value ) = @_; | |||
221 | 7 | 22 | $self->{socketConfig}->setOTP($value); | ||||
222 | 7 | 9 | return $self; | ||||
223 | } | ||||||
224 | |||||||
225 | |||||||
226 | sub setSession { | ||||||
227 | 12 | 1 | 1779 | my ( $self, $value ) = @_; | |||
228 | 12 | 28 | $self->{socketConfig}->setSession($value); | ||||
229 | 12 | 44 | return $self; | ||||
227 | 12 | 1 | 1818 | my ( $self, $value ) = @_; | |||
228 | 12 | 32 | $self->{socketConfig}->setSession($value); | ||||
229 | 12 | 13 | return $self; | ||||
230 | } | ||||||
231 | |||||||
232 | |||||||
233 | sub setRemoteIPAddress { | ||||||
234 | 3 | 1 | 313 | my ( $self, $value ) = @_; | |||
235 | 3 | 5 | $self->{socketConfig}->setRemoteAddress($value); | ||||
234 | 3 | 1 | 309 | my ( $self, $value ) = @_; | |||
235 | 3 | 8 | $self->{socketConfig}->setRemoteAddress($value); | ||||
236 | 3 | 3 | return $self; | ||||
237 | } | ||||||
238 | |||||||
239 | |||||||
240 | sub setCredentials { | ||||||
241 | 11 | 1 | 936 | my ( $self, $uid, $pw ) = @_; | |||
242 | 11 | 25 | $self->{socketConfig}->setLogin($uid); | ||||
243 | 11 | 21 | $self->{socketConfig}->setPassword($pw); | ||||
244 | 11 | 10 | return $self; | ||||
241 | 11 | 1 | 922 | my ( $self, $uid, $pw ) = @_; | |||
242 | 11 | 30 | $self->{socketConfig}->setLogin($uid); | ||||
243 | 11 | 25 | $self->{socketConfig}->setPassword($pw); | ||||
244 | 11 | 11 | return $self; | ||||
245 | } | ||||||
246 | |||||||
247 | |||||||
248 | sub setRoleCredentials { | ||||||
249 | 3 | 1 | 917 | my ( $self, $uid, $role, $pw ) = @_; | |||
250 | 3 | 5 | my $myuid = "${uid}!${role}"; | ||||
251 | 3 | 3 | $myuid =~ s/^\!$//msx; | ||||
252 | 3 | 4 | return $self->setCredentials( $myuid, $pw ); | ||||
249 | 3 | 1 | 911 | my ( $self, $uid, $role, $pw ) = @_; | |||
250 | 3 | 4 | my $myuid = "${uid}!${role}"; | ||||
251 | 3 | 5 | $myuid =~ s/^\!$//msx; | ||||
252 | 3 | 5 | return $self->setCredentials( $myuid, $pw ); | ||||
253 | } | ||||||
254 | |||||||
255 | |||||||
256 | sub login { | ||||||
257 | 3 | 1 | 7 | my $self = shift; | |||
258 | 3 | 3 | my $otp = shift; | ||||
259 | 3 | 13 | $self->setOTP( $otp || q{} ); | ||||
260 | 3 | 8 | my $rr = $self->request( { COMMAND => 'StartSession' } ); | ||||
261 | 3 | 10 | if ( $rr->isSuccess() ) { | ||||
262 | 1 | 2 | my $col = $rr->getColumn('SESSION'); | ||||
263 | 1 | 2 | my $sessid = q{}; | ||||
264 | 1 | 2 | if ( defined $col ) { | ||||
265 | 1 | 2 | my @d = $col->getData(); | ||||
266 | 1 | 1 | $sessid = $d[ 0 ]; | ||||
257 | 3 | 1 | 11 | my $self = shift; | |||
258 | 3 | 6 | my $otp = shift; | ||||
259 | 3 | 14 | $self->setOTP( $otp || q{} ); | ||||
260 | 3 | 13 | my $rr = $self->request( { COMMAND => 'StartSession' } ); | ||||
261 | 3 | 17 | if ( $rr->isSuccess() ) { | ||||
262 | 1 | 4 | my $col = $rr->getColumn('SESSION'); | ||||
263 | 1 | 1 | my $sessid = q{}; | ||||
264 | 1 | 4 | if ( defined $col ) { | ||||
265 | 1 | 3 | my @d = $col->getData(); | ||||
266 | 1 | 3 | $sessid = $d[ 0 ]; | ||||
267 | } | ||||||
268 | 1 | 4 | $self->setSession($sessid); | ||||
268 | 1 | 3 | $self->setSession($sessid); | ||||
269 | } | ||||||
270 | 3 | 28 | return $rr; | ||||
270 | 3 | 36 | return $rr; | ||||
271 | } | ||||||
272 | |||||||
273 | |||||||
274 | sub loginExtended { | ||||||
275 | 1 | 1 | 1 | my $self = shift; | |||
275 | 1 | 1 | 2 | my $self = shift; | |||
276 | 1 | 2 | my $params = shift; | ||||
277 | 1 | 1 | my $otpc = shift; | ||||
278 | 1 | 3 | if ( !defined $otpc ) { | ||||
277 | 1 | 2 | my $otpc = shift; | ||||
278 | 1 | 11 | if ( !defined $otpc ) { | ||||
279 | 1 | 2 | $otpc = q{}; | ||||
280 | } | ||||||
281 | 1 | 3 | $self->setOTP($otpc); | ||||
282 | 1 | 2 | my $cmd = { COMMAND => 'StartSession' }; | ||||
283 | 1 1 | 2 2 | foreach my $key ( keys %{$params} ) { | ||||
282 | 1 | 3 | my $cmd = { COMMAND => 'StartSession' }; | ||||
283 | 1 1 | 2 4 | foreach my $key ( keys %{$params} ) { | ||||
284 | 1 | 2 | $cmd->{$key} = $params->{$key}; | ||||
285 | } | ||||||
286 | 1 | 2 | my $rr = $self->request($cmd); | ||||
287 | 1 | 229 | if ( $rr->isSuccess() ) { | ||||
288 | 1 | 2 | my $col = $rr->getColumn('SESSION'); | ||||
286 | 1 | 3 | my $rr = $self->request($cmd); | ||||
287 | 1 | 4 | if ( $rr->isSuccess() ) { | ||||
288 | 1 | 376 | my $col = $rr->getColumn('SESSION'); | ||||
289 | 1 | 2 | my $sessid = q{}; | ||||
290 | 1 | 2 | if ( defined $col ) { | ||||
291 | 1 | 3 | my @d = $col->getData(); | ||||
292 | 1 | 1 | $sessid = $d[ 0 ]; | ||||
290 | 1 | 5 | if ( defined $col ) { | ||||
291 | 1 | 2 | my @d = $col->getData(); | ||||
292 | 1 | 2 | $sessid = $d[ 0 ]; | ||||
293 | } | ||||||
294 | 1 | 3 | $self->setSession($sessid); | ||||
294 | 1 | 5 | $self->setSession($sessid); | ||||
295 | } | ||||||
296 | 1 | 5 | return $rr; | ||||
296 | 1 | 8 | return $rr; | ||||
297 | } | ||||||
298 | |||||||
299 | |||||||
300 | sub logout { | ||||||
301 | 2 | 1 | 3 | my $self = shift; | |||
302 | 2 | 6 | my $rr = $self->request( { COMMAND => 'EndSession' } ); | ||||
303 | 2 | 6 | if ( $rr->isSuccess() ) { | ||||
304 | 1 | 3 | $self->setSession(q{}); | ||||
302 | 2 | 8 | my $rr = $self->request( { COMMAND => 'EndSession' } ); | ||||
303 | 2 | 9 | if ( $rr->isSuccess() ) { | ||||
304 | 1 | 4 | $self->setSession(q{}); | ||||
305 | } | ||||||
306 | 2 | 14 | return $rr; | ||||
306 | 2 | 16 | return $rr; | ||||
307 | } | ||||||
308 | |||||||
309 | |||||||
310 | sub request { | ||||||
311 | 18 | 1 | 32 | my ( $self, $cmd ) = @_; | |||
311 | 18 | 1 | 42 | my ( $self, $cmd ) = @_; | |||
312 | # flatten nested api command bulk parameters | ||||||
313 | 18 | 42 | my $newcmd = $self->_flattenCommand($cmd); | ||||
313 | 18 | 53 | my $newcmd = $self->_flattenCommand($cmd); | ||||
314 | # auto convert umlaut names to punycode | ||||||
315 | 18 | 34 | $newcmd = $self->_autoIDNConvert($newcmd); | ||||
315 | 18 | 45 | $newcmd = $self->_autoIDNConvert($newcmd); | ||||
316 | |||||||
317 | # request command to API | ||||||
318 | 18 | 39 | my $cfg = { CONNECTION_URL => $self->{socketURL} }; | ||||
319 | 18 | 39 | my $post = $self->getPOSTData($newcmd); | ||||
320 | 18 | 23 | my $secured = $self->getPOSTData( $newcmd, 1 ); | ||||
321 | |||||||
322 | 18 | 75 | my $ua = LWP::UserAgent->new(); | ||||
323 | 18 | 4755 | $ua->agent( $self->getUserAgent() ); | ||||
324 | 18 | 619 | $ua->default_header( 'Expect', q{} ); | ||||
325 | 18 | 474 | $ua->timeout($SOCKETTIMEOUT); | ||||
326 | 18 | 240 | my $referer = $self->getReferer(); | ||||
327 | 18 | 29 | if ($referer) { | ||||
318 | 18 | 51 | my $cfg = { CONNECTION_URL => $self->{socketURL} }; | ||||
319 | 18 | 47 | my $post = $self->getPOSTData($newcmd); | ||||
320 | 18 | 34 | my $secured = $self->getPOSTData( $newcmd, 1 ); | ||||
321 | |||||||
322 | 18 | 105 | my $ua = LWP::UserAgent->new(); | ||||
323 | 18 | 5215 | $ua->agent( $self->getUserAgent() ); | ||||
324 | 18 | 643 | $ua->default_header( 'Expect', q{} ); | ||||
325 | 18 | 481 | $ua->timeout($SOCKETTIMEOUT); | ||||
326 | 18 | 258 | my $referer = $self->getReferer(); | ||||
327 | 18 | 40 | if ($referer) { | ||||
328 | 0 | 0 | $ua->default_header( 'Referer', $referer ); | ||||
329 | } | ||||||
330 | 18 | 34 | my $proxy = $self->getProxy(); | ||||
331 | 18 | 25 | if ($proxy) { | ||||
330 | 18 | 46 | my $proxy = $self->getProxy(); | ||||
331 | 18 | 33 | if ($proxy) { | ||||
332 | 0 | 0 | $ua->proxy( [ 'http', 'https' ], $proxy ); | ||||
333 | } | ||||||
334 | |||||||
335 | 18 | 42 | my $r = $ua->post( $cfg->{CONNECTION_URL}, $post ); | ||||
336 | 18 | 13500095 | if ( $r->is_success ) { | ||||
337 | 17 | 169 | $r = WebService::Hexonet::Connector::Response->new( $r->decoded_content, $newcmd, $cfg ); | ||||
338 | 17 | 54 | if ( $self->{debugMode} ) { | ||||
339 | 2 | 8 | $self->{logger}->log( $secured, $r ); | ||||
334 | |||||||
335 | 18 | 53 | my $r = $ua->post( $cfg->{CONNECTION_URL}, $post ); | ||||
336 | 18 | 10367470 | if ( $r->is_success ) { | ||||
337 | 17 | 196 | $r = WebService::Hexonet::Connector::Response->new( $r->decoded_content, $newcmd, $cfg ); | ||||
338 | 17 | 69 | if ( $self->{debugMode} ) { | ||||
339 | 2 | 11 | $self->{logger}->log( $secured, $r ); | ||||
340 | } | ||||||
341 | } else { | ||||||
342 | 1 | 9 | $r = WebService::Hexonet::Connector::Response->new( $rtm->getTemplate('httperror')->getPlain(), $newcmd, $cfg ); | ||||
343 | 1 | 11 | if ( $self->{debugMode} ) { | ||||
342 | 1 | 13 | $r = WebService::Hexonet::Connector::Response->new( $rtm->getTemplate('httperror')->getPlain(), $newcmd, $cfg ); | ||||
343 | 1 | 9 | if ( $self->{debugMode} ) { | ||||
344 | 0 | 0 | $self->{logger}->log( $secured, $r, $r->status_line ); | ||||
345 | } | ||||||
346 | } | ||||||
347 | 18 | 346 | return $r; | ||||
347 | 18 | 467 | return $r; | ||||
348 | } | ||||||
349 | |||||||
350 | |||||||
351 | sub requestNextResponsePage { | ||||||
352 | 7 | 1 | 18 | my ( $self, $rr ) = @_; | |||
353 | 7 | 16 | my $mycmd = $rr->getCommand(); | ||||
354 | 7 | 20 | if ( defined $mycmd->{LAST} ) { | ||||
352 | 7 | 1 | 21 | my ( $self, $rr ) = @_; | |||
353 | 7 | 18 | my $mycmd = $rr->getCommand(); | ||||
354 | 7 | 17 | if ( defined $mycmd->{LAST} ) { | ||||
355 | 0 | 0 | croak 'Parameter LAST in use! Please remove it to avoid issues in requestNextPage.'; | ||||
356 | } | ||||||
357 | 7 | 9 | my $first = 0; | ||||
358 | 7 | 14 | if ( defined $mycmd->{FIRST} ) { | ||||
359 | 6 | 8 | $first = $mycmd->{FIRST}; | ||||
357 | 7 | 12 | my $first = 0; | ||||
358 | 7 | 17 | if ( defined $mycmd->{FIRST} ) { | ||||
359 | 6 | 10 | $first = $mycmd->{FIRST}; | ||||
360 | } | ||||||
361 | 7 | 17 | my $total = $rr->getRecordsTotalCount(); | ||||
362 | 7 | 16 | my $limit = $rr->getRecordsLimitation(); | ||||
363 | 7 | 12 | $first += $limit; | ||||
364 | 7 | 18 | if ( $first < $total ) { | ||||
365 | 6 | 7 | $mycmd->{FIRST} = $first; | ||||
366 | 6 | 7 | $mycmd->{LIMIT} = $limit; | ||||
367 | 6 | 11 | return $self->request($mycmd); | ||||
361 | 7 | 24 | my $total = $rr->getRecordsTotalCount(); | ||||
362 | 7 | 19 | my $limit = $rr->getRecordsLimitation(); | ||||
363 | 7 | 13 | $first += $limit; | ||||
364 | 7 | 17 | if ( $first < $total ) { | ||||
365 | 6 | 10 | $mycmd->{FIRST} = $first; | ||||
366 | 6 | 11 | $mycmd->{LIMIT} = $limit; | ||||
367 | 6 | 17 | return $self->request($mycmd); | ||||
368 | } | ||||||
369 | 1 | 3 | return; | ||||
370 | } | ||||||
371 | |||||||
372 | |||||||
373 | sub requestAllResponsePages { | ||||||
374 | 1 | 1 | 6 | my ( $self, $cmd ) = @_; | |||
375 | 1 | 1 | my @responses = (); | ||||
376 | 1 | 2 | my $command = {}; | ||||
377 | 1 1 | 1 2 | foreach my $key ( keys %{$cmd} ) { | ||||
374 | 1 | 1 | 8 | my ( $self, $cmd ) = @_; | |||
375 | 1 | 2 | my @responses = (); | ||||
376 | 1 | 1 | my $command = {}; | ||||
377 | 1 1 | 2 2 | foreach my $key ( keys %{$cmd} ) { | ||||
378 | 3 | 5 | $command->{$key} = $cmd->{$key}; | ||||
379 | } | ||||||
380 | 1 | 2 | $command->{FIRST} = 0; | ||||
381 | 1 | 2 | my $rr = $self->request($command); | ||||
382 | 1 | 1 | my $tmp = $rr; | ||||
380 | 1 | 1 | $command->{FIRST} = 0; | ||||
381 | 1 | 4 | my $rr = $self->request($command); | ||||
382 | 1 | 2 | my $tmp = $rr; | ||||
383 | 1 | 2 | my $idx = 0; | ||||
384 | 1 | 3 | while ( defined $tmp ) { | ||||
385 | 5 | 7 | push @responses, $tmp; | ||||
386 | 5 | 12 | $tmp = $self->requestNextResponsePage($tmp); | ||||
384 | 1 | 2 | while ( defined $tmp ) { | ||||
385 | 5 | 10 | push @responses, $tmp; | ||||
386 | 5 | 20 | $tmp = $self->requestNextResponsePage($tmp); | ||||
387 | } | ||||||
388 | 1 | 17 | return \@responses; | ||||
388 | 1 | 20 | return \@responses; | ||||
389 | } | ||||||
390 | |||||||
391 | |||||||
392 | sub setUserView { | ||||||
393 | 1 | 1 | 619 | my ( $self, $uid ) = @_; | |||
394 | 1 | 5 | $self->{socketConfig}->setUser($uid); | ||||
393 | 1 | 1 | 716 | my ( $self, $uid ) = @_; | |||
394 | 1 | 7 | $self->{socketConfig}->setUser($uid); | ||||
395 | 1 | 1 | return $self; | ||||
396 | } | ||||||
397 | |||||||
398 | |||||||
399 | sub resetUserView { | ||||||
400 | 1 | 1 | 1 | my $self = shift; | |||
401 | 1 | 5 | $self->{socketConfig}->setUser(q{}); | ||||
401 | 1 | 6 | $self->{socketConfig}->setUser(q{}); | ||||
402 | 1 | 1 | return $self; | ||||
403 | } | ||||||
404 | |||||||
405 | |||||||
406 | sub useDefaultConnectionSetup { | ||||||
407 | 1 | 1 | 323 | my $self = shift; | |||
407 | 1 | 1 | 348 | my $self = shift; | |||
408 | 1 | 2 | return $self->setURL($ISPAPI_CONNECTION_URL_LIVE); | ||||
409 | } | ||||||
410 | |||||||
411 | |||||||
412 | sub useHighPerformanceConnectionSetup { | ||||||
413 | 1 | 1 | 333 | my $self = shift; | |||
414 | 1 | 2 | return $self->setURL($ISPAPI_CONNECTION_URL_PROXY); | ||||
413 | 1 | 1 | 386 | my $self = shift; | |||
414 | 1 | 3 | return $self->setURL($ISPAPI_CONNECTION_URL_PROXY); | ||||
415 | } | ||||||
416 | |||||||
417 | |||||||
418 | sub useOTESystem { | ||||||
419 | 1 | 0 | 297 | my $self = shift; | |||
419 | 1 | 0 | 302 | my $self = shift; | |||
420 | 1 | 3 | $self->setURL($ISPAPI_CONNECTION_URL_OTE); | ||||
421 | 1 | 3 | $self->{socketConfig}->setSystemEntity('1234'); | ||||
421 | 1 | 2 | $self->{socketConfig}->setSystemEntity('1234'); | ||||
422 | 1 | 1 | return $self; | ||||
423 | } | ||||||
424 | |||||||
425 | |||||||
426 | sub useLIVESystem { | ||||||
427 | 2 | 1 | 2 | my $self = shift; | |||
428 | 2 | 5 | $self->setURL($ISPAPI_CONNECTION_URL_LIVE); | ||||
429 | 2 | 5 | $self->{socketConfig}->setSystemEntity('54cd'); | ||||
430 | 2 | 2 | return $self; | ||||
428 | 2 | 3 | $self->setURL($ISPAPI_CONNECTION_URL_LIVE); | ||||
429 | 2 | 4 | $self->{socketConfig}->setSystemEntity('54cd'); | ||||
430 | 2 | 1 | return $self; | ||||
431 | } | ||||||
432 | |||||||
433 | |||||||
434 | sub _flattenCommand { | ||||||
435 | 18 | 25 | my ( $self, $cmd ) = @_; | ||||
436 | 18 18 | 20 41 | for my $key ( keys %{$cmd} ) { | ||||
437 | 37 | 41 | my $newkey = uc $key; | ||||
438 | 37 | 58 | if ( $newkey ne $key ) { | ||||
435 | 18 | 35 | my ( $self, $cmd ) = @_; | ||||
436 | 18 18 | 25 38 | for my $key ( keys %{$cmd} ) { | ||||
437 | 37 | 43 | my $newkey = uc $key; | ||||
438 | 37 | 65 | if ( $newkey ne $key ) { | ||||
439 | 1 | 2 | $cmd->{$newkey} = delete $cmd->{$key}; | ||||
440 | } | ||||||
441 | 37 | 60 | if ( ref( $cmd->{$newkey} ) eq 'ARRAY' ) { | ||||
442 | 3 3 | 3 5 | my @val = @{ $cmd->{$newkey} }; | ||||
443 | 3 | 3 | my $idx = 0; | ||||
441 | 37 | 69 | if ( ref( $cmd->{$newkey} ) eq 'ARRAY' ) { | ||||
442 | 3 3 | 3 6 | my @val = @{ $cmd->{$newkey} }; | ||||
443 | 3 | 2 | my $idx = 0; | ||||
444 | 3 | 4 | for my $str (@val) { | ||||
445 | 6 | 8 | $str =~ s/[\r\n]//gmsx; | ||||
446 | 6 | 8 | $cmd->{"${key}${idx}"} = $str; | ||||
447 | 6 | 6 | $idx++; | ||||
445 | 6 | 9 | $str =~ s/[\r\n]//gmsx; | ||||
446 | 6 | 24 | $cmd->{"${key}${idx}"} = $str; | ||||
447 | 6 | 7 | $idx++; | ||||
448 | } | ||||||
449 | 3 | 4 | delete $cmd->{$newkey}; | ||||
449 | 3 | 6 | delete $cmd->{$newkey}; | ||||
450 | } | ||||||
451 | } | ||||||
452 | 18 | 31 | return $cmd; | ||||
452 | 18 | 32 | return $cmd; | ||||
453 | } | ||||||
454 | |||||||
455 | |||||||
456 | sub _autoIDNConvert { | ||||||
457 | 18 | 23 | my ( $self, $cmd ) = @_; | ||||
458 | 18 | 57 | if ( $cmd->{'COMMAND'} =~ /^CONVERTIDN$/imsx ) { | ||||
457 | 18 | 32 | my ( $self, $cmd ) = @_; | ||||
458 | 18 | 65 | if ( $cmd->{'COMMAND'} =~ /^CONVERTIDN$/imsx ) { | ||||
459 | 1 | 2 | return $cmd; | ||||
460 | } | ||||||
461 | 17 37 17 | 19 91 30 | my @keys = grep {/^(DOMAIN|NAMESERVER|DNSZONE)(\d*)$/imsx} keys %{$cmd}; | ||||
462 | 17 | 41 | if ( scalar @keys == 0 ) { | ||||
463 | 15 | 21 | return $cmd; | ||||
461 | 17 37 17 | 19 98 33 | my @keys = grep {/^(DOMAIN|NAMESERVER|DNSZONE)(\d*)$/imsx} keys %{$cmd}; | ||||
462 | 17 | 32 | if ( scalar @keys == 0 ) { | ||||
463 | 15 | 24 | return $cmd; | ||||
464 | } | ||||||
465 | 2 | 3 | my @toconvert = (); | ||||
466 | 2 | 3 | my @idxs = (); | ||||
467 | 2 | 3 | foreach my $key (@keys) { | ||||
468 | 5 | 6 | my $val = $cmd->{$key}; | ||||
469 | 5 | 9 | if ( $val =~ /[^[:lower:]\d. -]/imsx ) { | ||||
469 | 5 | 11 | if ( $val =~ /[^[:lower:]\d. -]/imsx ) { | ||||
470 | 1 | 2 | push @toconvert, $val; | ||||
471 | 1 | 2 | push @idxs, $key; | ||||
472 | } | ||||||
473 | } | ||||||
474 | 2 | 5 | if ( scalar @toconvert == 0 ) { | ||||
475 | 1 | 2 | return $cmd; | ||||
474 | 2 | 4 | if ( scalar @toconvert == 0 ) { | ||||
475 | 1 | 3 | return $cmd; | ||||
476 | } | ||||||
477 | 1 | 5 | my $r = $self->request( | ||||
477 | 1 | 6 | my $r = $self->request( | ||||
478 | { COMMAND => 'ConvertIDN', | ||||||
479 | DOMAIN => \@toconvert | ||||||
480 | } | ||||||
481 | ); | ||||||
482 | 1 | 4 | if ( $r->isSuccess() ) { | ||||
483 | 1 | 2 | my $col = $r->getColumn('ACE'); | ||||
484 | 1 | 2 | if ($col) { | ||||
483 | 1 | 3 | my $col = $r->getColumn('ACE'); | ||||
484 | 1 | 4 | if ($col) { | ||||
485 | 1 | 3 | my $data = $col->getData(); | ||||
486 | 1 | 2 | my $idx = 0; | ||||
487 | 1 1 | 1 2 | foreach my $pc ( @{$data} ) { | ||||
488 | 1 | 2 | $cmd->{ $idxs[ $idx ] } = $pc; | ||||
486 | 1 | 1 | my $idx = 0; | ||||
487 | 1 1 | 2 4 | foreach my $pc ( @{$data} ) { | ||||
488 | 1 | 3 | $cmd->{ $idxs[ $idx ] } = $pc; | ||||
489 | 1 | 2 | $idx++; | ||||
490 | } | ||||||
491 | } |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::Column; | ||||||
2 | |||||||
3 | 1 1 | 6 1 | use 5.030; | ||||
4 | 1 1 1 | 2 0 8 | use strict; | ||||
5 | 1 1 1 | 2 1 123 | use warnings; | ||||
6 | |||||||
7 | our $VERSION = 'v2.10.3'; | ||||||
2 | |||||||
3 | 1 1 | 6 2 | use 5.030; | ||||
4 | 1 1 1 | 2 3 11 | use strict; | ||||
5 | 1 1 1 | 2 1 130 | use warnings; | ||||
6 | |||||||
7 | our $VERSION = 'v2.10.4'; | ||||||
8 | |||||||
9 | |||||||
10 | sub new { | ||||||
11 | 161 | 1 | 1462 | my ( $class, $key, @data ) = @_; | |||
12 | 161 | 133 | my $self = {}; | ||||
13 | 161 | 173 | $self->{key} = $key; | ||||
14 | 161 161 | 124 430 | @{ $self->{data} } = @data; | ||||
15 | 161 | 140 | $self->{length} = scalar @data; | ||||
16 | 161 | 271 | return bless $self, $class; | ||||
11 | 161 | 1 | 1528 | my ( $class, $key, @data ) = @_; | |||
12 | 161 | 143 | my $self = {}; | ||||
13 | 161 | 166 | $self->{key} = $key; | ||||
14 | 161 161 | 119 473 | @{ $self->{data} } = @data; | ||||
15 | 161 | 152 | $self->{length} = scalar @data; | ||||
16 | 161 | 266 | return bless $self, $class; | ||||
17 | } | ||||||
18 | |||||||
19 | |||||||
20 | sub getKey { | ||||||
21 | 1 | 1 | 331 | my $self = shift; | |||
22 | 1 | 3 | return $self->{key}; | ||||
21 | 1 | 1 | 345 | my $self = shift; | |||
22 | 1 | 4 | return $self->{key}; | ||||
23 | } | ||||||
24 | |||||||
25 | |||||||
26 | sub getData { | ||||||
27 | 3 | 1 | 4 | my $self = shift; | |||
28 | 3 | 5 | return $self->{data}; | ||||
28 | 3 | 6 | return $self->{data}; | ||||
29 | } | ||||||
30 | |||||||
31 | |||||||
32 | sub getDataByIndex { | ||||||
33 | 25250 | 1 | 19002 | my $self = shift; | |||
34 | 25250 | 17206 | my $idx = shift; | ||||
35 | 25250 | 20745 | return $self->{data}[ $idx ] | ||||
33 | 25604 | 1 | 17068 | my $self = shift; | |||
34 | 25604 | 16444 | my $idx = shift; | ||||
35 | 25604 | 21010 | return $self->{data}[ $idx ] | ||||
36 | if $self->hasDataIndex($idx); | ||||||
37 | 20831 | 18795 | return; | ||||
37 | 21126 | 17546 | return; | ||||
38 | } | ||||||
39 | |||||||
40 | |||||||
41 | sub hasDataIndex { | ||||||
42 | 25250 | 1 | 17680 | my $self = shift; | |||
43 | 25250 | 16200 | my $idx = shift; | ||||
44 | 25250 | 28269 | return $idx < $self->{length}; | ||||
42 | 25604 | 1 | 17497 | my $self = shift; | |||
43 | 25604 | 16434 | my $idx = shift; | ||||
44 | 25604 | 27354 | return $idx < $self->{length}; | ||||
45 | } | ||||||
46 | |||||||
47 | 1; | ||||||
48 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::Logger; | ||||||
2 | |||||||
3 | 1 1 | 8 1 | use 5.030; | ||||
4 | 1 1 1 | 2 1 8 | use strict; | ||||
5 | 1 1 1 | 2 1 19 | use warnings; | ||||
6 | 1 1 1 | 252 3454 121 | use Data::Dumper; | ||||
7 | |||||||
8 | our $VERSION = 'v2.10.3'; | ||||||
2 | |||||||
3 | 1 1 | 10 2 | use 5.030; | ||||
4 | 1 1 1 | 2 1 12 | use strict; | ||||
5 | 1 1 1 | 2 0 23 | use warnings; | ||||
6 | 1 1 1 | 254 3764 124 | use Data::Dumper; | ||||
7 | |||||||
8 | our $VERSION = 'v2.10.4'; | ||||||
9 | |||||||
10 | |||||||
11 | sub new { | ||||||
12 | 4 | 1 | 5 | my ($class) = @_; | |||
13 | 4 | 10 | return bless {}, $class; | ||||
12 | 4 | 1 | 4 | my ($class) = @_; | |||
13 | 4 | 12 | return bless {}, $class; | ||||
14 | } | ||||||
15 | |||||||
16 | |||||||
17 | sub log { | ||||||
18 | 2 | 1 | 4 | my ( $self, $post, $r, $error ) = @_; | |||
19 | 2 | 5 | if ( defined $error ) { | ||||
19 | 2 | 6 | if ( defined $error ) { | ||||
20 | 0 0 | 0 0 | print {*STDERR} Dumper($post); | ||||
21 | 0 0 | 0 0 | print {*STDERR} 'HTTP communication failed: ' . $error; | ||||
22 | 0 0 | 0 0 | print {*STDERR} Dumper( $r->getCommandPlain() ); | ||||
23 | 0 0 | 0 0 | print {*STDERR} Dumper( $r->getPlain() ); | ||||
24 | } else { | ||||||
25 | 2 2 | 2 9 | print {*STDOUT} Dumper($post); | ||||
26 | 2 2 | 405 7 | print {*STDOUT} Dumper( $r->getCommandPlain() ); | ||||
27 | 2 2 | 52 9 | print {*STDOUT} Dumper( $r->getPlain() ); | ||||
25 | 2 2 | 3 14 | print {*STDOUT} Dumper($post); | ||||
26 | 2 2 | 551 10 | print {*STDOUT} Dumper( $r->getCommandPlain() ); | ||||
27 | 2 2 | 57 11 | print {*STDOUT} Dumper( $r->getPlain() ); | ||||
28 | } | ||||||
29 | 2 | 46 | return $self->{data}; | ||||
29 | 2 | 50 | return $self->{data}; | ||||
30 | } | ||||||
31 | |||||||
32 | 1; | ||||||
33 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::Response; | ||||||
2 | |||||||
3 | 1 1 | 9 2 | use 5.030; | ||||
4 | 1 1 1 | 2 1 9 | use strict; | ||||
5 | 1 1 1 | 1 1 20 | use warnings; | ||||
6 | 1 1 1 | 281 2 14 | use WebService::Hexonet::Connector::Column; | ||||
7 | 1 1 1 | 273 1 15 | use WebService::Hexonet::Connector::Record; | ||||
8 | 1 1 1 | 147 125 3 | use parent qw(WebService::Hexonet::Connector::ResponseTemplate); | ||||
9 | 1 1 1 | 23 1 3 | use POSIX qw(ceil floor); | ||||
10 | 1 1 1 | 285 6101 3 | use List::MoreUtils qw(first_index); | ||||
11 | 1 1 1 | 616 2 1040 | use Readonly; | ||||
2 | |||||||
3 | 1 1 | 10 1 | use 5.030; | ||||
4 | 1 1 1 | 2 0 10 | use strict; | ||||
5 | 1 1 1 | 4 1 25 | use warnings; | ||||
6 | 1 1 1 | 305 2 15 | use WebService::Hexonet::Connector::Column; | ||||
7 | 1 1 1 | 301 1 16 | use WebService::Hexonet::Connector::Record; | ||||
8 | 1 1 1 | 164 127 2 | use parent qw(WebService::Hexonet::Connector::ResponseTemplate); | ||||
9 | 1 1 1 | 24 1 3 | use POSIX qw(ceil floor); | ||||
10 | 1 1 1 | 285 6389 3 | use List::MoreUtils qw(first_index); | ||||
11 | 1 1 1 | 632 1 1059 | use Readonly; | ||||
12 | Readonly my $INDEX_NOT_FOUND => -1; | ||||||
13 | |||||||
14 | our $VERSION = 'v2.10.3'; | ||||||
13 | |||||||
14 | our $VERSION = 'v2.10.4'; | ||||||
15 | |||||||
16 | |||||||
17 | sub new { | ||||||
18 | 50 | 1 | 15247 | my ( $class, $raw, $cmd, $ph ) = @_; | |||
19 | 50 | 121 | my $self = WebService::Hexonet::Connector::ResponseTemplate->new($raw); | ||||
18 | 50 | 1 | 16533 | my ( $class, $raw, $cmd, $ph ) = @_; | |||
19 | 50 | 162 | my $self = WebService::Hexonet::Connector::ResponseTemplate->new($raw); | ||||
20 | # care about getting placeholder variables replaced | ||||||
21 | 50 | 120 | if ( $self->{raw} =~ /[{][[:upper:]_]+[}]/gsmx ) { | ||||
22 | 4 | 4 | if ( !defined $ph ) { | ||||
23 | 3 | 4 | $ph = {}; | ||||
21 | 50 | 134 | if ( $self->{raw} =~ /[{][[:upper:]_]+[}]/gsmx ) { | ||||
22 | 4 | 5 | if ( !defined $ph ) { | ||||
23 | 3 | 3 | $ph = {}; | ||||
24 | } | ||||||
25 | 4 4 | 4 6 | foreach my $key ( keys %{$ph} ) { | ||||
26 | 1 | 1 | my $find = "[{]${key}[}]"; | ||||
25 | 4 4 | 4 5 | foreach my $key ( keys %{$ph} ) { | ||||
26 | 1 | 2 | my $find = "[{]${key}[}]"; | ||||
27 | 1 | 2 | my $replace = $ph->{$key}; | ||||
28 | 1 | 15 | $self->{raw} =~ s/$find/$replace/gsmx; | ||||
28 | 1 | 31 | $self->{raw} =~ s/$find/$replace/gsmx; | ||||
29 | } | ||||||
30 | 4 | 9 | $self->{raw} =~ s/[{][[:upper:]_]+[}]//gsmx; | ||||
30 | 4 | 10 | $self->{raw} =~ s/[{][[:upper:]_]+[}]//gsmx; | ||||
31 | 4 | 6 | $self = WebService::Hexonet::Connector::ResponseTemplate->new( $self->{raw} ); | ||||
32 | } | ||||||
33 | 50 | 61 | $self = bless $self, $class; | ||||
34 | 50 | 61 | $self->{command} = $cmd; | ||||
35 | 50 | 82 | if ( defined $self->{command}->{PASSWORD} ) { | ||||
33 | 50 | 67 | $self = bless $self, $class; | ||||
34 | 50 | 89 | $self->{command} = $cmd; | ||||
35 | 50 | 95 | if ( defined $self->{command}->{PASSWORD} ) { | ||||
36 | # make password no longer accessible | ||||||
37 | 1 | 2 | $self->{command}->{PASSWORD} = '***'; | ||||
38 | } | ||||||
39 | 50 | 73 | $self->{columnkeys} = []; | ||||
40 | 50 | 61 | $self->{columns} = []; | ||||
41 | 50 | 53 | $self->{records} = []; | ||||
42 | 50 | 56 | $self->{recordIndex} = 0; | ||||
43 | |||||||
44 | 50 | 80 | my $h = $self->getHash(); | ||||
45 | 50 | 71 | if ( defined $h->{PROPERTY} ) { | ||||
46 | 33 33 | 31 77 | my @keys = keys %{ $h->{PROPERTY} }; | ||||
47 | 33 | 42 | my $count = 0; | ||||
48 | 33 | 39 | foreach my $key (@keys) { | ||||
49 | 160 160 | 117 441 | my @d = @{ $h->{PROPERTY}->{$key} }; | ||||
50 | 160 | 214 | $self->addColumn( $key, @d ); | ||||
51 | 160 | 122 | my $len = scalar @d; | ||||
52 | 160 | 193 | if ( $len > $count ) { | ||||
53 | 55 | 119 | $count = $len; | ||||
39 | 50 | 84 | $self->{columnkeys} = []; | ||||
40 | 50 | 72 | $self->{columns} = []; | ||||
41 | 50 | 135 | $self->{records} = []; | ||||
42 | 50 | 75 | $self->{recordIndex} = 0; | ||||
43 | |||||||
44 | 50 | 101 | my $h = $self->getHash(); | ||||
45 | 50 | 96 | if ( defined $h->{PROPERTY} ) { | ||||
46 | 33 33 | 34 86 | my @keys = keys %{ $h->{PROPERTY} }; | ||||
47 | 33 | 47 | my $count = 0; | ||||
48 | 33 | 48 | foreach my $key (@keys) { | ||||
49 | 160 160 | 110 445 | my @d = @{ $h->{PROPERTY}->{$key} }; | ||||
50 | 160 | 225 | $self->addColumn( $key, @d ); | ||||
51 | 160 | 106 | my $len = scalar @d; | ||||
52 | 160 | 185 | if ( $len > $count ) { | ||||
53 | 51 | 136 | $count = $len; | ||||
54 | } | ||||||
55 | } | ||||||
56 | 33 | 25 | $count--; | ||||
57 | 33 | 60 | for my $i ( 0 .. $count ) { | ||||
58 | 4204 | 3055 | my %d = (); | ||||
59 | 4204 | 3184 | foreach my $colkey (@keys) { | ||||
60 | 25167 | 21701 | my $col = $self->getColumn($colkey); | ||||
61 | 25167 | 22667 | if ( defined $col ) { | ||||
62 | 25167 | 24394 | my $v = $col->getDataByIndex($i); | ||||
63 | 25167 | 27085 | if ( defined $v ) { | ||||
64 | 4336 | 4820 | $d{$colkey} = $v; | ||||
56 | 33 | 37 | $count--; | ||||
57 | 33 | 61 | for my $i ( 0 .. $count ) { | ||||
58 | 4263 | 2781 | my %d = (); | ||||
59 | 4263 | 3090 | foreach my $colkey (@keys) { | ||||
60 | 25521 | 20691 | my $col = $self->getColumn($colkey); | ||||
61 | 25521 | 22611 | if ( defined $col ) { | ||||
62 | 25521 | 22751 | my $v = $col->getDataByIndex($i); | ||||
63 | 25521 | 24166 | if ( defined $v ) { | ||||
64 | 4395 | 4505 | $d{$colkey} = $v; | ||||
65 | } | ||||||
66 | } | ||||||
67 | } | ||||||
68 | 4204 | 3865 | $self->addRecord( \%d ); | ||||
68 | 4263 | 3878 | $self->addRecord( \%d ); | ||||
69 | } | ||||||
70 | } | ||||||
71 | 50 | 343 | return $self; | ||||
71 | 50 | 446 | return $self; | ||||
72 | } | ||||||
73 | |||||||
74 | |||||||
75 | sub addColumn { | ||||||
76 | 160 | 1 | 422 | my ( $self, $key, @data ) = @_; | |||
77 | 160 160 | 104 261 | push @{ $self->{columns} }, WebService::Hexonet::Connector::Column->new( $key, @data ); | ||||
78 | 160 160 | 127 158 | push @{ $self->{columnkeys} }, $key; | ||||
79 | 160 | 198 | return $self; | ||||
76 | 160 | 1 | 467 | my ( $self, $key, @data ) = @_; | |||
77 | 160 160 | 116 292 | push @{ $self->{columns} }, WebService::Hexonet::Connector::Column->new( $key, @data ); | ||||
78 | 160 160 | 132 171 | push @{ $self->{columnkeys} }, $key; | ||||
79 | 160 | 225 | return $self; | ||||
80 | } | ||||||
81 | |||||||
82 | |||||||
83 | sub addRecord { | ||||||
84 | 4204 | 1 | 3421 | my ( $self, $h ) = @_; | |||
85 | 4204 4204 | 3100 4497 | push @{ $self->{records} }, WebService::Hexonet::Connector::Record->new($h); | ||||
86 | 4204 | 4252 | return $self; | ||||
84 | 4263 | 1 | 3295 | my ( $self, $h ) = @_; | |||
85 | 4263 4263 | 2826 4382 | push @{ $self->{records} }, WebService::Hexonet::Connector::Record->new($h); | ||||
86 | 4263 | 3803 | return $self; | ||||
87 | } | ||||||
88 | |||||||
89 | |||||||
90 | sub getColumn { | ||||||
91 | 25270 | 1 | 21943 | my ( $self, $key ) = @_; | |||
92 | 25270 | 22838 | if ( $self->_hasColumn($key) ) { | ||||
93 | 25253 88317 25253 | 70652 61694 24635 | my $idx = first_index { $_ eq $key } @{ $self->{columnkeys} }; | ||||
94 | 25253 | 29914 | return $self->{columns}[ $idx ]; | ||||
91 | 25624 | 1 | 20698 | my ( $self, $key ) = @_; | |||
92 | 25624 | 21234 | if ( $self->_hasColumn($key) ) { | ||||
93 | 25607 89546 25607 | 64035 62525 24739 | my $idx = first_index { $_ eq $key } @{ $self->{columnkeys} }; | ||||
94 | 25607 | 29621 | return $self->{columns}[ $idx ]; | ||||
95 | } | ||||||
96 | 17 | 50 | return; | ||||
96 | 17 | 48 | return; | ||||
97 | } | ||||||
98 | |||||||
99 | |||||||
100 | sub getColumnIndex { | ||||||
101 | 2 | 1 | 4 | my ( $self, $key, $idx ) = @_; | |||
101 | 2 | 1 | 5 | my ( $self, $key, $idx ) = @_; | |||
102 | 2 | 3 | my $col = $self->getColumn($key); | ||||
103 | 2 | 5 | return $col->getDataByIndex($idx) if defined $col; | ||||
104 | 1 | 1 | return; | ||||
105 | } | ||||||
106 | |||||||
107 | |||||||
108 | sub getColumnKeys { | ||||||
109 | 3 | 1 | 302 | my $self = shift; | |||
110 | 3 3 | 4 5 | return \@{ $self->{columnkeys} }; | ||||
109 | 3 | 1 | 336 | my $self = shift; | |||
110 | 3 3 | 2 7 | return \@{ $self->{columnkeys} }; | ||||
111 | } | ||||||
112 | |||||||
113 | |||||||
114 | sub getColumns { | ||||||
115 | 1 | 0 | 3 | my $self = shift; | |||
116 | 1 1 | 1 1 | return \@{ $self->{columns} }; | ||||
116 | 1 1 | 1 2 | return \@{ $self->{columns} }; | ||||
117 | } | ||||||
118 | |||||||
119 | |||||||
120 | sub getCommand { | ||||||
121 | 9 | 1 | 24 | my $self = shift; | |||
122 | 9 | 15 | return $self->{command}; | ||||
121 | 9 | 1 | 28 | my $self = shift; | |||
122 | 9 | 22 | return $self->{command}; | ||||
123 | } | ||||||
124 | |||||||
125 | |||||||
126 | sub getCommandPlain { | ||||||
127 | 4 | 1 | 12 | my $self = shift; | |||
128 | 4 | 4 | my $str = q{}; | ||||
129 | 4 4 | 3 15 | foreach my $key ( sort keys %{ $self->{command} } ) { | ||||
130 | 10 | 10 | my $val = $self->{command}->{$key}; | ||||
128 | 4 | 5 | my $str = q{}; | ||||
129 | 4 4 | 7 15 | foreach my $key ( sort keys %{ $self->{command} } ) { | ||||
130 | 10 | 13 | my $val = $self->{command}->{$key}; | ||||
131 | 10 | 14 | $str .= "${key} = ${val}\n"; | ||||
132 | } | ||||||
133 | 4 | 10 | return $str; | ||||
133 | 4 | 9 | return $str; | ||||
134 | } | ||||||
135 | |||||||
136 | |||||||
137 | sub getCurrentPageNumber { | ||||||
138 | 19 | 1 | 20 | my $self = shift; | |||
139 | 19 | 17 | my $first = $self->getFirstRecordIndex(); | ||||
138 | 19 | 1 | 19 | my $self = shift; | |||
139 | 19 | 20 | my $first = $self->getFirstRecordIndex(); | ||||
140 | 19 | 22 | my $limit = $self->getRecordsLimitation(); | ||||
141 | 19 | 32 | if ( defined $first && $limit > 0 ) { | ||||
142 | 14 | 28 | return floor( $first / $limit ) + 1; | ||||
141 | 19 | 35 | if ( defined $first && $limit > 0 ) { | ||||
142 | 14 | 31 | return floor( $first / $limit ) + 1; | ||||
143 | } | ||||||
144 | 5 | 5 | return $INDEX_NOT_FOUND; | ||||
145 | } | ||||||
146 | |||||||
147 | |||||||
148 | sub getCurrentRecord { | ||||||
149 | 2 | 1 | 5 | my $self = shift; | |||
149 | 2 | 1 | 6 | my $self = shift; | |||
150 | 2 | 3 | return $self->{records}[ $self->{recordIndex} ] | ||||
151 | if $self->_hasCurrentRecord(); | ||||||
152 | 1 | 2 | return; | ||||
152 | 1 | 3 | return; | ||||
153 | } | ||||||
154 | |||||||
155 | |||||||
156 | sub getFirstRecordIndex { | ||||||
157 | 28 | 1 | 27 | my $self = shift; | |||
158 | 28 | 29 | my $col = $self->getColumn('FIRST'); | ||||
159 | 28 | 33 | if ( defined $col ) { | ||||
160 | 21 | 25 | my $f = $col->getDataByIndex(0); | ||||
161 | 21 | 63 | if ( defined $f ) { | ||||
162 | 21 | 28 | return int $f; | ||||
157 | 28 | 1 | 28 | my $self = shift; | |||
158 | 28 | 31 | my $col = $self->getColumn('FIRST'); | ||||
159 | 28 | 40 | if ( defined $col ) { | ||||
160 | 21 | 21 | my $f = $col->getDataByIndex(0); | ||||
161 | 21 | 26 | if ( defined $f ) { | ||||
162 | 21 | 34 | return int $f; | ||||
163 | } | ||||||
164 | } | ||||||
165 | 7 7 | 7 6 | my $len = scalar @{ $self->{records} }; | ||||
166 | 7 | 13 | return 0 if ( $len > 0 ); | ||||
165 | 7 7 | 7 8 | my $len = scalar @{ $self->{records} }; | ||||
166 | 7 | 11 | return 0 if ( $len > 0 ); | ||||
167 | 6 | 7 | return; | ||||
168 | } | ||||||
169 | |||||||
170 | |||||||
171 | sub getLastRecordIndex { | ||||||
172 | 9 | 1 | 12 | my $self = shift; | |||
173 | 9 | 11 | my $col = $self->getColumn('LAST'); | ||||
174 | 9 | 13 | if ( defined $col ) { | ||||
175 | 7 | 10 | my $l = $col->getDataByIndex(0); | ||||
176 | 7 | 9 | if ( defined $l ) { | ||||
177 | 7 | 12 | return int $l; | ||||
172 | 9 | 1 | 14 | my $self = shift; | |||
173 | 9 | 14 | my $col = $self->getColumn('LAST'); | ||||
174 | 9 | 14 | if ( defined $col ) { | ||||
175 | 7 | 11 | my $l = $col->getDataByIndex(0); | ||||
176 | 7 | 10 | if ( defined $l ) { | ||||
177 | 7 | 16 | return int $l; | ||||
178 | } | ||||||
179 | } | ||||||
180 | 2 | 3 | my $len = $self->getRecordsCount(); | ||||
181 | 2 | 5 | if ( $len > 0 ) { | ||||
182 | 1 | 3 | return ( $len - 1 ); | ||||
181 | 2 | 3 | if ( $len > 0 ) { | ||||
182 | 1 | 2 | return ( $len - 1 ); | ||||
183 | } | ||||||
184 | 1 | 2 | return; | ||||
184 | 1 | 3 | return; | ||||
185 | } | ||||||
186 | |||||||
187 | |||||||
188 | sub getListHash { | ||||||
189 | 1 | 1 | 3 | my $self = shift; | |||
191 | 1 1 | 1 2 | foreach my $rec ( @{ $self->getRecords() } ) { | ||||
192 | 2 | 3 | push @lh, $rec->getData(); | ||||
193 | } | ||||||
194 | 1 | 2 | my $r = { | ||||
194 | 1 | 3 | my $r = { | ||||
195 | LIST => \@lh, | ||||||
196 | meta => { | ||||||
197 | columns => $self->getColumnKeys(), | ||||||
201 | 1 | 3 | return $r; | ||||
202 | } | ||||||
203 | |||||||
204 | |||||||
205 | sub getNextRecord { | ||||||
206 | 5 | 1 | 7 | my $self = shift; | |||
207 | 5 | 8 | return $self->{records}[ ++$self->{recordIndex} ] | ||||
206 | 5 | 1 | 8 | my $self = shift; | |||
207 | 5 | 7 | return $self->{records}[ ++$self->{recordIndex} ] | ||||
208 | if ( $self->_hasNextRecord() ); | ||||||
209 | 2 | 4 | return; | ||||
209 | 2 | 5 | return; | ||||
210 | } | ||||||
211 | |||||||
212 | |||||||
213 | sub getNextPageNumber { | ||||||
214 | 5 | 1 | 7 | my $self = shift; | |||
215 | 5 | 5 | my $cp = $self->getCurrentPageNumber(); | ||||
216 | 5 | 11 | if ( $cp < 0 ) { | ||||
217 | 1 | 1 | return $INDEX_NOT_FOUND; | ||||
214 | 5 | 1 | 6 | my $self = shift; | |||
215 | 5 | 8 | my $cp = $self->getCurrentPageNumber(); | ||||
216 | 5 | 9 | if ( $cp < 0 ) { | ||||
217 | 1 | 2 | return $INDEX_NOT_FOUND; | ||||
218 | } | ||||||
219 | 4 | 5 | my $page = $cp + 1; | ||||
220 | 4 | 4 | my $pages = $self->getNumberOfPages(); | ||||
219 | 4 | 3 | my $page = $cp + 1; | ||||
220 | 4 | 5 | my $pages = $self->getNumberOfPages(); | ||||
221 | 4 | 9 | return $page if ( $page <= $pages ); | ||||
222 | 0 | 0 | return $pages; | ||||
223 | } | ||||||
224 | |||||||
225 | |||||||
226 | sub getNumberOfPages { | ||||||
227 | 9 | 1 | 8 | my $self = shift; | |||
228 | 9 | 9 | my $t = $self->getRecordsTotalCount(); | ||||
229 | 9 | 8 | my $limit = $self->getRecordsLimitation(); | ||||
230 | 9 | 16 | if ( $t > 0 && $limit > 0 ) { | ||||
231 | 8 | 14 | return ceil( $t / $limit ); | ||||
228 | 9 | 11 | my $t = $self->getRecordsTotalCount(); | ||||
229 | 9 | 9 | my $limit = $self->getRecordsLimitation(); | ||||
230 | 9 | 20 | if ( $t > 0 && $limit > 0 ) { | ||||
231 | 8 | 19 | return ceil( $t / $limit ); | ||||
232 | } | ||||||
233 | 1 | 3 | return 0; | ||||
234 | } | ||||||
235 | |||||||
236 | |||||||
237 | sub getPagination { | ||||||
238 | 3 | 1 | 276 | my $self = shift; | |||
238 | 3 | 1 | 302 | my $self = shift; | |||
239 | 3 | 5 | my $r = { | ||||
240 | COUNT => $self->getRecordsCount(), | ||||||
241 | CURRENTPAGE => $self->getCurrentPageNumber(), | ||||||
247 | PREVIOUSPAGE => $self->getPreviousPageNumber(), | ||||||
248 | TOTAL => $self->getRecordsTotalCount() | ||||||
249 | }; | ||||||
250 | 3 | 8 | return $r; | ||||
250 | 3 | 7 | return $r; | ||||
251 | } | ||||||
252 | |||||||
253 | |||||||
254 | sub getPreviousPageNumber { | ||||||
255 | 5 | 1 | 7 | my $self = shift; | |||
256 | 5 | 6 | my $cp = $self->getCurrentPageNumber(); | ||||
255 | 5 | 1 | 6 | my $self = shift; | |||
256 | 5 | 4 | my $cp = $self->getCurrentPageNumber(); | ||||
257 | 5 | 9 | if ( $cp < 0 ) { | ||||
258 | 1 | 1 | return $INDEX_NOT_FOUND; | ||||
258 | 1 | 2 | return $INDEX_NOT_FOUND; | ||||
259 | } | ||||||
260 | 4 | 5 | my $np = $cp - 1; | ||||
261 | 4 | 9 | return $np if ( $np > 0 ); | ||||
262 | 4 | 4 | return $INDEX_NOT_FOUND; | ||||
260 | 4 | 4 | my $np = $cp - 1; | ||||
261 | 4 | 4 | return $np if ( $np > 0 ); | ||||
262 | 4 | 6 | return $INDEX_NOT_FOUND; | ||||
263 | } | ||||||
264 | |||||||
265 | |||||||
266 | sub getPreviousRecord { | ||||||
267 | 4 | 1 | 6 | my $self = shift; | |||
268 | 4 | 6 | return $self->{records}[ --$self->{recordIndex} ] | ||||
267 | 4 | 1 | 8 | my $self = shift; | |||
268 | 4 | 7 | return $self->{records}[ --$self->{recordIndex} ] | ||||
269 | if ( $self->_hasPreviousRecord() ); | ||||||
270 | 3 | 7 | return; | ||||
270 | 3 | 9 | return; | ||||
271 | } | ||||||
272 | |||||||
273 | |||||||
274 | sub getRecord { | ||||||
275 | 2 | 1 | 4 | my ( $self, $idx ) = @_; | |||
276 | 2 | 8 | if ( $idx >= 0 && $self->getRecordsCount() > $idx ) { | ||||
277 | 2 | 7 | return $self->{records}[ $idx ]; | ||||
275 | 2 | 1 | 6 | my ( $self, $idx ) = @_; | |||
276 | 2 | 10 | if ( $idx >= 0 && $self->getRecordsCount() > $idx ) { | ||||
277 | 2 | 13 | return $self->{records}[ $idx ]; | ||||
278 | } | ||||||
279 | 0 | 0 | return; | ||||
280 | } | ||||||
281 | |||||||
282 | |||||||
283 | sub getRecords { | ||||||
284 | 1 | 1 | 2 | my $self = shift; | |||
285 | 1 1 | 1 2 | return \@{ $self->{records} }; | ||||
285 | 1 1 | 1 3 | return \@{ $self->{records} }; | ||||
286 | } | ||||||
287 | |||||||
288 | |||||||
289 | sub getRecordsCount { | ||||||
290 | 18 | 1 | 20 | my $self = shift; | |||
291 | 18 18 | 15 14 | my $len = scalar @{ $self->{records} }; | ||||
292 | 18 | 33 | return $len; | ||||
290 | 18 | 1 | 17 | my $self = shift; | |||
291 | 18 18 | 14 27 | my $len = scalar @{ $self->{records} }; | ||||
292 | 18 | 81 | return $len; | ||||
293 | } | ||||||
294 | |||||||
295 | |||||||
296 | sub getRecordsTotalCount { | ||||||
297 | 19 | 1 | 25 | my $self = shift; | |||
298 | 19 | 24 | my $col = $self->getColumn('TOTAL'); | ||||
299 | 19 | 21 | if ( defined $col ) { | ||||
300 | 18 | 23 | my $t = $col->getDataByIndex(0); | ||||
301 | 18 | 27 | if ( defined $t ) { | ||||
302 | 18 | 36 | return int $t; | ||||
297 | 19 | 1 | 24 | my $self = shift; | |||
298 | 19 | 26 | my $col = $self->getColumn('TOTAL'); | ||||
299 | 19 | 33 | if ( defined $col ) { | ||||
300 | 18 | 21 | my $t = $col->getDataByIndex(0); | ||||
301 | 18 | 25 | if ( defined $t ) { | ||||
302 | 18 | 37 | return int $t; | ||||
303 | } | ||||||
304 | } | ||||||
305 | 1 | 2 | return $self->getRecordsCount(); | ||||
305 | 1 | 4 | return $self->getRecordsCount(); | ||||
306 | } | ||||||
307 | |||||||
308 | |||||||
309 | sub getRecordsLimitation { | ||||||
310 | 42 | 1 | 39 | my $self = shift; | |||
311 | 42 | 49 | my $col = $self->getColumn('LIMIT'); | ||||
312 | 42 | 50 | if ( defined $col ) { | ||||
313 | 36 | 50 | my $l = $col->getDataByIndex(0); | ||||
314 | 36 | 39 | if ( defined $l ) { | ||||
315 | 36 | 41 | return int $l; | ||||
310 | 42 | 1 | 38 | my $self = shift; | |||
311 | 42 | 44 | my $col = $self->getColumn('LIMIT'); | ||||
312 | 42 | 49 | if ( defined $col ) { | ||||
313 | 36 | 41 | my $l = $col->getDataByIndex(0); | ||||
314 | 36 | 45 | if ( defined $l ) { | ||||
315 | 36 | 53 | return int $l; | ||||
316 | } | ||||||
317 | } | ||||||
318 | 6 | 7 | return $self->getRecordsCount(); | ||||
319 | } | ||||||
320 | |||||||
321 | |||||||
322 | sub hasNextPage { | ||||||
323 | 2 | 1 | 5 | my $self = shift; | |||
323 | 2 | 1 | 6 | my $self = shift; | |||
324 | 2 | 3 | my $cp = $self->getCurrentPageNumber(); | ||||
325 | 2 | 7 | if ( $cp < 0 ) { | ||||
326 | 1 | 2 | return 0; | ||||
325 | 2 | 6 | if ( $cp < 0 ) { | ||||
326 | 1 | 3 | return 0; | ||||
327 | } | ||||||
328 | 1 | 1 | my $np = $cp + 1; | ||||
329 | 1 | 2 | if ( $np <= $self->getNumberOfPages() ) { | ||||
330 | 1 | 2 | return 1; | ||||
329 | 1 | 3 | if ( $np <= $self->getNumberOfPages() ) { | ||||
330 | 1 | 3 | return 1; | ||||
331 | } | ||||||
332 | 0 | 0 | return 0; | ||||
333 | } | ||||||
334 | |||||||
335 | |||||||
336 | sub hasPreviousPage { | ||||||
337 | 2 | 1 | 5 | my $self = shift; | |||
337 | 2 | 1 | 6 | my $self = shift; | |||
338 | 2 | 3 | my $cp = $self->getCurrentPageNumber(); | ||||
339 | 2 | 7 | if ( $cp < 0 ) { | ||||
340 | 1 | 2 | return 0; | ||||
339 | 2 | 6 | if ( $cp < 0 ) { | ||||
340 | 1 | 4 | return 0; | ||||
341 | } | ||||||
342 | 1 | 1 | my $pp = $cp - 1; | ||||
343 | 1 | 2 | if ( $pp > 0 ) { | ||||
343 | 1 | 3 | if ( $pp > 0 ) { | ||||
344 | 0 | 0 | return 1; | ||||
345 | } | ||||||
346 | 1 | 3 | return 0; | ||||
346 | 1 | 2 | return 0; | ||||
347 | } | ||||||
348 | |||||||
349 | |||||||
350 | sub rewindRecordList { | ||||||
351 | 1 | 1 | 1 | my $self = shift; | |||
352 | 1 | 2 | $self->{recordIndex} = 0; | ||||
353 | 1 | 1 | return $self; | ||||
352 | 1 | 1 | $self->{recordIndex} = 0; | ||||
353 | 1 | 2 | return $self; | ||||
354 | } | ||||||
355 | |||||||
356 | |||||||
357 | sub _hasColumn { | ||||||
358 | 25270 | 20234 | my ( $self, $key ) = @_; | ||||
359 | 25270 88325 25270 | 27214 62609 26812 | my $idx = first_index { $_ eq $key } @{ $self->{columnkeys} }; | ||||
360 | 25270 | 30911 | return ( $idx > $INDEX_NOT_FOUND ); | ||||
358 | 25624 | 20084 | my ( $self, $key ) = @_; | ||||
359 | 25624 89554 25624 | 25245 61180 24886 | my $idx = first_index { $_ eq $key } @{ $self->{columnkeys} }; | ||||
360 | 25624 | 29537 | return ( $idx > $INDEX_NOT_FOUND ); | ||||
361 | } | ||||||
362 | |||||||
363 | |||||||
364 | sub _hasCurrentRecord { | ||||||
365 | 8 | 4 | my $self = shift; | ||||
366 | 8 8 | 7 9 | my $len = scalar @{ $self->{records} }; | ||||
367 | 8 | 42 | return ( $len > 0 && $self->{recordIndex} >= 0 && $self->{recordIndex} < $len ); | ||||
365 | 8 | 7 | my $self = shift; | ||||
366 | 8 8 | 5 9 | my $len = scalar @{ $self->{records} }; | ||||
367 | 8 | 40 | return ( $len > 0 && $self->{recordIndex} >= 0 && $self->{recordIndex} < $len ); | ||||
368 | } | ||||||
369 | |||||||
370 | |||||||
371 | sub _hasNextRecord { | ||||||
372 | 5 | 3 | my $self = shift; | ||||
373 | 5 | 6 | my $next = $self->{recordIndex} + 1; | ||||
374 | 5 5 | 4 5 | my $len = scalar @{ $self->{records} }; | ||||
372 | 5 | 5 | my $self = shift; | ||||
373 | 5 | 5 | my $next = $self->{recordIndex} + 1; | ||||
374 | 5 5 | 2 7 | my $len = scalar @{ $self->{records} }; | ||||
375 | 5 | 7 | return ( $self->_hasCurrentRecord() && $next < $len ); | ||||
376 | } | ||||||
377 | |||||||
378 | |||||||
379 | sub _hasPreviousRecord { | ||||||
380 | 4 | 3 | my $self = shift; | ||||
381 | 4 | 9 | return ( $self->{recordIndex} > 0 && $self->_hasCurrentRecord() ); | ||||
380 | 4 | 2 | my $self = shift; | ||||
381 | 4 | 8 | return ( $self->{recordIndex} > 0 && $self->_hasCurrentRecord() ); | ||||
382 | } | ||||||
383 | |||||||
384 | 1; | ||||||
385 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::ResponseParser; | ||||||
2 | |||||||
3 | 1 1 | 7 1 | use 5.030; | ||||
4 | 1 1 1 | 2 1 7 | use strict; | ||||
5 | 1 1 1 | 2 3 291 | use warnings; | ||||
6 | |||||||
7 | our $VERSION = 'v2.10.3'; | ||||||
2 | |||||||
3 | 1 1 | 8 2 | use 5.030; | ||||
4 | 1 1 1 | 2 0 13 | use strict; | ||||
5 | 1 1 1 | 1 1 307 | use warnings; | ||||
6 | |||||||
7 | our $VERSION = 'v2.10.4'; | ||||||
8 | |||||||
9 | |||||||
10 | sub parse { | ||||||
11 | 112 | 1 | 101 | my $response = shift; | |||
12 | 112 | 99 | my %hash = (); | ||||
13 | 112 | 292 | $response =~ s/\r\n/\n/gmsx; | ||||
14 | 112 | 733 | foreach ( split /\n/msx, $response ) { | ||||
15 | 5047 | 7068 | if (/^([^\=]*[^\t\= ])[\t ]*=[\t ]*(.+)/msx) { | ||||
16 | 4790 | 4381 | my $attr = $1; | ||||
17 | 4790 | 4400 | my $value = $2; | ||||
18 | 4790 | 9596 | $value =~ s/[\t ]*$//msx; | ||||
19 | 4790 | 5848 | if ( $attr =~ /^property\[([^\]]*)\]/imsx ) { | ||||
20 | 4455 | 4366 | if ( !defined $hash{PROPERTY} ) { | ||||
21 | 50 | 61 | $hash{PROPERTY} = {}; | ||||
11 | 112 | 1 | 111 | my $response = shift; | |||
12 | 112 | 104 | my %hash = (); | ||||
13 | 112 | 277 | $response =~ s/\r\n/\n/gmsx; | ||||
14 | 112 | 670 | foreach ( split /\n/msx, $response ) { | ||||
15 | 5106 | 6932 | if (/^([^\=]*[^\t\= ])[\t ]*=[\t ]*(.+)/msx) { | ||||
16 | 4849 | 4032 | my $attr = $1; | ||||
17 | 4849 | 3707 | my $value = $2; | ||||
18 | 4849 | 9533 | $value =~ s/[\t ]*$//msx; | ||||
19 | 4849 | 5290 | if ( $attr =~ /^property\[([^\]]*)\]/imsx ) { | ||||
20 | 4514 | 4220 | if ( !defined $hash{PROPERTY} ) { | ||||
21 | 50 | 76 | $hash{PROPERTY} = {}; | ||||
22 | } | ||||||
23 | 4455 | 4017 | my $prop = uc $1; | ||||
24 | 4455 | 3749 | $prop =~ s/\s//ogmsx; | ||||
25 | 4455 | 4167 | if ( defined $hash{PROPERTY}{$prop} ) { | ||||
26 | 4193 4193 | 2827 4617 | push @{ $hash{PROPERTY}{$prop} }, $value; | ||||
23 | 4514 | 3792 | my $prop = uc $1; | ||||
24 | 4514 | 3433 | $prop =~ s/\s//ogmsx; | ||||
25 | 4514 | 3957 | if ( defined $hash{PROPERTY}{$prop} ) { | ||||
26 | 4252 4252 | 2797 4523 | push @{ $hash{PROPERTY}{$prop} }, $value; | ||||
27 | } else { | ||||||
28 | 262 | 384 | $hash{PROPERTY}{$prop} = [ $value ]; | ||||
28 | 262 | 373 | $hash{PROPERTY}{$prop} = [ $value ]; | ||||
29 | } | ||||||
30 | } else { | ||||||
31 | 335 | 467 | $hash{ uc $attr } = $value; | ||||
31 | 335 | 455 | $hash{ uc $attr } = $value; | ||||
32 | } | ||||||
33 | } | ||||||
34 | } | ||||||
35 | 112 | 287 | return \%hash; | ||||
35 | 112 | 338 | return \%hash; | ||||
36 | } | ||||||
37 | |||||||
38 | |||||||
39 | sub serialize { | ||||||
40 | 6 | 1 | 25 | my $h = shift; | |||
41 | 6 | 4 | my $plain = '[RESPONSE]'; | ||||
42 | 6 | 10 | if ( defined $h->{PROPERTY} ) { | ||||
43 | 3 | 3 | my $props = $h->{PROPERTY}; | ||||
44 | 3 3 | 3 8 | foreach my $key ( sort keys %{$props} ) { | ||||
45 | 5 | 4 | my $i = 0; | ||||
46 | 5 5 | 4 6 | foreach my $val ( @{ $props->{$key} } ) { | ||||
40 | 6 | 1 | 27 | my $h = shift; | |||
41 | 6 | 7 | my $plain = '[RESPONSE]'; | ||||
42 | 6 | 8 | if ( defined $h->{PROPERTY} ) { | ||||
43 | 3 | 4 | my $props = $h->{PROPERTY}; | ||||
44 | 3 3 | 3 9 | foreach my $key ( sort keys %{$props} ) { | ||||
45 | 5 | 5 | my $i = 0; | ||||
46 | 5 5 | 5 5 | foreach my $val ( @{ $props->{$key} } ) { | ||||
47 | 11 | 13 | $plain .= "\r\nPROPERTY[${key}][${i}]=${val}"; | ||||
48 | 11 | 12 | $i++; | ||||
48 | 11 | 9 | $i++; | ||||
49 | } | ||||||
50 | } | ||||||
51 | } | ||||||
52 | 6 | 8 | if ( defined $h->{CODE} ) { | ||||
52 | 6 | 10 | if ( defined $h->{CODE} ) { | ||||
53 | 5 | 6 | $plain .= "\r\nCODE=" . $h->{CODE}; | ||||
54 | } | ||||||
55 | 6 | 9 | if ( defined $h->{DESCRIPTION} ) { | ||||
55 | 6 | 7 | if ( defined $h->{DESCRIPTION} ) { | ||||
56 | 5 | 5 | $plain .= "\r\nDESCRIPTION=" . $h->{DESCRIPTION}; | ||||
57 | } | ||||||
58 | 6 | 6 | if ( defined $h->{QUEUETIME} ) { | ||||
58 | 6 | 9 | if ( defined $h->{QUEUETIME} ) { | ||||
59 | 1 | 1 | $plain .= "\r\nQUEUETIME=" . $h->{QUEUETIME}; | ||||
60 | } | ||||||
61 | 6 | 7 | if ( defined $h->{RUNTIME} ) { | ||||
61 | 6 | 8 | if ( defined $h->{RUNTIME} ) { | ||||
62 | 1 | 2 | $plain .= "\r\nRUNTIME=" . $h->{RUNTIME}; | ||||
63 | } | ||||||
64 | 6 | 6 | $plain .= "\r\nEOF\r\n"; | ||||
65 | 6 | 7 | return $plain; | ||||
65 | 6 | 8 | return $plain; | ||||
66 | } | ||||||
67 | |||||||
68 | 1; | ||||||
69 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::ResponseTemplate; | ||||||
2 | |||||||
3 | 1 1 | 321 2 | use 5.030; | ||||
4 | 1 1 1 | 3 1 15 | use strict; | ||||
5 | 1 1 1 | 2 1 16 | use warnings; | ||||
6 | 1 1 1 | 279 2 15 | use WebService::Hexonet::Connector::ResponseParser; | ||||
7 | 1 1 1 | 298 2 261 | use WebService::Hexonet::Connector::ResponseTemplateManager; | ||||
8 | |||||||
9 | our $VERSION = 'v2.10.3'; | ||||||
2 | |||||||
3 | 1 1 | 350 2 | use 5.030; | ||||
4 | 1 1 1 | 2 1 9 | use strict; | ||||
5 | 1 1 1 | 1 6 22 | use warnings; | ||||
6 | 1 1 1 | 342 2 19 | use WebService::Hexonet::Connector::ResponseParser; | ||||
7 | 1 1 1 | 328 2 237 | use WebService::Hexonet::Connector::ResponseTemplateManager; | ||||
8 | |||||||
9 | our $VERSION = 'v2.10.4'; | ||||||
10 | |||||||
11 | my $rtm = WebService::Hexonet::Connector::ResponseTemplateManager->getInstance(); | ||||||
12 | |||||||
13 | |||||||
14 | sub new { | ||||||
15 | 110 | 1 | 2959 | my ( $class, $raw ) = @_; | |||
16 | 110 | 106 | my $self = {}; | ||||
17 | 110 | 269 | if ( !defined $raw || length $raw == 0 ) { | ||||
18 | 11 | 11 | $raw = "[RESPONSE]\r\nCODE=423\r\nDESCRIPTION=Empty API response. Probably unreachable API end point {CONNECTION_URL}\r\nEOF\r\n"; | ||||
15 | 110 | 1 | 3081 | my ( $class, $raw ) = @_; | |||
16 | 110 | 112 | my $self = {}; | ||||
17 | 110 | 303 | if ( !defined $raw || length $raw == 0 ) { | ||||
18 | 11 | 12 | $raw = "[RESPONSE]\r\nCODE=423\r\nDESCRIPTION=Empty API response. Probably unreachable API end point {CONNECTION_URL}\r\nEOF\r\n"; | ||||
19 | } | ||||||
20 | 110 | 129 | $self->{raw} = $raw; | ||||
21 | 110 | 155 | $self->{hash} = WebService::Hexonet::Connector::ResponseParser::parse($raw); | ||||
22 | 110 | 245 | if ( !defined $self->{hash}->{'DESCRIPTION'} || !defined $self->{hash}->{'CODE'} ) { | ||||
20 | 110 | 130 | $self->{raw} = $raw; | ||||
21 | 110 | 170 | $self->{hash} = WebService::Hexonet::Connector::ResponseParser::parse($raw); | ||||
22 | 110 | 249 | if ( !defined $self->{hash}->{'DESCRIPTION'} || !defined $self->{hash}->{'CODE'} ) { | ||||
23 | 1 | 2 | $self->{raw} = $rtm->getTemplate('invalid')->getPlain(); | ||||
24 | 1 | 3 | $self->{hash} = WebService::Hexonet::Connector::ResponseParser::parse( $self->{raw} ); | ||||
25 | } | ||||||
26 | 110 | 217 | return bless $self, $class; | ||||
26 | 110 | 246 | return bless $self, $class; | ||||
27 | } | ||||||
28 | |||||||
29 | |||||||
30 | sub getCode { | ||||||
31 | 3 | 1 | 7 | my $self = shift; | |||
32 | 3 | 7 | return ( $self->{hash}->{CODE} + 0 ); | ||||
33 | } | ||||||
34 | |||||||
35 | |||||||
36 | sub getDescription { | ||||||
37 | 7 | 1 | 16 | my $self = shift; | |||
38 | 7 | 17 | return $self->{hash}->{DESCRIPTION}; | ||||
37 | 7 | 1 | 12 | my $self = shift; | |||
38 | 7 | 21 | return $self->{hash}->{DESCRIPTION}; | ||||
39 | } | ||||||
40 | |||||||
41 | |||||||
42 | sub getPlain { | ||||||
43 | 32 | 1 | 65 | my $self = shift; | |||
44 | 32 | 65 | return $self->{raw}; | ||||
43 | 32 | 1 | 69 | my $self = shift; | |||
44 | 32 | 91 | return $self->{raw}; | ||||
45 | } | ||||||
46 | |||||||
47 | |||||||
48 | sub getQueuetime { | ||||||
49 | 2 | 1 | 5 | my $self = shift; | |||
50 | 2 | 3 | if ( defined $self->{hash}->{QUEUETIME} ) { | ||||
50 | 2 | 5 | if ( defined $self->{hash}->{QUEUETIME} ) { | ||||
51 | 1 | 3 | return ( $self->{hash}->{QUEUETIME} + 0.00 ); | ||||
52 | } | ||||||
53 | 1 | 3 | return 0.00; | ||||
54 | } | ||||||
55 | |||||||
56 | |||||||
57 | sub getHash { | ||||||
58 | 62 | 1 | 70 | my $self = shift; | |||
59 | 62 | 83 | return $self->{hash}; | ||||
58 | 62 | 1 | 75 | my $self = shift; | |||
59 | 62 | 93 | return $self->{hash}; | ||||
60 | } | ||||||
61 | |||||||
62 | |||||||
63 | sub getRuntime { | ||||||
64 | 2 | 1 | 5 | my $self = shift; | |||
64 | 2 | 1 | 7 | my $self = shift; | |||
65 | 2 | 3 | if ( defined $self->{hash}->{RUNTIME} ) { | ||||
66 | 1 | 5 | return ( $self->{hash}->{RUNTIME} + 0.00 ); | ||||
66 | 1 | 4 | return ( $self->{hash}->{RUNTIME} + 0.00 ); | ||||
67 | } | ||||||
68 | 1 | 18 | return 0.00; | ||||
68 | 1 | 2 | return 0.00; | ||||
69 | } | ||||||
70 | |||||||
71 | |||||||
72 | sub isError { | ||||||
73 | 2 | 1 | 1440 | my $self = shift; | |||
73 | 2 | 1 | 1721 | my $self = shift; | |||
74 | 2 | 5 | my $first = substr $self->{hash}->{CODE}, 0, 1; | ||||
75 | 2 | 6 | return ( $first eq '5' ); | ||||
75 | 2 | 7 | return ( $first eq '5' ); | ||||
76 | } | ||||||
77 | |||||||
78 | |||||||
79 | sub isSuccess { | ||||||
80 | 18 | 1 | 5547 | my $self = shift; | |||
81 | 18 | 42 | my $first = substr $self->{hash}->{CODE}, 0, 1; | ||||
82 | 18 | 85 | return ( $first eq '2' ); | ||||
80 | 18 | 1 | 6755 | my $self = shift; | |||
81 | 18 | 54 | my $first = substr $self->{hash}->{CODE}, 0, 1; | ||||
82 | 18 | 63 | return ( $first eq '2' ); | ||||
83 | } | ||||||
84 | |||||||
85 | |||||||
86 | sub isTmpError { | ||||||
87 | 1 | 1 | 616 | my $self = shift; | |||
88 | 1 | 3 | my $first = substr $self->{hash}->{CODE}, 0, 1; | ||||
89 | 1 | 3 | return ( $first eq '4' ); | ||||
87 | 1 | 1 | 763 | my $self = shift; | |||
88 | 1 | 4 | my $first = substr $self->{hash}->{CODE}, 0, 1; | ||||
89 | 1 | 4 | return ( $first eq '4' ); | ||||
90 | } | ||||||
91 | |||||||
92 | |||||||
93 | sub isPending { | ||||||
94 | 2 | 1 | 5 | my $self = shift; | |||
95 | 2 | 13 | if ( defined $self->{hash}->{PENDING} ) { | ||||
94 | 2 | 1 | 27 | my $self = shift; | |||
95 | 2 | 3 | if ( defined $self->{hash}->{PENDING} ) { | ||||
96 | 1 | 3 | return int( $self->{hash}->{PENDING} ); | ||||
97 | } | ||||||
98 | 1 | 2 | return 0; |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::ResponseTemplateManager; | ||||||
2 | |||||||
3 | 1 1 | 7 2 | use 5.030; | ||||
2 | |||||||
3 | 1 1 | 8 1 | use 5.030; | ||||
4 | 1 1 1 | 2 1 9 | use strict; | ||||
5 | 1 1 1 | 2 1 15 | use warnings; | ||||
5 | 1 1 1 | 2 1 23 | use warnings; | ||||
6 | 1 1 1 | 2 1 14 | use WebService::Hexonet::Connector::ResponseTemplate; | ||||
7 | 1 1 1 | 2 1 268 | use WebService::Hexonet::Connector::ResponseParser; | ||||
8 | |||||||
9 | our $VERSION = 'v2.10.3'; | ||||||
7 | 1 1 1 | 1 1 274 | use WebService::Hexonet::Connector::ResponseParser; | ||||
8 | |||||||
9 | our $VERSION = 'v2.10.4'; | ||||||
10 | |||||||
11 | my $instance = undef; | ||||||
12 | |||||||
13 | |||||||
14 | sub getInstance { | ||||||
15 | 3 | 1 | 8 | if ( !defined $instance ) { | |||
16 | 1 | 1 | my $self = { templates => {} }; | ||||
17 | 1 | 2 | $instance = bless $self, shift; | ||||
18 | 1 | 1 | $instance->addTemplate( '404', $instance->generateTemplate( '421', 'Page not found' ) ); | ||||
19 | 1 | 2 | $instance->addTemplate( '500', $instance->generateTemplate( '500', 'Internal server error' ) ); | ||||
20 | 1 | 1 | $instance->addTemplate( 'empty', $instance->generateTemplate( '423', 'Empty API response. Probably unreachable API end point {CONNECTION_URL}' ) ); | ||||
15 | 3 | 1 | 7 | if ( !defined $instance ) { | |||
16 | 1 | 2 | my $self = { templates => {} }; | ||||
17 | 1 | 1 | $instance = bless $self, shift; | ||||
18 | 1 | 2 | $instance->addTemplate( '404', $instance->generateTemplate( '421', 'Page not found' ) ); | ||||
19 | 1 | 1 | $instance->addTemplate( '500', $instance->generateTemplate( '500', 'Internal server error' ) ); | ||||
20 | 1 | 2 | $instance->addTemplate( 'empty', $instance->generateTemplate( '423', 'Empty API response. Probably unreachable API end point {CONNECTION_URL}' ) ); | ||||
21 | 1 | 1 | $instance->addTemplate( 'error', $instance->generateTemplate( '421', 'Command failed due to server error. Client should try again' ) ); | ||||
22 | 1 | 1 | $instance->addTemplate( 'expired', $instance->generateTemplate( '530', 'SESSION NOT FOUND' ) ); | ||||
23 | 1 | 2 | $instance->addTemplate( 'httperror', $instance->generateTemplate( '421', 'Command failed due to HTTP communication error' ) ); | ||||
23 | 1 | 1 | $instance->addTemplate( 'httperror', $instance->generateTemplate( '421', 'Command failed due to HTTP communication error' ) ); | ||||
24 | 1 | 1 | $instance->addTemplate( 'invalid', $instance->generateTemplate( '423', 'Invalid API response. Contact Support' ) ); | ||||
25 | 1 | 3 | $instance->addTemplate( 'unauthorized', $instance->generateTemplate( '530', 'Unauthorized' ) ); | ||||
25 | 1 | 1 | $instance->addTemplate( 'unauthorized', $instance->generateTemplate( '530', 'Unauthorized' ) ); | ||||
26 | } | ||||||
27 | 3 | 5 | return $instance; | ||||
27 | 3 | 3 | return $instance; | ||||
28 | } | ||||||
29 | |||||||
30 | |||||||
31 | sub generateTemplate { | ||||||
32 | 10 | 1 | 274 | my ( $self, $code, $description ) = @_; | |||
33 | 10 | 16 | return "[RESPONSE]\r\nCODE=${code}\r\nDESCRIPTION=${description}\r\nEOF\r\n"; | ||||
32 | 10 | 1 | 285 | my ( $self, $code, $description ) = @_; | |||
33 | 10 | 18 | return "[RESPONSE]\r\nCODE=${code}\r\nDESCRIPTION=${description}\r\nEOF\r\n"; | ||||
34 | } | ||||||
35 | |||||||
36 | |||||||
37 | sub addTemplate { | ||||||
38 | 10 | 1 | 10 | my ( $self, $id, $plain ) = @_; | |||
39 | 10 | 12 | $self->{templates}->{$id} = $plain; | ||||
40 | 10 | 9 | return $instance; | ||||
38 | 10 | 1 | 9 | my ( $self, $id, $plain ) = @_; | |||
39 | 10 | 14 | $self->{templates}->{$id} = $plain; | ||||
40 | 10 | 11 | return $instance; | ||||
41 | } | ||||||
42 | |||||||
43 | |||||||
44 | sub getTemplate { | ||||||
45 | 35 | 1 | 7642 | my ( $self, $id ) = @_; | |||
45 | 35 | 1 | 7924 | my ( $self, $id ) = @_; | |||
46 | 35 | 34 | my $plain; | ||||
47 | 35 | 47 | if ( $self->hasTemplate($id) ) { | ||||
48 | 34 | 37 | $plain = $self->{templates}->{$id}; | ||||
47 | 35 | 49 | if ( $self->hasTemplate($id) ) { | ||||
48 | 34 | 38 | $plain = $self->{templates}->{$id}; | ||||
49 | } else { | ||||||
50 | 1 | 1 | $plain = $self->generateTemplate( '500', 'Response Template not found' ); | ||||
50 | 1 | 2 | $plain = $self->generateTemplate( '500', 'Response Template not found' ); | ||||
51 | } | ||||||
52 | 35 | 53 | return WebService::Hexonet::Connector::ResponseTemplate->new($plain); | ||||
52 | 35 | 68 | return WebService::Hexonet::Connector::ResponseTemplate->new($plain); | ||||
53 | } | ||||||
54 | |||||||
55 | |||||||
56 | sub getTemplates { | ||||||
57 | 1 | 1 | 1 | my $self = shift; | |||
58 | 1 | 2 | my $tmp = {}; | ||||
57 | 1 | 1 | 2 | my $self = shift; | |||
58 | 1 | 1 | my $tmp = {}; | ||||
59 | 1 | 1 | my $tpls = $self->{templates}; | ||||
60 | 1 1 | 1 3 | foreach my $key ( keys %{$tpls} ) { | ||||
60 | 1 1 | 2 3 | foreach my $key ( keys %{$tpls} ) { | ||||
61 | 10 | 13 | $tmp->{$key} = WebService::Hexonet::Connector::ResponseTemplate->new( $tpls->{$key} ); | ||||
62 | } | ||||||
63 | 1 | 2 | return $tmp; | ||||
63 | 1 | 3 | return $tmp; | ||||
64 | } | ||||||
65 | |||||||
66 | |||||||
67 | sub hasTemplate { | ||||||
68 | 35 | 1 | 37 | my ( $self, $id ) = @_; | |||
69 | 35 | 65 | return defined $self->{templates}->{$id}; | ||||
68 | 35 | 1 | 35 | my ( $self, $id ) = @_; | |||
69 | 35 | 61 | return defined $self->{templates}->{$id}; | ||||
70 | } | ||||||
71 | |||||||
72 | |||||||
73 | sub isTemplateMatchHash { | ||||||
74 | 2 | 1 | 4 | my ( $self, $tpl2, $id ) = @_; | |||
74 | 2 | 1 | 6 | my ( $self, $tpl2, $id ) = @_; | |||
75 | 2 | 3 | my $tpl = $self->getTemplate($id); | ||||
76 | 2 | 4 | my $h = $tpl->getHash(); | ||||
77 | 2 | 9 | return ( $h->{CODE} eq $tpl2->{CODE} ) && ( $h->{DESCRIPTION} eq $tpl2->{DESCRIPTION} ); | ||||
76 | 2 | 5 | my $h = $tpl->getHash(); | ||||
77 | 2 | 12 | return ( $h->{CODE} eq $tpl2->{CODE} ) && ( $h->{DESCRIPTION} eq $tpl2->{DESCRIPTION} ); | ||||
78 | } | ||||||
79 | |||||||
80 | |||||||
81 | sub isTemplateMatchPlain { | ||||||
82 | 1 | 1 | 2 | my ( $self, $plain, $id ) = @_; | |||
83 | 1 | 1 | my $h = WebService::Hexonet::Connector::ResponseParser::parse($plain); | ||||
84 | 1 | 2 | return $self->isTemplateMatchHash( $h, $id ); | ||||
83 | 1 | 3 | my $h = WebService::Hexonet::Connector::ResponseParser::parse($plain); | ||||
84 | 1 | 1 | return $self->isTemplateMatchHash( $h, $id ); | ||||
85 | } | ||||||
86 | |||||||
87 | 1; | ||||||
88 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector::SocketConfig; | ||||||
2 | |||||||
3 | 1 1 | 9 2 | use 5.030; | ||||
4 | 1 1 1 | 2 1 10 | use strict; | ||||
5 | 1 1 1 | 2 1 18 | use warnings; | ||||
6 | 1 1 1 | 18 2 2 | use utf8; | ||||
7 | |||||||
8 | our $VERSION = 'v2.10.3'; | ||||||
2 | |||||||
3 | 1 1 | 8 2 | use 5.030; | ||||
4 | 1 1 1 | 2 1 8 | use strict; | ||||
5 | 1 1 1 | 2 1 22 | use warnings; | ||||
6 | 1 1 1 | 17 1 3 | use utf8; | ||||
7 | |||||||
8 | our $VERSION = 'v2.10.4'; | ||||||
9 | |||||||
10 | |||||||
11 | sub new { | ||||||
12 | 3 | 1 | 318 | my $class = shift; | |||
13 | 3 | 18 | return bless { | ||||
12 | 3 | 1 | 338 | my $class = shift; | |||
13 | 3 | 22 | return bless { | ||||
14 | entity => q{}, | ||||||
15 | login => q{}, | ||||||
16 | otp => q{}, | ||||||
21 | }, $class; | ||||||
22 | } | ||||||
23 | |||||||
24 | |||||||
25 | sub getPOSTData { | ||||||
26 | 53 | 1 | 52 | my $self = shift; | |||
27 | 53 | 51 | my $data = {}; | ||||
28 | 53 | 92 | if ( length $self->{entity} ) { | ||||
29 | 52 | 71 | $data->{'s_entity'} = $self->{entity}; | ||||
26 | 53 | 1 | 51 | my $self = shift; | |||
27 | 53 | 63 | my $data = {}; | ||||
28 | 53 | 95 | if ( length $self->{entity} ) { | ||||
29 | 52 | 79 | $data->{'s_entity'} = $self->{entity}; | ||||
30 | } | ||||||
31 | 53 | 76 | if ( length $self->{login} ) { | ||||
32 | 35 | 48 | $data->{'s_login'} = $self->{login}; | ||||
31 | 53 | 78 | if ( length $self->{login} ) { | ||||
32 | 35 | 68 | $data->{'s_login'} = $self->{login}; | ||||
33 | } | ||||||
34 | 53 | 74 | if ( length $self->{otp} ) { | ||||
35 | 1 | 1 | $data->{'s_otp'} = $self->{otp}; | ||||
34 | 53 | 92 | if ( length $self->{otp} ) { | ||||
35 | 1 | 2 | $data->{'s_otp'} = $self->{otp}; | ||||
36 | } | ||||||
37 | 53 | 64 | if ( length $self->{pw} ) { | ||||
38 | 35 | 39 | $data->{'s_pw'} = $self->{pw}; | ||||
37 | 53 | 91 | if ( length $self->{pw} ) { | ||||
38 | 35 | 61 | $data->{'s_pw'} = $self->{pw}; | ||||
39 | } | ||||||
40 | 53 | 82 | if ( length $self->{remoteaddr} ) { | ||||
41 | 37 | 40 | $data->{'s_remoteaddr'} = $self->{remoteaddr}; | ||||
40 | 53 | 76 | if ( length $self->{remoteaddr} ) { | ||||
41 | 37 | 49 | $data->{'s_remoteaddr'} = $self->{remoteaddr}; | ||||
42 | } | ||||||
43 | 53 | 65 | if ( length $self->{session} ) { | ||||
44 | 7 | 9 | $data->{'s_session'} = $self->{session}; | ||||
43 | 53 | 71 | if ( length $self->{session} ) { | ||||
44 | 7 | 12 | $data->{'s_session'} = $self->{session}; | ||||
45 | } | ||||||
46 | 53 | 66 | if ( length $self->{user} ) { | ||||
46 | 53 | 69 | if ( length $self->{user} ) { | ||||
47 | 2 | 4 | $data->{'s_user'} = $self->{user}; | ||||
48 | } | ||||||
49 | 53 | 63 | return $data; | ||||
49 | 53 | 64 | return $data; | ||||
50 | } | ||||||
51 | |||||||
52 | |||||||
53 | sub getSession { | ||||||
54 | 3 | 1 | 4 | my $self = shift; | |||
55 | 3 | 5 | return $self->{session}; | ||||
54 | 3 | 1 | 3 | my $self = shift; | |||
55 | 3 | 6 | return $self->{session}; | ||||
56 | } | ||||||
57 | |||||||
58 | |||||||
59 | sub getSystemEntity { | ||||||
60 | 1 | 1 | 1 | my $self = shift; | |||
60 | 1 | 1 | 2 | my $self = shift; | |||
61 | 1 | 3 | return $self->{entity}; | ||||
62 | } | ||||||
63 | |||||||
64 | |||||||
65 | sub setLogin { | ||||||
66 | 11 | 1 | 13 | my ( $self, $value ) = @_; | |||
67 | 11 | 13 | $self->{session} = q{}; # Empty string | ||||
68 | 11 | 14 | $self->{login} = $value; | ||||
66 | 11 | 1 | 19 | my ( $self, $value ) = @_; | |||
67 | 11 | 16 | $self->{session} = q{}; # Empty string | ||||
68 | 11 | 12 | $self->{login} = $value; | ||||
69 | 11 | 11 | return $self; | ||||
70 | } | ||||||
71 | |||||||
72 | |||||||
73 | sub setOTP { | ||||||
74 | 7 | 1 | 8 | my ( $self, $value ) = @_; | |||
75 | 7 | 7 | $self->{session} = q{}; # Empty string | ||||
76 | 7 | 9 | $self->{otp} = $value; | ||||
77 | 7 | 7 | return $self; | ||||
74 | 7 | 1 | 10 | my ( $self, $value ) = @_; | |||
75 | 7 | 9 | $self->{session} = q{}; # Empty string | ||||
76 | 7 | 8 | $self->{otp} = $value; | ||||
77 | 7 | 9 | return $self; | ||||
78 | } | ||||||
79 | |||||||
80 | |||||||
81 | sub setPassword { | ||||||
82 | 11 | 1 | 12 | my ( $self, $value ) = @_; | |||
83 | 11 | 10 | $self->{session} = q{}; # Empty string | ||||
84 | 11 | 13 | $self->{pw} = $value; | ||||
85 | 11 | 9 | return $self; | ||||
83 | 11 | 14 | $self->{session} = q{}; # Empty string | ||||
84 | 11 | 14 | $self->{pw} = $value; | ||||
85 | 11 | 13 | return $self; | ||||
86 | } | ||||||
87 | |||||||
88 | |||||||
89 | sub setRemoteAddress { | ||||||
90 | 3 | 1 | 4 | my ( $self, $value ) = @_; | |||
91 | 3 | 3 | $self->{remoteaddr} = $value; | ||||
90 | 3 | 1 | 3 | my ( $self, $value ) = @_; | |||
91 | 3 | 2 | $self->{remoteaddr} = $value; | ||||
92 | 3 | 3 | return $self; | ||||
93 | } | ||||||
94 | |||||||
95 | |||||||
96 | sub setSession { | ||||||
97 | 12 | 1 | 15 | my ( $self, $value ) = @_; | |||
98 | 12 | 14 | $self->{session} = $value; | ||||
99 | 12 | 13 | $self->{login} = q{}; # Empty string | ||||
100 | 12 | 12 | $self->{pw} = q{}; # Empty string | ||||
101 | 12 | 12 | $self->{otp} = q{}; # Empty string | ||||
102 | 12 | 11 | return $self; | ||||
97 | 12 | 1 | 14 | my ( $self, $value ) = @_; | |||
98 | 12 | 16 | $self->{session} = $value; | ||||
99 | 12 | 20 | $self->{login} = q{}; # Empty string | ||||
100 | 12 | 13 | $self->{pw} = q{}; # Empty string | ||||
101 | 12 | 14 | $self->{otp} = q{}; # Empty string | ||||
102 | 12 | 13 | return $self; | ||||
103 | } | ||||||
104 | |||||||
105 | |||||||
106 | sub setSystemEntity { | ||||||
107 | 4 | 1 | 5 | my ( $self, $value ) = @_; | |||
108 | 4 | 4 | $self->{entity} = $value; | ||||
107 | 4 | 1 | 6 | my ( $self, $value ) = @_; | |||
108 | 4 | 5 | $self->{entity} = $value; | ||||
109 | 4 | 5 | return $self; | ||||
110 | } | ||||||
111 | |||||||
112 | |||||||
113 | sub setUser { | ||||||
114 | 2 | 1 | 3 | my ( $self, $value ) = @_; | |||
115 | 2 | 5 | $self->{user} = $value; | ||||
116 | 2 | 3 | return $self; | ||||
114 | 2 | 1 | 4 | my ( $self, $value ) = @_; | |||
115 | 2 | 4 | $self->{user} = $value; | ||||
116 | 2 | 5 | return $self; | ||||
117 | } | ||||||
118 | |||||||
119 | 1; | ||||||
120 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Hexonet::Connector; | ||||||
2 | |||||||
3 | 1 1 | 251961 4 | use 5.030; | ||||
4 | 1 1 1 | 3 1 12 | use strict; | ||||
5 | 1 1 1 | 1 1 25 | use warnings; | ||||
6 | 1 1 1 | 364 1 22 | use WebService::Hexonet::Connector::APIClient; | ||||
7 | 1 1 1 | 3 1 10 | use WebService::Hexonet::Connector::Column; | ||||
8 | 1 1 1 | 2 1 7 | use WebService::Hexonet::Connector::Record; | ||||
2 | |||||||
3 | 1 1 | 216488 4 | use 5.030; | ||||
4 | 1 1 1 | 2 1 11 | use strict; | ||||
5 | 1 1 1 | 3 1 37 | use warnings; | ||||
6 | 1 1 1 | 364 2 23 | use WebService::Hexonet::Connector::APIClient; | ||||
7 | 1 1 1 | 4 1 10 | use WebService::Hexonet::Connector::Column; | ||||
8 | 1 1 1 | 2 1 9 | use WebService::Hexonet::Connector::Record; | ||||
9 | 1 1 1 | 2 1 9 | use WebService::Hexonet::Connector::Response; | ||||
10 | 1 1 1 | 2 1 8 | use WebService::Hexonet::Connector::ResponseParser; | ||||
10 | 1 1 1 | 2 1 9 | use WebService::Hexonet::Connector::ResponseParser; | ||||
11 | 1 1 1 | 1 1 8 | use WebService::Hexonet::Connector::ResponseTemplate; | ||||
12 | 1 1 1 | 1 1 7 | use WebService::Hexonet::Connector::ResponseTemplateManager; | ||||
13 | 1 1 1 | 2 1 18 | use WebService::Hexonet::Connector::SocketConfig; | ||||
14 | |||||||
15 | our $VERSION = 'v2.10.3'; | ||||||
12 | 1 1 1 | 2 1 7 | use WebService::Hexonet::Connector::ResponseTemplateManager; | ||||
13 | 1 1 1 | 2 1 22 | use WebService::Hexonet::Connector::SocketConfig; | ||||
14 | |||||||
15 | our $VERSION = 'v2.10.4'; | ||||||
16 | |||||||
17 | 1; | ||||||
18 |