File Coverage

blib/lib/Net/BaruwaAPI.pm
Criterion Covered Total %
statement 254 284 89.4
branch 20 32 62.5
condition 0 9 0.0
subroutine 78 79 98.7
pod 68 69 98.5
total 420 473 88.7


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # vim: ai ts=4 sts=4 et sw=4
3             # Net::BaruwaAPI Perl bindings for the Baruwa REST API
4             # Copyright (C) 2015-2019 Andrew Colin Kissa
5             #
6             # This Source Code Form is subject to the terms of the Mozilla Public
7             # License, v. 2.0. If a copy of the MPL was not distributed with this file,
8             # You can obtain one at http://mozilla.org/MPL/2.0/.
9             package Net::BaruwaAPI;
10              
11             # use utf8;
12 17     17   1214754 use feature 'state';
  17         147  
  17         2012  
13 17     17   7130 use JSON::MaybeXS;
  17         119186  
  17         1123  
14 17     17   6784 use HTTP::Request;
  17         314818  
  17         796  
15 17     17   139 use Carp qw/croak/;
  17         30  
  17         1023  
16 17     17   10209 use LWP::UserAgent;
  17         382288  
  17         718  
17 17     17   8937 use Type::Params qw/compile/;
  17         1290961  
  17         165  
18 17     17   3723 use Types::Standard qw(Str InstanceOf Object Int Bool Dict Num ArrayRef Optional);
  17         38  
  17         76  
19 17     17   29176 use Moo;
  17         158368  
  17         89  
