]> git.proxmox.com Git - pmg-api.git/commitdiff
api: statistics: refactor return for detail calls
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 21 Jan 2021 15:51:03 +0000 (16:51 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 27 Jan 2021 08:28:42 +0000 (09:28 +0100)
all api methods returning information for a particular sender,
receiver or contact have similar returns.

This commit pulls the common ones out into a sub like the common method
parameters in $default_properties.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/API2/Statistics.pm

index adc7650b17548ecf52c5c85648e0206118a0a798..064865d6d39ef7e773e2df231ef29589112ac410 100644 (file)
@@ -257,6 +257,40 @@ __PACKAGE__->register_method ({
        return $res;
     }});
 
+my $detail_return_properties = sub {
+    my ($prop) = @_;
+
+    $prop //= {};
+
+    $prop->{time} = {
+       description => "Receive time stamp",
+       type => 'integer',
+    };
+
+    $prop->{bytes} = {
+       description => "Mail traffic (Bytes).",
+       type => 'number',
+    };
+
+    $prop->{blocked} = {
+       description => "Mail was blocked.",
+       type => 'boolean',
+    };
+
+    $prop->{spamlevel} = {
+       description => "Spam score.",
+       type => 'number',
+    };
+
+    $prop->{virusinfo} = {
+       description => "Virus name.",
+       type => 'string',
+       optional => 1,
+    };
+
+    return $prop;
+};
+
 __PACKAGE__->register_method ({
     name => 'contactdetails',
     path => 'contact/{contact}',
@@ -282,33 +316,12 @@ __PACKAGE__->register_method ({
        type => 'array',
        items => {
            type => "object",
-           properties => {
-               time => {
-                   description => "Receive time stamp",
-                   type => 'integer',
-               },
+           properties => $detail_return_properties->({
                sender => {
                    description => "Sender email.",
                    type => 'string',
                },
-               bytes => {
-                   description => "Mail traffic (Bytes).",
-                   type => 'number',
-               },
-               blocked => {
-                   description => "Mail was blocked.",
-                   type => 'boolean',
-               },
-               spamlevel => {
-                   description => "Spam score.",
-                   type => 'number',
-               },
-               virusinfo => {
-                   description => "Virus name.",
-                   type => 'string',
-                   optional => 1,
-               },
-           },
+           }),
        },
     },
     code => sub {
@@ -421,33 +434,12 @@ __PACKAGE__->register_method ({
        type => 'array',
        items => {
            type => "object",
-           properties => {
-               time => {
-                   description => "Receive time stamp",
-                   type => 'integer',
-               },
+           properties => $detail_return_properties->({
                receiver => {
                    description => "Receiver email.",
                    type => 'string',
                },
-               bytes => {
-                   description => "Mail traffic (Bytes).",
-                   type => 'number',
-               },
-               blocked => {
-                   description => "Mail was blocked.",
-                   type => 'boolean',
-               },
-               spamlevel => {
-                   description => "Spam score.",
-                   type => 'number',
-               },
-               virusinfo => {
-                   description => "Virus name.",
-                   type => 'string',
-                   optional => 1,
-               },
-           },
+           }),
        },
     },
     code => sub {
@@ -568,33 +560,12 @@ __PACKAGE__->register_method ({
        type => 'array',
        items => {
            type => "object",
-           properties => {
-               time => {
-                   description => "Receive time stamp",
-                   type => 'integer',
-               },
+           properties => $detail_return_properties->({
                sender => {
                    description => "Sender email.",
                    type => 'string',
                },
-               bytes => {
-                   description => "Mail traffic (Bytes).",
-                   type => 'number',
-               },
-               blocked => {
-                   description => "Mail was blocked.",
-                   type => 'boolean',
-               },
-               spamlevel => {
-                   description => "Spam score.",
-                   type => 'number',
-               },
-               virusinfo => {
-                   description => "Virus name.",
-                   type => 'string',
-                   optional => 1,
-               },
-           },
+           }),
        },
     },
     code => sub {