Skip to content

Commit 3d14f51

Browse files
committed
added limit property to getAll methods, and fixed unit tests
1 parent 7f2cffe commit 3d14f51

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

src/GhostIO.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public function __construct($url, $username, $password, $clientId, $clientSecret
3333
* because it will get all the records if you limit the request as "all"
3434
* @return Collection All posts
3535
*/
36-
public function getAllPosts(array $fields = [])
36+
public function getAllPosts(array $fields = [], $limit = 15)
3737
{
3838
$provider = PostProvider::getInstance($this->client);
39-
return $provider->getAll($fields);
39+
return $provider->getAll($fields, $limit);
4040
}
4141

4242
/**
@@ -96,10 +96,10 @@ public function getTagBySlug($slug)
9696
* Method to get all the Users of the account.
9797
* @return Collection All users
9898
*/
99-
public function getAllUsers(array $fields = [])
99+
public function getAllUsers(array $fields = [], $limit = 15)
100100
{
101101
$provider = UserProvider::getInstance($this->client);
102-
return $provider->getAll($fields);
102+
return $provider->getAll($fields, $limit);
103103
}
104104

105105
/**

src/Providers/PostProvider.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ class PostProvider
1515
* because it will get all the records if you limit the request as "all"
1616
* @return Collection All posts
1717
*/
18-
public function getAll(array $fields = [])
18+
public function getAll(array $fields = [], $limit = 15)
1919
{
20-
$options = [];
21-
22-
// We include all the tag information by default
23-
$options['query'] = [ 'include' => ['tags'] ];
20+
$options = [
21+
'query' => [
22+
'limit' => $limit,
23+
'include' => [ 'tags' ] // We include all the tag information by default
24+
]
25+
];
2426

2527
// filtering the fields we want to get
2628
if (!empty($fields)) {
27-
$options['query'] = [ 'fields' => $fields ];
29+
$options['query']['fields'] = $fields;
2830
}
2931

3032
// Do the /posts request

src/Providers/UserProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ class UserProvider
1414
* Method to get all the users of the account.
1515
* @return Collection All users
1616
*/
17-
public function getAll(array $fields = [])
17+
public function getAll(array $fields = [], $limit = 15)
1818
{
19-
$options = [];
19+
$options = [
20+
'query' => ['limit' => $limit ]
21+
];
2022

2123
// filtering the fields we want to get
2224
if (!empty($fields)) {
23-
$options['query'] = [ 'fields' => $fields ];
25+
$options['query']['fields'] = $fields;
2426
}
2527

2628
// Do the /users request

tests/Providers/PostProviderTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ public function testProvidersCanGetAllPostsWithFieldsParameter()
7878
->with(
7979
$this->equalTo('GET'),
8080
$this->equalTo('posts'),
81-
[ 'query' => [ 'fields' => ['id', 'html']] ]
81+
[
82+
'query' => [
83+
'fields' => ['id', 'html'],
84+
'limit' => 15,
85+
'include' => ['tags']
86+
]
87+
]
8288
)
8389
->willReturn($apiResponse);
8490

tests/Providers/UserProviderTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ public function testProvidersCanGetAllUsersWithFieldsParameter()
7676
$this->clientMock->expects($this->once())
7777
->method('request')
7878
->with(
79-
$this->equalTo('GET'),
80-
$this->equalTo('users'),
81-
[ 'query' => [ 'fields' => ['id', 'html']] ]
79+
$this->equalTo('GET'),
80+
$this->equalTo('users'),
81+
[
82+
'query' => [
83+
'fields' => ['id', 'html'],
84+
'limit' => 15
85+
]
86+
]
8287
)
8388
->willReturn($apiResponse);
8489

0 commit comments

Comments
 (0)