Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 10 additions & 43 deletions src/eCloud/InstanceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace UKFast\SDK\eCloud;

use GuzzleHttp\Exception\GuzzleException;
use UKFast\SDK\eCloud\Entities\Volume;
use UKFast\SDK\Entities\ClientEntityInterface;
use UKFast\SDK\Exception\UKFastException;
use UKFast\SDK\Traits\PageItems;
Expand Down Expand Up @@ -82,51 +84,16 @@ public function getCredentials($id)

/**
* Get array of instance volumes
* @param $id
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
* @param string $id
* @param array<string, mixed> $filters
* @return array<int, Volume>
* @throws GuzzleException
*/
public function getVolumes($id)
public function getVolumes($id, $filters = [])
{
$page = $this->paginatedRequest(
$this->collectionPath . '/' . $id . '/volumes',
$currentPage = 1,
$perPage = 15
);

if ($page->totalItems() == 0) {
return [];
}

$volumeClient = new VolumeClient;
$page->serializeWith(function ($item) use ($volumeClient) {
return $volumeClient->loadEntity($item);
});

$items = $page->getItems();
if ($page->totalPages() == 1) {
return $items;
}

// get any remaining pages
while ($page->pageNumber() < $page->totalPages()) {
$page = $this->paginatedRequest(
$this->collectionPath . '/' . $id . '/volumes',
$currentPage++,
$perPage
);

$page->serializeWith(function ($item) use ($volumeClient) {
return $volumeClient->loadEntity($item);
});

$items = array_merge(
$items,
$page->getItems()
);
}

return $items;
return $this->getChildResources($id, 'volumes', function ($data) {
return (new VolumeClient())->loadEntity($data);
}, $filters);
}

/**
Expand Down