From c1641270c055e6a58af4171d3d034cd09dfe5b2d Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 10 Aug 2022 16:07:35 +1000 Subject: [PATCH] Created fetch() method to handle fetchall requests --- src/API.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/API.php b/src/API.php index b013ebc..8f300bc 100644 --- a/src/API.php +++ b/src/API.php @@ -118,18 +118,8 @@ final class API return $result; } - /** - * Get a list of our clients - * - * @param array $parameters - * @return Generic - * @throws \Exception - */ - public function getCustomers(array $parameters=[]): Generic + private function fetch(string $path,array $parameters,string $key): Base { - Log::debug(sprintf('%s:Get a list of customers',static::LOGKEY)); - $key = 'customers'; - $fetchall = FALSE; if (Arr::get($parameters,'fetchall')) { Arr::forget($parameters,['fetchall']); @@ -139,9 +129,9 @@ final class API $fetchall = TRUE; } - $o = new Generic($this->execute($key,$parameters),$key); + $o = new Generic($this->execute($path,$parameters),$key); - return $fetchall ? $this->fetchall($o,$key,$parameters) : $o; + return $fetchall ? $this->fetchall($o,$path,$parameters) : $o; } private function fetchall(Base $o,string $path,array $parameters): Base @@ -155,6 +145,20 @@ final class API return $o; } + /** + * Get a list of our clients + * + * @param array $parameters + * @return Generic + * @throws \Exception + */ + public function getCustomers(array $parameters=[]): Generic + { + Log::debug(sprintf('%s:Get a list of customers',static::LOGKEY)); + + return $this->fetch('customers',$parameters,'customers'); + } + /** * Get a list of our clients domains * @@ -166,7 +170,7 @@ final class API { Log::debug(sprintf('%s:Get a list of domains',static::LOGKEY)); - return new Generic($this->execute('domains',$parameters),'domains'); + return $this->fetch('domains',$parameters,'domains'); } /**