20              
21             our $VERSION = '0.06';
22             our $AUTHORITY = 'cpan:DATOPDOG';
23              
24             my $api_path = '/api/v1';
25              
26             has 'api_url' => (is => 'ro', isa => Str, predicate => 'has_api_url', required => 1);
27              
28             has 'api_token' => (is => 'ro', isa => Str, predicate => 'has_api_token', required => 1);
29              
30             has 'ua' => (
31             isa => InstanceOf['LWP::UserAgent'],
32             is => 'ro',
33             lazy => 1,
34             default => sub {
35             LWP::UserAgent->new(
36             agent => "BaruwaAPI-Perl",
37             cookie_jar => {},
38             keep_alive => 4,
39             timeout => 60,
40             );
41             },
42             );
43              
44             has 'json' => (
45             is => 'ro',
46             isa => Object,
47             lazy => 1,
48             default => sub {
49             return JSON::MaybeXS->new( utf8 => 1 );
50             }
51             );
52              
53             sub _call {
54 0     0   0 my ($self) = @_;
55 0         0 my $request_method = shift @_;
56 0         0 my $url = shift @_;
57 0         0 my $data = shift @_;
58              
59 0         0 my $ua = $self->ua;
60 0         0 $ua->default_header('Authorization', "Bearer " . $self->api_token);
61 0         0 $url = $self->api_url . $url;
62              
63 0         0 my $req = HTTP::Request->new( $request_method, $url );
64 0         0 $req->accept_decodable;
65              
66 0 0       0 if ($data) {
67 0         0 $req->content($data);
68             }
69 0         0 $req->header( 'Content-Length' => length $req->content );
70              
71 0         0 my $res = $ua->request($req);
72              
73 0 0 0     0 if ($res->header('Content-Type') and $res->header('Content-Type') =~ 'application/json') {
74 0         0 my $json = $res->decoded_content;
75 0         0 $data = eval { $self->json->decode($json) };
  0         0  
76 0 0       0 unless ($data) {
77 0 0       0 die unless $res->is_error;
78 0         0 $data = { code => $res->code, message => $res->message };
79             }
80             } else {
81 0         0 $data = { code => $res->code, message => $res->message };
82             }
83              
84 0 0 0     0 if (not $res->is_success and ref $data eq 'HASH' and exists $data->{message}) {
      0        
85 0         0 my $message = $data->{message};
86              
87 0 0       0 if (exists $data->{errors}) {
88 0         0 $message .= ': '.join(' - ', map { $_->{message} } grep { exists $_->{message} } @{ $data->{errors} });
  0         0  
  0         0  
  0         0  
89             }
90 0         0 croak $message;
91             }
92 0         0 return $data;
93             }
94              
95              
96             sub get_users {
97 2     2 1 3427 state $check = compile(Object, Optional[Int]);
98 2         1692 my ($self, $page) = $check->(@_);
99 2         83 my $path = "$api_path/users";
100 2 100       8 $path = "$api_path/users?page=$page" unless @_ == 1;
101 2         8 return $self->_call('GET', $path);
102             }
103              
104             sub get_user {
105 1     1 1 1129 state $check = compile(Object, Int);
106 1         1001 my ($self, $userid) = $check->(@_);
107 1         18 return $self->_call('GET', "$api_path/users/$userid");
108             }
109              
110             sub create_user {
111 1     1 1 4046 state $check = compile(Object,
112             Dict[
113             username => Str,
114             firstname => Str,
115             lastname => Str,
116             password1 => Str,
117             password2 => Str,
118             email => Str,
119             timezone => Str,
120             account_type => Int,
121             domains => Int,
122             active => Bool,
123             send_report => Bool,
124             spam_checks => Bool,
125             low_score => Num,
126             high_score => Num,
127             block_macros => Bool,
128             ]);
129 1         22625 my ($self, $data) = $check->(@_);
130 1         231 return $self->_call('POST', "$api_path/users", $data);
131             }
132              
133             sub update_user {
134 1     1 1 1148 state $check = compile(Object,
135             Dict[
136             username => Str,
137             firstname => Str,
138             lastname => Str,
139             email => Str,
140             timezone => Str,
141             domains => Int,
142             active => Bool,
143             send_report => Bool,
144             spam_checks => Bool,
145             low_score => Num,
146             high_score => Num,
147             block_macros => Bool,
148             ]);
149 1         15686 my ($self, $data) = $check->(@_);
150 1         202 return $self->_call('PUT', "$api_path/users", $data);
151             }
152              
153             sub delete_user {
154 1     1 1 1417 state $check = compile(Object,
155             Dict[
156             username => Str,
157             firstname => Str,
158             lastname => Str,
159             email => Str,
160             timezone => Str,
161             domains => Int,
162             active => Bool,
163             send_report => Bool,
164             spam_checks => Bool,
165             low_score => Num,
166             high_score => Num,
167             block_macros => Bool,
168             ]);
169 1         15422 my ($self, $data) = $check->(@_);
170             # my ($self, $data) = @_;
171 1         191 return $self->_call('DELETE', "$api_path/users", $data);
172             }
173              
174             sub set_user_passwd {
175 1     1 1 1422 state $check = compile(Object, Int,
176             Dict[
177             password1 => Str,
178             password2 => Str,
179             ]);
180 1         4448 my ($self, $userid, $data) = $check->(@_);
181 1         110 return $self->_call('POST', "$api_path/users/chpw/$userid");
182             }
183              
184             sub get_aliases {
185 1     1 1 3619 state $check = compile(Object, Int);
186 1         1029 my ($self, $addressid) = $check->(@_);
187 1         27 return $self->_call('GET', "$api_path/aliasaddresses/$addressid");
188             }
189              
190             sub create_alias {
191 1     1 1 999 state $check = compile(Object, Int,
192             Dict[
193             address => Str,
194             enabled => Bool,
195             ]);
196 1         6866 my ($self, $userid, $data) = $check->(@_);
197 1         113 return $self->_call('POST', "$api_path/aliasaddresses/$userid", $data);
198             }
199              
200             sub update_alias {
201 1     1 1 1076 state $check = compile(Object, Int,
202             Dict[
203             address => Str,
204             enabled => Bool,
205             ]);
206 1         3878 my ($self, $addressid, $data) = $check->(@_);
207 1         98 return $self->_call('PUT', "$api_path/aliasaddresses/$addressid", $data);
208             }
209              
210             sub delete_alias {
211 1     1 1 5950 state $check = compile(Object, Int,
212             Dict[
213             address => Str,
214             enabled => Bool,
215             ]);
216 1         3914 my ($self, $addressid, $data) = $check->(@_);
217 1         100 return $self->_call('DELETE', "$api_path/aliasaddresses/$addressid", $data);
218             }
219              
220             sub get_domains {
221 2     2 1 4664 state $check = compile(Object, Optional[Int]);
222 2         1836 my ($self, $page) = $check->(@_);
223 2         85 my $path = "$api_path/domains";
224 2 100       8 $path = "$api_path/domains?page=$page" unless @_ == 1;
225 2         8 return $self->_call('GET', $path);
226             }
227              
228             sub get_domain {
229 1     1 1 851 state $check = compile(Object, Int);
230 1         910 my ($self, $domainid) = $check->(@_);
231 1         17 return $self->_call('GET', "$api_path/domains/$domainid");
232             }
233              
234             sub get_domain_by_name {
235 1     1 0 847 state $check = compile(Object, Str);
236 1         878 my ($self, $domain_name) = $check->(@_);
237 1         17 return $self->_call('GET', "$api_path/domains/byname/$domain_name");
238             }
239              
240             sub create_domain {
241 1     1 1 946 state $check = compile(Object,
242             Dict[
243             name => Str,
244             site_url => Str,
245             status => Bool,
246             accept_inbound => Bool,
247             discard_mail => Bool,
248             smtp_callout => Bool,
249             ldap_callout => Bool,
250             virus_checks => Bool,
251             virus_checks_at_smtp => Bool,
252             block_macros => Bool,
253             spam_checks => Bool,
254             spam_actions => Num,
255             highspam_actions => Num,
256             virus_actions => Num,
257             low_score => Num,
258             high_score => Num,
259             message_size => Str,
260             delivery_mode => Num,
261             language => Str,
262             timezone => Str,
263             report_every => Num,
264             organizations => Num
265             ]);
266 1         31880 my ($self, $data) = $check->(@_);
267 1         279 return $self->_call('POST', "$api_path/domains", $data);
268             }
269              
270             sub update_domain {
271 1     1 1 1484 state $check = compile(Object, Int,
272             Dict[
273             name => Str,
274             site_url => Str,
275             status => Bool,
276             accept_inbound => Bool,
277             discard_mail => Bool,
278             smtp_callout => Bool,
279             ldap_callout => Bool,
280             virus_checks => Bool,
281             virus_checks_at_smtp => Bool,
282             block_macros => Bool,
283             spam_checks => Bool,
284             spam_actions => Num,
285             highspam_actions => Num,
286             virus_actions => Num,
287             low_score => Num,
288             high_score => Num,
289             message_size => Str,
290             delivery_mode => Num,
291             language => Str,
292             timezone => Str,
293             report_every => Num,
294             organizations => Num
295             ]);
296 1         30616 my ($self, $domainid, $data) = $check->(@_);
297 1         272 return $self->_call('PUT', "$api_path/domains/$domainid", $data);
298             }
299              
300             sub delete_domain {
301 1     1 1 5412 state $check = compile(Object, Int);
302 1         1141 my ($self, $domainid) = $check->(@_);
303 1         19 return $self->_call('DELETE', "$api_path/domains/$domainid");
304             }
305              
306             sub get_domainaliases {
307 2     2 1 19538 state $check = compile(Object, Int, Optional[Int]);
308 2         2411 my ($self, $domainid, $page) = $check->(@_);
309 2         111 my $path = "$api_path/domainaliases/$domainid";
310 2 100       10 $path = "$api_path/domainaliases/$domainid?page=$page" unless @_ == 2;
311 2         10 return $self->_call('GET', $path);
312             }
313              
314             sub get_domainalias {
315 1     1 1 1125 state $check = compile(Object, Int, Int);
316 1         1631 my ($self, $domainid, $aliasid) = $check->(@_);
317 1         21 return $self->_call('GET', "$api_path/domainaliases/$domainid/$aliasid");
318             }
319              
320             sub create_domainalias {
321 1     1 1 971 state $check = compile(Object, Int,
322             Dict[
323             name => Str,
324             status => Bool,
325             accept_inbound => Bool,
326             domain => Int
327             ]);
328 1         9536 my ($self, $domainid, $data) = $check->(@_);
329 1         119 return $self->_call('POST', "$api_path/domainaliases/$domainid", $data);
330             }
331              
332             sub update_domainalias {
333 1     1 1 1066 state $check = compile(Object, Int, Int,
334             Dict[
335             name => Str,
336             status => Bool,
337             accept_inbound => Bool,
338             domain => Int
339             ]);
340 1         6780 my ($self, $domainid, $aliasid, $data) = $check->(@_);
341 1         120 return $self->_call('PUT', "$api_path/domainaliases/$domainid/$aliasid", $data);
342             }
343              
344             sub delete_domainalias {
345 1     1 1 1049 state $check = compile(Object, Int, Int,
346             Dict[
347             name => Str,
348             status => Bool,
349             accept_inbound => Bool,
350             domain => Int
351             ]);
352 1         6778 my ($self, $domainid, $aliasid, $data) = $check->(@_);
353 1         117 return $self->_call('DELETE', "$api_path/domainaliases/$domainid/$aliasid", $data);
354             }
355              
356             sub get_deliveryservers {
357 2     2 1 4779 state $check = compile(Object, Int, Optional[Int]);
358 2         2077 my ($self, $domainid, $page) = $check->(@_);
359 2         95 my $path = "$api_path/deliveryservers/$domainid";
360 2 100       9 $path = "$api_path/deliveryservers/$domainid?page=$page" unless @_ == 2;
361 2         6 return $self->_call('GET', $path);
362             }
363              
364             sub get_deliveryserver {
365 1     1 1 1102 state $check = compile(Object, Int, Int);
366 1         1165 my ($self, $domainid, $serverid) = $check->(@_);
367 1         21 return $self->_call('GET', "$api_path/deliveryservers/$domainid/$serverid");
368             }
369              
370             sub create_deliveryserver {
371 1     1 1 1202 state $check = compile(Object, Int,
372             Dict[
373             address => Str,
374             protocol => Int,
375             port => Int,
376             require_tls => Bool,
377             verification_only => Bool,
378             enabled => Bool
379             ]);
380 1         11707 my ($self, $domainid, $data) = $check->(@_);
381 1         128 return $self->_call('POST', "$api_path/deliveryservers/$domainid", $data);
382             }
383              
384             sub update_deliveryserver {
385 1     1 1 1367 state $check = compile(Object, Int, Int,
386             Dict[
387             address => Str,
388             protocol => Int,
389             port => Int,
390             require_tls => Bool,
391             verification_only => Bool,
392             enabled => Bool
393             ]);
394 1         9015 my ($self, $domainid, $serverid, $data) = $check->(@_);
395 1         126 return $self->_call('PUT', "$api_path/deliveryservers/$domainid/$serverid", $data);
396             }
397              
398             sub delete_deliveryserver {
399 1     1 1 1286 state $check = compile(Object, Int, Int,
400             Dict[
401             address => Str,
402             protocol => Int,
403             port => Int,
404             require_tls => Bool,
405             verification_only => Bool,
406             enabled => Bool
407             ]);
408 1         9183 my ($self, $domainid, $serverid, $data) = $check->(@_);
409 1         146 return $self->_call('DELETE', "$api_path/deliveryservers/$domainid/$serverid", $data);
410             }
411              
412             sub get_user_deliveryservers {
413 2     2 1 4765 state $check = compile(Object, Int, Optional[Int]);
414 2         2055 my ($self, $domainid, $page) = $check->(@_);
415 2         95 my $path = "$api_path/userdeliveryservers/$domainid";
416 2 100       10 $path = "$api_path/userdeliveryservers/$domainid?page=$page" unless @_ == 2;
417 2         8 return $self->_call('GET', $path);
418             }
419              
420             sub get_user_deliveryserver {
421 1     1 1 1160 state $check = compile(Object, Int, Int);
422 1         1158 my ($self, $domainid, $serverid) = $check->(@_);
423 1         22 return $self->_call('GET', "$api_path/userdeliveryservers/$domainid/$serverid");
424             }
425              
426             sub create_user_deliveryserver {
427 1     1 1 1175 state $check = compile(Object, Int,
428             Dict[
429             address => Str,
430             protocol => Int,
431             port => Int,
432             require_tls => Bool,
433             verification_only => Bool,
434             enabled => Bool
435             ]);
436 1         11729 my ($self, $domainid, $data) = $check->(@_);
437 1         121 return $self->_call('POST', "$api_path/userdeliveryservers/$domainid", $data);
438             }
439              
440             sub update_user_deliveryserver {
441 1     1 1 1221 state $check = compile(Object, Int, Int,
442             Dict[
443             address => Str,
444             protocol => Int,
445             port => Int,
446             require_tls => Bool,
447             verification_only => Bool,
448             enabled => Bool
449             ]);
450 1         8821 my ($self, $domainid, $serverid, $data) = $check->(@_);
451 1         122 return $self->_call('PUT', "$api_path/userdeliveryservers/$domainid/$serverid", $data);
452             }
453              
454             sub delete_user_deliveryserver {
455 1     1 1 1176 state $check = compile(Object, Int, Int,
456             Dict[
457             address => Str,
458             protocol => Int,
459             port => Int,
460             require_tls => Bool,
461             verification_only => Bool,
462             enabled => Bool
463             ]);
464 1         8863 my ($self, $domainid, $serverid, $data) = $check->(@_);
465 1         118 return $self->_call('DELETE', "$api_path/userdeliveryservers/$domainid/$serverid", $data);
466             }
467              
468             sub get_domain_smarthosts {
469 2     2 1 5913 state $check = compile(Object, Int, Optional[Int]);
470 2         2293 my ($self, $domainid, $page) = $check->(@_);
471 2         106 my $path = "$api_path/domains/smarthosts/$domainid";
472 2 100       10 $path = "$api_path/domains/smarthosts/$domainid?page=$page" unless @_ == 2;
473 2         9 return $self->_call('GET', $path);
474             }
475              
476             sub get_domain_smarthost {
477 2     2 1 2414 state $check = compile(Object, Int, Int);
478 2         1261 my ($self, $domainid, $serverid) = $check->(@_);
479 2         40 return $self->_call('GET', "$api_path/domains/smarthosts/$domainid/$serverid");
480             }
481              
482             sub create_domain_smarthost {
483 1     1 1 1128 state $check = compile(Object, Int,
484             Dict[
485             address => Str,
486             username => Str,
487             password => Str,
488             port => Int,
489             require_tls => Bool,
490             enabled => Bool,
491             description => Str,
492             ]);
493 1         13108 my ($self, $domainid, $data) = $check->(@_);
494 1         157 return $self->_call('POST', "$api_path/domains/smarthosts/$domainid", $data);
495             }
496              
497             sub update_domain_smarthost {
498 1     1 1 1689 state $check = compile(Object, Int, Int,
499             Dict[
500             address => Str,
501             username => Str,
502             password => Str,
503             port => Int,
504             require_tls => Bool,
505             enabled => Bool,
506             description => Str,
507             ]);
508 1         11226 my ($self, $domainid, $serverid, $data) = $check->(@_);
509 1         157 return $self->_call('PUT', "$api_path/domains/smarthosts/$domainid/$serverid", $data);
510             }
511              
512             sub delete_domain_smarthost {
513 1     1 1 1522 state $check = compile(Object, Int, Int,
514             Dict[
515             address => Str,
516             username => Str,
517             password => Str,
518             port => Int,
519             require_tls => Bool,
520             enabled => Bool,
521             description => Str,
522             ]);
523 1         10305 my ($self, $domainid, $serverid, $data) = $check->(@_);
524 1         160 return $self->_call('DELETE', "$api_path/domains/smarthosts/$domainid/$serverid", $data);
525             }
526              
527             sub get_org_smarthosts {
528 2     2 1 5212 state $check = compile(Object, Int, Optional[Int]);
529 2         2018 my ($self, $orgid, $page) = $check->(@_);
530 2         91 my $path = "$api_path/organizations/smarthosts/$orgid";
531 2 100       9 $path = "$api_path/organizations/smarthosts/$orgid?page=$page" unless @_ == 2;
532 2         7 return $self->_call('GET', $path);
533             }
534              
535             sub get_org_smarthost {
536 2     2 1 2259 state $check = compile(Object, Int, Int);
537 2         1128 my ($self, $orgid, $serverid) = $check->(@_);
538 2         36 return $self->_call('GET', "$api_path/organizations/smarthosts/$orgid/$serverid");
539             }
540              
541             sub create_org_smarthost {
542 1     1 1 1161 state $check = compile(Object, Int,
543             Dict[
544             address => Str,
545             username => Str,
546             password => Str,
547             port => Int,
548             require_tls => Bool,
549             enabled => Bool,
550             description => Str,
551             ]);
552 1         12476 my ($self, $orgid, $data) = $check->(@_);
553 1         142 return $self->_call('POST', "$api_path/organizations/smarthosts/$orgid", $data);
554             }
555              
556             sub update_org_smarthost {
557 1     1 1 1389 state $check = compile(Object, Int, Int,
558             Dict[
559             address => Str,
560             username => Str,
561             password => Str,
562             port => Int,
563             require_tls => Bool,
564             enabled => Bool,
565             description => Str,
566             ]);
567 1         9880 my ($self, $orgid, $serverid, $data) = $check->(@_);
568 1         140 return $self->_call('PUT', "$api_path/organizations/smarthosts/$orgid/$serverid", $data);
569             }
570              
571             sub delete_org_smarthost {
572 1     1 1 1357 state $check = compile(Object, Int, Int,
573             Dict[
574             address => Str,
575             username => Str,
576             password => Str,
577             port => Int,
578             require_tls => Bool,
579             enabled => Bool,
580             description => Str,
581             ]);
582 1         10000 my ($self, $orgid, $serverid, $data) = $check->(@_);
583 1         155 return $self->_call('DELETE', "$api_path/organizations/smarthosts/$orgid/$serverid", $data);
584             }
585              
586             sub get_fallbackservers {
587 2     2 1 5082 state $check = compile(Object, Int, Optional[Int]);
588 2         2176 my ($self, $orgid, $page) = $check->(@_);
589 2         99 my $path = "$api_path/fallbackservers/list/$orgid";
590 2 100       10 $path = "$api_path/fallbackservers/list/$orgid?page=$page" unless @_ == 2;
591 2         10 return $self->_call('GET', $path);
592             }
593              
594             sub get_fallbackserver {
595 1     1 1 934 state $check = compile(Object, Int);
596 1         893 my ($self, $serverid) = $check->(@_);
597 1         18 return $self->_call('GET', "$api_path/fallbackservers/$serverid");
598             }
599              
600             sub create_fallbackserver {
601 1     1 1 935 state $check = compile(Object, Int,
602             Dict[
603             address => Str,
604             protocol => Int,
605             port => Int,
606             require_tls => Bool,
607             verification_only => Bool,
608             enabled => Bool
609             ]);
610 1         11635 my ($self, $orgid, $data) = $check->(@_);
611 1         127 return $self->_call('POST', "$api_path/fallbackservers/$orgid", $data);
612             }
613              
614             sub update_fallbackserver {
615 1     1 1 1042 state $check = compile(Object, Int,
616             Dict[
617             address => Str,
618             protocol => Int,
619             port => Int,
620             require_tls => Bool,
621             verification_only => Bool,
622             enabled => Bool
623             ]);
624 1         9183 my ($self, $serverid, $data) = $check->(@_);
625 1         149 return $self->_call('PUT', "$api_path/fallbackservers/$serverid", $data);
626             }
627              
628             sub delete_fallbackserver {
629 1     1 1 1147 state $check = compile(Object, Int,
630             Dict[
631             address => Str,
632             protocol => Int,
633             port => Int,
634             require_tls => Bool,
635             verification_only => Bool,
636             enabled => Bool
637             ]);
638 1         8947 my ($self, $serverid, $data) = $check->(@_);
639 1         159 return $self->_call('DELETE', "$api_path/fallbackservers/$serverid", $data);
640             }
641              
642             sub get_authservers {
643 2     2 1 4802 state $check = compile(Object, Int, Optional[Int]);
644 2         2122 my ($self, $domainid, $page) = $check->(@_);
645 2         96 my $path = "$api_path/authservers/$domainid";
646 2 100       9 $path = "$api_path/authservers/$domainid?page=$page" unless @_ == 2;
647 2         9 return $self->_call('GET', $path);
648             }
649              
650             sub get_authserver {
651 1     1 1 1268 state $check = compile(Object, Int, Int);
652 1         1180 my ($self, $domainid, $serverid) = $check->(@_);
653 1         21 return $self->_call('GET', "$api_path/authservers/$domainid/$serverid");
654             }
655              
656             sub create_authserver {
657 1     1 1 896 state $check = compile(Object, Int,
658             Dict[
659             address => Str,
660             protocol => Int,
661             port => Int,
662             enabled => Bool,
663             split_address => Bool,
664             user_map_template => Str
665             ]);
666 1         12446 my ($self, $domainid, $data) = $check->(@_);
667 1         150 return $self->_call('POST', "$api_path/authservers/$domainid", $data);
668             }
669              
670             sub update_authserver {
671 1     1 1 1600 state $check = compile(Object, Int, Int,
672             Dict[
673             address => Str,
674             protocol => Int,
675             port => Int,
676             enabled => Bool,
677             split_address => Bool,
678             user_map_template => Str
679             ]);
680 1         9709 my ($self, $domainid, $serverid, $data) = $check->(@_);
681 1         189 return $self->_call('PUT', "$api_path/authservers/$domainid/$serverid", $data);
682             }
683              
684             sub delete_authserver {
685 1     1 1 1591 state $check = compile(Object, Int, Int,
686             Dict[
687             address => Str,
688             protocol => Int,
689             port => Int,
690             enabled => Bool,
691             split_address => Bool,
692             user_map_template => Str
693             ]);
694 1         9750 my ($self, $domainid, $serverid, $data) = $check->(@_);
695 1         149 return $self->_call('DELETE', "$api_path/authservers/$domainid/$serverid", $data);
696             }
697              
698             sub get_ldapsettings {
699 1     1 1 12734 state $check = compile(Object, Int, Int, Int);
700 1         1660 my ($self, $domainid, $serverid, $settingsid) = $check->(@_);
701 1         38 return $self->_call('GET', "$api_path/ldapsettings/$domainid/$serverid/$settingsid");
702             }
703              
704             sub create_ldapsettings {
705 1     1 1 966 state $check = compile(Object, Int, Int,
706             Dict[
707             basedn => Str,
708             nameattribute => Str,
709             emailattribute => Str,
710             binddn => Str,
711             bindpw => Str,
712             usetls => Bool,
713             usesearch => Bool,
714             searchfilter => Str,
715             search_scope => Str,
716             emailsearchfilter => Str,
717             emailsearch_scope => Str
718             ]);
719 1         18089 my ($self, $domainid, $serverid, $data) = $check->(@_);
720 1         211 return $self->_call('POST', "$api_path/ldapsettings/$domainid/$serverid", $data);
721             }
722              
723             sub update_ldapsettings {
724 1     1 1 1061 state $check = compile(Object, Int, Int, Int,
725             Dict[
726             basedn => Str,
727             nameattribute => Str,
728             emailattribute => Str,
729             binddn => Str,
730             bindpw => Str,
731             usetls => Bool,
732             usesearch => Bool,
733             searchfilter => Str,
734             search_scope => Str,
735             emailsearchfilter => Str,
736             emailsearch_scope => Str
737             ]);
738 1         15403 my ($self, $domainid, $serverid, $settingsid, $data) = $check->(@_);
739 1         208 return $self->_call('PUT', "$api_path/ldapsettings/$domainid/$serverid/$settingsid", $data);
740             }
741              
742             sub delete_ldapsettings {
743 1     1 1 1080 state $check = compile(Object, Int, Int, Int,
744             Dict[
745             basedn => Str,
746             nameattribute => Str,
747             emailattribute => Str,
748             binddn => Str,
749             bindpw => Str,
750             usetls => Bool,
751             usesearch => Bool,
752             searchfilter => Str,
753             search_scope => Str,
754             emailsearchfilter => Str,
755             emailsearch_scope => Str
756             ]);
757 1         15779 my ($self, $domainid, $serverid, $settingsid, $data) = $check->(@_);
758 1         207 return $self->_call('DELETE', "$api_path/ldapsettings/$domainid/$serverid/$settingsid", $data);
759             }
760              
761             sub get_radiussettings {
762 1     1 1 3725 state $check = compile(Object, Int, Int, Int);
763 1         1676 my ($self, $domainid, $serverid, $settingsid) = $check->(@_);
764 1         34 return $self->_call('GET', "$api_path/radiussettings/$domainid/$serverid/$settingsid");
765             }
766              
767             sub create_radiussettings {
768 1     1 1 1036 state $check = compile(Object, Int, Int,
769             Dict[
770             secret => Str,
771             timeout => Int
772             ]);
773 1         8017 my ($self, $domainid, $serverid, $data) = $check->(@_);
774 1         106 return $self->_call('POST', "$api_path/radiussettings/$domainid/$serverid", $data);
775             }
776              
777             sub update_radiussettings {
778 1     1 1 1495 state $check = compile(Object, Int, Int, Int,
779             Dict[
780             secret => Str,
781             timeout => Int
782             ]);
783 1         5574 my ($self, $domainid, $serverid, $settingsid, $data) = $check->(@_);
784 1         116 return $self->_call('PUT', "$api_path/radiussettings/$domainid/$serverid/$settingsid", $data);
785             }
786              
787             sub delete_radiussettings {
788 1     1 1 1395 state $check = compile(Object, Int, Int, Int,
789             Dict[
790             secret => Str,
791             timeout => Int
792             ]);
793 1         5572 my ($self, $domainid, $serverid, $settingsid, $data) = $check->(@_);
794 1         422 return $self->_call('DELETE', "$api_path/radiussettings/$domainid/$serverid/$settingsid", $data);
795             }
796              
797             sub get_organizations {
798 2     2 1 2685 state $check = compile(Object, Optional[Int]);
799 2         1589 my ($self, $page) = $check->(@_);
800 2         74 my $path = "$api_path/organizations";
801 2 100       9 $path = "$api_path/organizations?page=$page" unless @_ == 1;
802 2         8 return $self->_call('GET', $path);
803             }
804              
805             sub get_organization {
806 1     1 1 1142 state $check = compile(Object, Int);
807 1         974 my ($self, $orgid) = $check->(@_);
808 1         18 return $self->_call('GET', "$api_path/organizations/$orgid");
809             }
810              
811             sub create_organization {
812 1     1 1 4583 state $check = compile(Object,
813             Dict[
814             name => Str,
815             domains => ArrayRef,
816             admins => ArrayRef
817             ]);
818 1         8282 my ($self, $data) = $check->(@_);
819 1         125 return $self->_call('POST', "$api_path/organizations", $data);
820             }
821              
822             sub update_organization {
823 1     1 1 1204 state $check = compile(Object, Int,
824             Dict[
825             name => Str,
826             domains => ArrayRef,
827             admins => ArrayRef
828             ]);
829 1         5488 my ($self, $orgid, $data) = $check->(@_);
830 1         109 return $self->_call('PUT', "$api_path/organizations/$orgid", $data);
831             }
832              
833             sub delete_organization {
834 1     1 1 1384 state $check = compile(Object, Int);
835 1         896 my ($self, $orgid) = $check->(@_);
836 1         18 return $self->_call('DELETE', "$api_path/organizations/$orgid");
837             }
838              
839             sub get_relay {
840 1     1 1 1109 state $check = compile(Object, Int);
841 1         840 my ($self, $relayid) = $check->(@_);
842 1         16 return $self->_call('GET', "$api_path/relays/$relayid");
843             }
844              
845             sub create_relay {
846 1     1 1 3581 state $check = compile(Object, Int,
847             Dict[
848             address => Str,
849             username => Str,
850             enabled => Bool,
851             require_tls => Bool,
852             password1 => Str,
853             password2 => Str,
854             description => Str,
855             low_score => Num,
856             high_score => Num,
857             spam_actions => Int,
858             highspam_actions => Int,
859             block_macros => Bool,
860             ratelimit => Int
861             ]);
862 1         21025 my ($self, $orgid, $data) = $check->(@_);
863 1         197 return $self->_call('POST', "$api_path/relays/$orgid", $data);
864             }
865              
866             sub update_relay {
867 1     1 1 949 state $check = compile(Object, Int,
868             Dict[
869             address => Str,
870             username => Str,
871             enabled => Bool,
872             require_tls => Bool,
873             password1 => Str,
874             password2 => Str,
875             description => Str,
876             low_score => Num,
877             high_score => Num,
878             spam_actions => Int,
879             highspam_actions => Int,
880             block_macros => Bool,
881             ratelimit => Int
882             ]);
883 1         17953 my ($self, $relayid, $data) = $check->(@_);
884 1         175 return $self->_call('PUT', "$api_path/relays/$relayid", $data);
885             }
886              
887             sub delete_relay {
888 1     1 1 1088 state $check = compile(Object, Int,
889             Dict[
890             address => Str,
891             username => Str,
892             enabled => Bool,
893             require_tls => Bool,
894             password1 => Str,
895             password2 => Str,
896             description => Str,
897             low_score => Num,
898             high_score => Num,
899             spam_actions => Int,
900             highspam_actions => Int,
901             block_macros => Bool,
902             ratelimit => Int
903             ]);
904 1         17945 my ($self, $relayid, $data) = $check->(@_);
905 1         195 return $self->_call('DELETE', "$api_path/relays/$relayid", $data);
906             }
907              
908             sub get_status {
909 1     1 1 3910 state $check = compile(Object);
910 1         716 my ($self) = $check->(@_);
911 1         18 return $self->_call('GET', "$api_path/status");
912             }
913              
914 17     17   133827 no Moo;
  17         40  
  17         122  
915              
916             1;
917              
918             __END__