From f093454ecf123f11137c9d5ed971f9e09522f63e Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Thu, 25 Apr 2013 13:18:55 +0000 Subject: [PATCH 1/3] Fetches data from all pages (in case there are more that 30 items) --- lib/Github/Api/AbstractApi.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index be6063d3cfb..56b07d4193f 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -36,8 +36,16 @@ public function configure() protected function get($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); + $responseContent = $response->getContent(); + $pagination = $response->getPagination(); + if (isset($pagination['next'])) { + $nextPageResponse = $this->get(str_replace($this->client->getOption('base_url'), '', $pagination['next']), $parameters, $requestHeaders); + foreach ($nextPageResponse as $item) { + $responseContent[] = $item; + } + } - return $response->getContent(); + return $responseContent; } /** From 75939fec8a1135ab63524ac21ea9e24152cddf7c Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Fri, 26 Apr 2013 14:13:37 +0000 Subject: [PATCH 2/3] Removed recursion, use per_page attribute instead --- lib/Github/Api/AbstractApi.php | 10 +--------- lib/Github/Api/Organization.php | 6 ++++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 56b07d4193f..be6063d3cfb 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -36,16 +36,8 @@ public function configure() protected function get($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); - $responseContent = $response->getContent(); - $pagination = $response->getPagination(); - if (isset($pagination['next'])) { - $nextPageResponse = $this->get(str_replace($this->client->getOption('base_url'), '', $pagination['next']), $parameters, $requestHeaders); - foreach ($nextPageResponse as $item) { - $responseContent[] = $item; - } - } - return $responseContent; + return $response->getContent(); } /** diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 29f23ccf2d7..6c5cdc86b46 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -38,13 +38,15 @@ public function update($organization, array $params) * * @param string $organization the user name * @param string $type the type of repositories + * @param int $items_per_page the number of items per page * * @return array the repositories */ - public function repositories($organization, $type = 'all') + public function repositories($organization, $type = 'all', $items_per_page = 30) { return $this->get('orgs/'.urlencode($organization).'/repos', array( - 'type' => $type + 'type' => $type, + 'per_page' => $items_per_page, )); } From 02d0787ebab9e4dd0ad295f1a31449c1796467d9 Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Fri, 26 Apr 2013 14:24:52 +0000 Subject: [PATCH 3/3] Fixed unit test --- test/Github/Tests/Api/OrganizationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index b1497c2f4c4..6017dcd3a13 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -46,7 +46,7 @@ public function shouldGetOrganizationRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/repos', array('type' => 'all')) + ->with('orgs/KnpLabs/repos', array('type' => 'all', 'per_page' => 30)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('KnpLabs'));