diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 0285f44886a..2279340535c 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 @@ -549,4 +550,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..e27ec33a809 --- /dev/null +++ b/lib/Github/Api/Repository/Traffic.php @@ -0,0 +1,62 @@ + + */ +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 + * @param string|day $per + * + * @return array + */ + public function views($owner, $repository, $per = 'day') + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/views?per='.rawurlencode($per)); + } + /** + * @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/test/Github/Tests/Api/Repository/TrafficTest.php b/test/Github/Tests/Api/Repository/TrafficTest.php new file mode 100644 index 00000000000..3a181ca286b --- /dev/null +++ b/test/Github/Tests/Api/Repository/TrafficTest.php @@ -0,0 +1,36 @@ +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; + } +}