[pmg-devel] [PATCH pmg-api 2/5] api: statistics: refactor return for detail calls

Stoiko Ivanov s.ivanov at proxmox.com
Fri Jan 15 10:46:22 CET 2021


all api methods returning information for a particular sender,
receiver or contact have similar returns.

This commit pulls the common ones out into a hash for reusing them.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/API2/Statistics.pm | 90 ++++++++++++--------------------------
 1 file changed, 27 insertions(+), 63 deletions(-)

diff --git a/src/PMG/API2/Statistics.pm b/src/PMG/API2/Statistics.pm
index adc7650..0d12dd3 100644
--- a/src/PMG/API2/Statistics.pm
+++ b/src/PMG/API2/Statistics.pm
@@ -257,6 +257,30 @@ __PACKAGE__->register_method ({
 	return $res;
     }});
 
+my %detail_return_properties = (
+    time => {
+	description => "Receive time stamp",
+	type => 'integer',
+    },
+    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,
+    },
+);
+
 __PACKAGE__->register_method ({
     name => 'contactdetails',
     path => 'contact/{contact}',
@@ -283,31 +307,11 @@ __PACKAGE__->register_method ({
 	items => {
 	    type => "object",
 	    properties => {
-		time => {
-		    description => "Receive time stamp",
-		    type => 'integer',
-		},
+		%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,
-		},
 	    },
 	},
     },
@@ -422,31 +426,11 @@ __PACKAGE__->register_method ({
 	items => {
 	    type => "object",
 	    properties => {
-		time => {
-		    description => "Receive time stamp",
-		    type => 'integer',
-		},
+		%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,
-		},
 	    },
 	},
     },
@@ -569,31 +553,11 @@ __PACKAGE__->register_method ({
 	items => {
 	    type => "object",
 	    properties => {
-		time => {
-		    description => "Receive time stamp",
-		    type => 'integer',
-		},
+		%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,
-		},
 	    },
 	},
     },
-- 
2.20.1





More information about the pmg-devel mailing list