From 5522af5f70462dd9984b9ccb0d351f8dab5b16fa Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Thu, 21 Jan 2021 16:51:03 +0100 Subject: [PATCH] api: statistics: refactor return for detail calls 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 --- src/PMG/API2/Statistics.pm | 109 ++++++++++++++----------------------- 1 file changed, 40 insertions(+), 69 deletions(-) diff --git a/src/PMG/API2/Statistics.pm b/src/PMG/API2/Statistics.pm index adc7650..064865d 100644 --- a/src/PMG/API2/Statistics.pm +++ b/src/PMG/API2/Statistics.pm @@ -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 { -- 2.39.5