From 3d14f51843423ac91d287960caf44eb5e52dc80e Mon Sep 17 00:00:00 2001 From: Enrique Perez Date: Tue, 28 Nov 2017 09:52:06 -0800 Subject: [PATCH] added limit property to getAll methods, and fixed unit tests --- src/GhostIO.php | 8 ++++---- src/Providers/PostProvider.php | 14 ++++++++------ src/Providers/UserProvider.php | 8 +++++--- tests/Providers/PostProviderTest.php | 8 +++++++- tests/Providers/UserProviderTest.php | 11 ++++++++--- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/GhostIO.php b/src/GhostIO.php index 3093350..b9ba9a4 100644 --- a/src/GhostIO.php +++ b/src/GhostIO.php @@ -33,10 +33,10 @@ public function __construct($url, $username, $password, $clientId, $clientSecret * because it will get all the records if you limit the request as "all" * @return Collection All posts */ - public function getAllPosts(array $fields = []) + public function getAllPosts(array $fields = [], $limit = 15) { $provider = PostProvider::getInstance($this->client); - return $provider->getAll($fields); + return $provider->getAll($fields, $limit); } /** @@ -96,10 +96,10 @@ public function getTagBySlug($slug) * Method to get all the Users of the account. * @return Collection All users */ - public function getAllUsers(array $fields = []) + public function getAllUsers(array $fields = [], $limit = 15) { $provider = UserProvider::getInstance($this->client); - return $provider->getAll($fields); + return $provider->getAll($fields, $limit); } /** diff --git a/src/Providers/PostProvider.php b/src/Providers/PostProvider.php index a9e1341..828554b 100644 --- a/src/Providers/PostProvider.php +++ b/src/Providers/PostProvider.php @@ -15,16 +15,18 @@ class PostProvider * because it will get all the records if you limit the request as "all" * @return Collection All posts */ - public function getAll(array $fields = []) + public function getAll(array $fields = [], $limit = 15) { - $options = []; - - // We include all the tag information by default - $options['query'] = [ 'include' => ['tags'] ]; + $options = [ + 'query' => [ + 'limit' => $limit, + 'include' => [ 'tags' ] // We include all the tag information by default + ] + ]; // filtering the fields we want to get if (!empty($fields)) { - $options['query'] = [ 'fields' => $fields ]; + $options['query']['fields'] = $fields; } // Do the /posts request diff --git a/src/Providers/UserProvider.php b/src/Providers/UserProvider.php index d934e7c..a3e294f 100644 --- a/src/Providers/UserProvider.php +++ b/src/Providers/UserProvider.php @@ -14,13 +14,15 @@ class UserProvider * Method to get all the users of the account. * @return Collection All users */ - public function getAll(array $fields = []) + public function getAll(array $fields = [], $limit = 15) { - $options = []; + $options = [ + 'query' => ['limit' => $limit ] + ]; // filtering the fields we want to get if (!empty($fields)) { - $options['query'] = [ 'fields' => $fields ]; + $options['query']['fields'] = $fields; } // Do the /users request diff --git a/tests/Providers/PostProviderTest.php b/tests/Providers/PostProviderTest.php index 76f1fce..cfaae3f 100644 --- a/tests/Providers/PostProviderTest.php +++ b/tests/Providers/PostProviderTest.php @@ -78,7 +78,13 @@ public function testProvidersCanGetAllPostsWithFieldsParameter() ->with( $this->equalTo('GET'), $this->equalTo('posts'), - [ 'query' => [ 'fields' => ['id', 'html']] ] + [ + 'query' => [ + 'fields' => ['id', 'html'], + 'limit' => 15, + 'include' => ['tags'] + ] + ] ) ->willReturn($apiResponse); diff --git a/tests/Providers/UserProviderTest.php b/tests/Providers/UserProviderTest.php index 3810a23..28d3e22 100644 --- a/tests/Providers/UserProviderTest.php +++ b/tests/Providers/UserProviderTest.php @@ -76,9 +76,14 @@ public function testProvidersCanGetAllUsersWithFieldsParameter() $this->clientMock->expects($this->once()) ->method('request') ->with( - $this->equalTo('GET'), - $this->equalTo('users'), - [ 'query' => [ 'fields' => ['id', 'html']] ] + $this->equalTo('GET'), + $this->equalTo('users'), + [ + 'query' => [ + 'fields' => ['id', 'html'], + 'limit' => 15 + ] + ] ) ->willReturn($apiResponse);