Skip to content

Commit 3972020

Browse files
author
Paul McNally
committed
add endpoint for az prices
1 parent 9616fb7 commit 3972020

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/eCloud/AvailabilityZoneClient.php

+39
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace UKFast\SDK\eCloud;
44

5+
use UKFast\SDK\eCloud\Entities\Product;
56
use UKFast\SDK\Entities\ClientEntityInterface;
67
use UKFast\SDK\Traits\PageItems;
78
use UKFast\SDK\eCloud\Entities\AvailabilityZone;
@@ -28,4 +29,42 @@ public function getEntityMap()
2829
'datacentre_site_id' => 'datacentreSiteId'
2930
];
3031
}
32+
33+
/**
34+
* Get an array of all products and prices for the availability zone
35+
*
36+
* @param int $id Region ID
37+
* @param array $filters
38+
* @return array
39+
*/
40+
public function getProducts($id, $filters = [])
41+
{
42+
$page = $this->paginatedRequest($this->collectionPath . '/' . $id . '/prices', 1, 15, $filters);
43+
44+
if ($page->totalItems() == 0) {
45+
return [];
46+
}
47+
48+
$loadEntity = function ($data) {
49+
return new Product($this->apiToFriendly($data, Product::$entityMap));
50+
};
51+
52+
$page->serializeWith($loadEntity);
53+
54+
$items = $page->getItems();
55+
if ($page->totalPages() == 1) {
56+
return $items;
57+
}
58+
59+
while ($page->pageNumber() < $page->totalPages()) {
60+
$page = $this->getPage($page->pageNumber() + 1, 15, $filters);
61+
62+
$page->serializeWith($loadEntity);
63+
$items = array_merge(
64+
$items,
65+
$page->getItems()
66+
);
67+
}
68+
return $items;
69+
}
3170
}

0 commit comments

Comments
 (0)