diff --git a/src/Api/Abstracts/AbstractAllApi.php b/src/Api/Abstracts/AbstractAllApi.php new file mode 100644 index 0000000..55a8b30 --- /dev/null +++ b/src/Api/Abstracts/AbstractAllApi.php @@ -0,0 +1,85 @@ +getMaxPageCount(); + $itemsPerPage = $this->getItemsPerPage(); + // Loop over pages until the $maxPageCount is reached + for ($pageNum=1; $pageNum < $maxPageCount; $pageNum++) { + $searchItemsCollection = $this->getPageOfAllItems($pageNum, $itemsPerPage); + if ($searchItemsCollection && $searchItemsCollection->count() > 0) { + $searchItemsArray = $searchItemsCollection->toArray(); + $allItems = array_merge($allItems, $searchItemsArray); + } else { + break; + } + } + return new ApiItemCollection($allItems); + } + + public function getMaxPageCount() { + return $this->maxPageCount; + } + + public function getItemsPerPage() { + return $this->itemsPerPage; + } + +} diff --git a/src/Api/AbstractApi.php b/src/Api/Abstracts/AbstractApi.php similarity index 89% rename from src/Api/AbstractApi.php rename to src/Api/Abstracts/AbstractApi.php index 7726877..e81c769 100644 --- a/src/Api/AbstractApi.php +++ b/src/Api/Abstracts/AbstractApi.php @@ -1,15 +1,17 @@ preparePath($path, $parameters); - - return $this->client->getHttpClient()->get($path, $requestHeaders); - } - /** * @param string $path * @param array $parameters * @param array $requestHeaders * @return mixed */ - protected function get($path, array $parameters = array(), $requestHeaders = array(), $debugRequest = false) + public function get($path, array $parameters = array(), $requestHeaders = array(), $debugRequest = false) { $client = $this->getClient(); $guzzleClient = $client->getGuzzleClient(); @@ -221,7 +208,7 @@ abstract class AbstractApi * @param array $requestHeaders * @return mixed */ - protected function post($path, $body, $requestHeaders = array(), $debugRequest = false) + public function post($path, $body, $requestHeaders = array(), $debugRequest = false) { $client = $this->getClient(); $guzzleClient = $client->getGuzzleClient(); @@ -259,7 +246,7 @@ abstract class AbstractApi * @param array $requestHeaders * @return mixed */ - protected function put($path, $body, $requestHeaders = array(), $debugRequest = false) + public function put($path, $body, $requestHeaders = array(), $debugRequest = false) { $client = $this->getClient(); $guzzleClient = $client->getGuzzleClient(); @@ -296,7 +283,7 @@ abstract class AbstractApi * @param array $requestHeaders * @return mixed */ - protected function delete($path, $requestHeaders = array(), $debugRequest = false) + public function delete($path, $requestHeaders = array(), $debugRequest = false) { $client = $this->getClient(); $guzzleClient = $client->getGuzzleClient(); diff --git a/src/Api/Interfaces/AllApiInterface.php b/src/Api/Interfaces/AllApiInterface.php new file mode 100644 index 0000000..85e278f --- /dev/null +++ b/src/Api/Interfaces/AllApiInterface.php @@ -0,0 +1,53 @@ +getMaxPageCount(); - // Loop over pages until the $maxPageCount is reached - for ($pageNum=1; $pageNum < $maxPageCount; $pageNum++) { - $searchItemsCollection = $this->search("", $pageNum); - if ($searchItemsCollection && $searchItemsCollection->count() > 0) { - $searchItemsArray = $searchItemsCollection->toArray(); - $allItems = array_merge($allItems, $searchItemsArray); - } else { - break; - } - } - return new ApiItemCollection($allItems); + public function getPageOfAllItems(int $page = 1, int $limit = null, array $extraOptions = array()) { + return $this->search("", $page, $limit, $extraOptions); } /** @@ -67,8 +39,6 @@ class Repositories extends AbstractApi * @param integer $page The page of items to return * @param integer $limit Maximum number of items per page * @param array $extraOptions An array of extra options to pass the API reoute - * @return void - * * @return ApiItemCollection */ public function search(string $keyword = "", int $page = 1, int $limit = null, array $extraOptions = array()) @@ -104,12 +74,4 @@ class Repositories extends AbstractApi } } - public function getMaxPageCount() { - return $this->maxPageCount; - } - - public function getItemsPerPage() { - return $this->itemsPerPage; - } - }