Skip to content

GraphQL API #509

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 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aad9546
Create Traffic.php
m1guelpf Jan 10, 2017
f05e626
Add Clones
m1guelpf Jan 10, 2017
a229d8a
Apply fixes from StyleCI
m1guelpf Jan 10, 2017
350b828
Add Traffic to Repo
m1guelpf Jan 11, 2017
d6767ea
Add Traffic
m1guelpf Jan 11, 2017
ded9d04
Apply fixes from StyleCI
m1guelpf Jan 11, 2017
f4cfcb4
Add owned()
m1guelpf Jan 11, 2017
adcd5a8
Apply fixes from StyleCI
m1guelpf Jan 11, 2017
8264b32
list() -> referers()
m1guelpf Jan 11, 2017
ec15450
Add params
m1guelpf Jan 12, 2017
60ac5de
Finish adding params
m1guelpf Jan 12, 2017
f0efa76
Add tests for repos-owned
m1guelpf Jan 12, 2017
b06d0ba
Fix tests
m1guelpf Jan 12, 2017
8027309
Syntax
m1guelpf Jan 12, 2017
bf17eab
Test skeleton
m1guelpf Jan 12, 2017
73f9828
Apply fixes from StyleCI
m1guelpf Jan 12, 2017
fe3ef14
Merge pull request #4 from m1guelpf/add-traffic
m1guelpf Jan 14, 2017
beb5984
Merge pull request #5 from m1guelpf/patch-1
m1guelpf Jan 14, 2017
f413e41
Merge pull request #6 from m1guelpf/repos-owned
m1guelpf Jan 14, 2017
678b830
Update composer.json
m1guelpf Jan 14, 2017
2842b78
Add replace
m1guelpf Jan 14, 2017
a7c3573
Syntax
m1guelpf Jan 14, 2017
2cb67e7
Add GraphQL API
m1guelpf Jan 23, 2017
89d3f3e
Apply fixes from StyleCI
m1guelpf Jan 23, 2017
623b3e6
Merge pull request #8 from KnpLabs/master
m1guelpf Jan 23, 2017
20c1c09
Merge pull request #7 from m1guelpf/graphql
m1guelpf Jan 23, 2017
44ec311
Create GraphQL.php
m1guelpf Jan 23, 2017
f0279c9
Update composer.json
m1guelpf Jan 23, 2017
f8f0e49
Update composer.json
m1guelpf Jan 23, 2017
e2bf2a1
Add GraphQL API
m1guelpf Jan 23, 2017
35a0d47
Fix return
m1guelpf Jan 23, 2017
722c5af
Merge branch 'packagist' into graphql
m1guelpf Jan 23, 2017
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
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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": {
Expand All @@ -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"
}
}
}
26 changes: 26 additions & 0 deletions lib/Github/Api/GraphQL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Github\Api;

/**
* GraphQL API.
*
* @link http://developer.github.com/v3/markdown/
* @author Miguel Piedrafita <soy@miguelpiedrafita.com>
*/
class GraphQL extends AbstractApi
{
/**
* @param string $query
*
* @return array
*/
public function graphql($query)
{
$params = array(
'query' => $query
);

return $this->post('/graphql', $params);
}
}
25 changes: 25 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 @@ -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.
*
Expand Down Expand Up @@ -549,4 +569,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 <soy@miguelpiedrafita.com>
*/
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');
}
}
5 changes: 4 additions & 1 deletion lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* @method Api\Authorizations authorization()
* @method Api\Authorizations authorizations()
* @method Api\Meta meta()
* @method Api\GraphQL graphql()
*
* @author Joseph Bielawski <stloyd@gmail.com>
*
Expand Down Expand Up @@ -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));
}
Expand Down
20 changes: 20 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
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
{
// ...

/**
* @test
*/
public function shoulddoSomething()
{
// 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;
}
}