Skip to content

Add Traffic #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -549,4 +550,9 @@ public function projects()
{
return new Projects($this->client);
}

public function traffic()
{
return new Traffic($this->client);
}
}
61 changes: 61 additions & 0 deletions lib/Github/Api/Repository/Traffic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;

/**
* @link https://developer.github.com/v3/repos/traffic/
* @author Miguel Piedrafita <[email protected]>
*/
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not added.

{
return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/clones');
}
}
37 changes: 37 additions & 0 deletions test/Github/Tests/Api/Repository/TrafficTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Github\Tests\Api\TestCase;

class TrafficTest extends TestCase
{
// ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed


/**
* @test
*/
public function shoulddoSomething()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the name of this function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also update the test content

{
// Create a variable with the "Server response".
$expectedValue = array('comment1');

// Get the API mock (see "getApiClass" below).
$api = $this->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;
}
}