APIClient/Request/UAPIFromWHM1.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 67 CC 7 SCAR 25.9
CC
7
Cov
0%
new
30.0
_EXTRACT_RESPONSE
12.0
HTTP_RESPONSE_CLASS
2.0
CRAP 13.3
1 package cPanel::APIClient::Request::UAPIFromWHM1;
2  
3 # Copyright 2020 cPanel, L. L. C.
4 # All rights reserved.
5 # http://cpanel.net
6 #
7 # This is free software; you can redistribute it and/or modify it under the
8 # same terms as Perl itself. See L<perlartistic>.
9  
10 use strict;
11 use warnings;
12  
13 use parent qw( cPanel::APIClient::Request::WHM1 );
14  
15 use cPanel::APIClient::Utils::JSON ();
16 use cPanel::APIClient::Response::UAPI ();
17  
18 sub HTTP_RESPONSE_CLASS { return 'cPanel::APIClient::Response::UAPI' }
19  
20 sub new {
21 my ($class, $cpusername, $module, $fn, $args_hr, $metaargs_hr) = @_;
22  
23 die 'Need username!' if !defined $cpusername || !length $cpusername;
24 die 'Need module!' if !defined $module || !length $module;
25 die 'Need function name!' if !defined $fn || !length $fn;
26  
27 my %args = (
28 cpanel_jsonapi_apiversion => 3,
29 cpanel_jsonapi_module => $module,
30 cpanel_jsonapi_func => $fn,
31 cpanel_jsonapi_user => $cpusername,
32 $args_hr ? %$args_hr : (),
33 );
34  
35 return $class->SUPER::new( 'cpanel', \%args, $metaargs_hr );
36 }
37  
38 sub _EXTRACT_RESPONSE {
39  
40 # Ordinarily our response looks thus:
41 #
42 # {
43 # "module": "Email",
44 # "func": "list_pops",
45 # "result": {
46 # "metadata": {
47 # "transformed": 1
48 # },
49 # "warnings": null,
50 # "data": [
51 # {
52 # "suspended_incoming": 0,
53 # "email": "mail@proxied.tld",
54 # "suspended_login": 0,
55 # "login": "mail@proxied.tld"
56 # },
57 # {
58 # "suspended_login": 0,
59 # "email": "proxied",
60 # "suspended_incoming": 0,
61 # "login": "Main Account"
62 # }
63 # ],
64 # "messages": null,
65 # "errors": null,
66 # "status": 1
67 # },
68 # "apiversion": 3
69 # }
70  
71 return $_[1]->{'result'} if 'HASH' eq ref $_[1]->{'result'};
72  
73 # If the given username fails authn, though, an error like this is
74 # returned:
75 #
76 # {
77 # "data": {
78 # "reason": "User parameter is invalid or was not supplied",
79 # "result": "0"
80 # },
81 # "type": "text",
82 # "error": "User parameter is invalid or was not supplied"
83 # }
84  
85 die cPanel::APIClient::X->create('API', $_[1]->{'error'}) if $_[1]->{'error'};
86  
87 # This shouldn’t happen …
88 require Data::Dumper;
89 die "$_[0]: Received invalid payload: " . Data::Dumper::Dumper($_[1]);
90 }
91  
92 1;