From 7da3204e3bc2bd8ffbdad8764370a64d477a87fb Mon Sep 17 00:00:00 2001 From: John Gile Date: Tue, 9 Aug 2016 13:12:44 -0500 Subject: [PATCH] Droplet Pagination add per_page parameter add page parameter --- spec/DigitalOceanV2/Api/DropletSpec.php | 4 ++-- src/Api/Droplet.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spec/DigitalOceanV2/Api/DropletSpec.php b/spec/DigitalOceanV2/Api/DropletSpec.php index 120a5312..2a77e62c 100644 --- a/spec/DigitalOceanV2/Api/DropletSpec.php +++ b/spec/DigitalOceanV2/Api/DropletSpec.php @@ -19,7 +19,7 @@ function it_is_initializable() function it_returns_an_empty_array($adapter) { - $adapter->get('https://api.digitalocean.com/v2/droplets?per_page=200')->willReturn('{"droplets": []}'); + $adapter->get('https://api.digitalocean.com/v2/droplets?per_page=200&page=1')->willReturn('{"droplets": []}'); $droplets = $this->getAll(); $droplets->shouldBeArray(); @@ -30,7 +30,7 @@ function it_returns_an_array_of_droplet_entity($adapter) { $total = 3; $adapter - ->get('https://api.digitalocean.com/v2/droplets?per_page=200') + ->get('https://api.digitalocean.com/v2/droplets?per_page=200&page=1') ->willReturn(sprintf('{"droplets": [{},{},{}], "meta": {"total": %d}}', $total)); $droplets = $this->getAll(); diff --git a/src/Api/Droplet.php b/src/Api/Droplet.php index abc0afc9..b71ccd0d 100644 --- a/src/Api/Droplet.php +++ b/src/Api/Droplet.php @@ -24,12 +24,15 @@ */ class Droplet extends AbstractApi { - /** - * @return DropletEntity[] - */ - public function getAll() + /** + * @param int $per_page + * @param int $page + * + * @return DropletEntity[] + */ + public function getAll($per_page = 200, $page = 1) { - $droplets = $this->adapter->get(sprintf('%s/droplets?per_page=%d', $this->endpoint, 200)); + $droplets = $this->adapter->get(sprintf('%s/droplets?per_page=%d&page=%d', $this->endpoint, $per_page, $page)); $droplets = json_decode($droplets);