diff --git a/composer.json b/composer.json index 62e44e009cc..4034d11b824 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "knplabs/github-api", + "name": "m1guelpf/github-api", "type": "library", "description": "GitHub API v3 client", - "homepage": "https://github.com/KnpLabs/php-github-api", + "homepage": "https://github.com/m1guelpf/php-github-api", "keywords": ["github", "gh", "api", "gist"], "license": "MIT", "authors": [ @@ -14,6 +14,11 @@ "name": "Thibault Duplessis", "email": "thibault.duplessis@gmail.com", "homepage": "http://ornicar.github.com" + }, + { + "name": "Miguel Piedrafita", + "email": "soy@miguelpiedrafita.com", + "homepage": "https://miguelpiedrafita.com" } ], "require": { @@ -32,12 +37,10 @@ "guzzlehttp/psr7": "^1.2", "sllh/php-cs-fixer-styleci-bridge": "^1.3" }, + "replace": { + "knplabs/github-api": "dev-master" + }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } - }, - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } } } diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php new file mode 100644 index 00000000000..a17d43cacb0 --- /dev/null +++ b/lib/Github/Api/GraphQL.php @@ -0,0 +1,26 @@ + + */ +class GraphQL extends AbstractApi +{ + /** + * @param string $query + * + * @return array + */ + public function graphql($query) + { + $params = array( + 'query' => $query + ); + + return $this->post('/graphql', $params); + } +} diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 0285f44886a..64a7f68efbe 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -15,6 +15,7 @@ use Github\Api\Repository\Labels; use Github\Api\Repository\Stargazers; use Github\Api\Repository\Statuses; +use Github\Api\Repository\Traffic; /** * Searching repositories, getting repository information @@ -59,6 +60,25 @@ public function all($id = null) return $this->get('/repositories?since=' . rawurldecode($id)); } + /** + * List all repositories owned by the user. + * + * @link https://developer.github.com/v3/repos/#list-your-repositories + * + * @param int|null $id The integer ID of the last Repository that you’ve seen. + * @param string|all $visibility The repo visibility + * @param string|full_name $sort How to sort the data. + * + * @return array list of users found + */ + public function owned($visibility = 'all', $sort = 'full_name', $id = null) + { + if (!is_int($id)) { + return $this->get('/user/repos?affiliation=owner'); + } + + return $this->get('/user/repos?affiliation=owner&since=' . rawurldecode($id)); + } /** * Get the last year of commit activity for a repository grouped by week. * @@ -549,4 +569,9 @@ public function projects() { return new Projects($this->client); } + + public function traffic() + { + return new Traffic($this->client); + } } diff --git a/lib/Github/Api/Repository/Traffic.php b/lib/Github/Api/Repository/Traffic.php new file mode 100644 index 00000000000..76c89da2a66 --- /dev/null +++ b/lib/Github/Api/Repository/Traffic.php @@ -0,0 +1,61 @@ + + */ +class Traffic extends AbstractApi +{ + /** + * @link https://developer.github.com/v3/repos/traffic/#list-referrers + * + * @param string $owner + * @param string $repository + * + * @return array + */ + public function referers($owner, $repository) + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/referrers'); + } + /** + * @link https://developer.github.com/v3/repos/traffic/#list-paths + * + * @param string $owner + * @param string $repository + * + * @return array + */ + public function paths($owner, $repository) + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/paths'); + } + /** + * @link https://developer.github.com/v3/repos/traffic/#views + * + * @param string $owner + * @param string $repository + * + * @return array + */ + public function views($owner, $repository) + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/views'); + } + /** + * @link https://developer.github.com/v3/repos/traffic/#clones + * + * @param string $owner + * @param string $repository + * + * @return array + */ + public function clones($owner, $repository) + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/clones'); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index eb7f3e727dd..a1b3857cf6c 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -54,6 +54,7 @@ * @method Api\Authorizations authorization() * @method Api\Authorizations authorizations() * @method Api\Meta meta() + * @method Api\GraphQL graphql() * * @author Joseph Bielawski * @@ -267,7 +268,9 @@ public function api($name) case 'meta': $api = new Api\Meta($this); break; - + case 'graphql': + $api = new Api\GraphQL($this); + break; default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index cc2e9c8e52c..2d1d9f9b34d 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -78,7 +78,27 @@ public function shouldGetAllRepositories() $this->assertEquals($expectedArray, $api->all()); } + +/** + * @test + */ + public function shouldGetOwnedRepositories() + { + $expectedArray = array( + array('id' => 1, 'name' => 'dummy project'), + array('id' => 2, 'name' => 'awesome another project'), + array('id' => 3, 'name' => 'fork of php'), + array('id' => 4, 'name' => 'fork of php-cs'), + ); + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/user/repos?affiliation=owner') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->owned()); + } /** * @test */ diff --git a/test/Github/Tests/Api/Repository/TrafficTest.php b/test/Github/Tests/Api/Repository/TrafficTest.php new file mode 100644 index 00000000000..e3ad192dc14 --- /dev/null +++ b/test/Github/Tests/Api/Repository/TrafficTest.php @@ -0,0 +1,37 @@ +getApiMock(); + + $api->expects($this->once()) // Expect one call + ->method('get') // A GET request + ->with('/gists/123/comments/456') // URI should be "/gists/123/comments/456" + ->will($this->returnValue($expectedValue)); // Should return the "Server response" + + // Call Comments::show + $result = $api->show(123, 456); + + // Verify that the result is the "Server response" as we expect. + $this->assertEquals($expectedValue, $result); + } + + protected function getApiClass() + { + // Tell the "getAPIMock" what class to mock. + return \Github\Api\Gist\Comments::class; + } +}