-
-
Notifications
You must be signed in to change notification settings - Fork 598
Add basic search api implementation. #186
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e929f3
KnpLabs/php-github-api#178 - adds a basic search api implementation.
stackpr 3dd65b7
Split find into 4 methods.
stackpr 32ae587
Added method phpdoc.
stackpr bb2b30e
Changed to single quotes.
stackpr 5c1f9fc
KnpLabs/php-github-api#178: Added "Search" check to Github\ClientTest
164c142
KnpLabs/php-github-api#178: Added tests for Github\Api\Search
a7e3946
KnpLabs/php-github-api#178: Documentation added for Github\Client\Search
92633d1
Merge pull request #1 from YevKov/master
stackpr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Search API | ||
[Back to the navigation](index.md) | ||
|
||
Searching repositories, code, issues and users. | ||
Wrap [GitHub Search API](http://developer.github.com/v3/search/). All methods are described on that page. | ||
|
||
### Search repositories | ||
|
||
```php | ||
$repos = $client->api('search')->repositories('github language:php'); | ||
``` | ||
|
||
Returns a list of repositories found by such criteria. | ||
|
||
### Search code | ||
|
||
```php | ||
$repos = $client->api('search')->code('@todo language:php'); | ||
``` | ||
|
||
Returns a list of files found by such criteria (containing "@todo" and language==php). | ||
|
||
### Search issues | ||
|
||
```php | ||
$repos = $client->api('search')->issues('bug language:php'); | ||
``` | ||
|
||
Returns a list of issues found by such criteria. | ||
|
||
### Search users | ||
|
||
```php | ||
$repos = $client->api('search')->users('location:Amsterdam language:php'); | ||
``` | ||
|
||
Returns a list of users found by such criteria. | ||
|
||
### Sorting results | ||
|
||
You can sort results using 2-3 arguments. | ||
|
||
```php | ||
$repos = $client->api('repo')->repositories('...', 'created', 'asc'); | ||
$repos = $client->api('repo')->code('...........', 'indexed', 'desc'); | ||
$repos = $client->api('repo')->issues('.........', 'comments', 'asc'); | ||
$repos = $client->api('repo')->users('..........', 'followers', 'asc'); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Github\Api; | ||
|
||
use Github\Api\Issue\Comments; | ||
use Github\Api\Issue\Events; | ||
use Github\Api\Issue\Labels; | ||
use Github\Api\Issue\Milestones; | ||
use Github\Exception\MissingArgumentException; | ||
|
||
/** | ||
* Implement the Search API. | ||
* | ||
* @link https://developer.github.com/v3/search/ | ||
* @author Greg Payne <greg.payne@gmail.com> | ||
*/ | ||
class Search extends AbstractApi | ||
{ | ||
|
||
/** | ||
* Search repositories by filter (q) | ||
* @link https://developer.github.com/v3/search/#search-repositories | ||
* | ||
* @param string $q the filter | ||
* @param string $sort the sort field | ||
* @param string $order asc/desc | ||
* | ||
* @return array list of repositories found | ||
*/ | ||
public function repositories($q, $sort = 'updated', $order = 'desc') | ||
{ | ||
return $this->get('/search/repositories', array('q' => $q, 'sort' => $sort, 'order' => $order)); | ||
} | ||
|
||
/** | ||
* Search issues by filter (q) | ||
* @link https://developer.github.com/v3/search/#search-issues | ||
* | ||
* @param string $q the filter | ||
* @param string $sort the sort field | ||
* @param string $order asc/desc | ||
* | ||
* @return array list of issues found | ||
*/ | ||
public function issues($q, $sort = 'updated', $order = 'desc') | ||
{ | ||
return $this->get('/search/issues', array('q' => $q, 'sort' => $sort, 'order' => $order)); | ||
} | ||
|
||
/** | ||
* Search code by filter (q) | ||
* @link https://developer.github.com/v3/search/#search-code | ||
* | ||
* @param string $q the filter | ||
* @param string $sort the sort field | ||
* @param string $order asc/desc | ||
* | ||
* @return array list of code found | ||
*/ | ||
public function code($q, $sort = 'updated', $order = 'desc') | ||
{ | ||
return $this->get('/search/code', array('q' => $q, 'sort' => $sort, 'order' => $order)); | ||
} | ||
|
||
/** | ||
* Search users by filter (q) | ||
* @link https://developer.github.com/v3/search/#search-users | ||
* | ||
* @param string $q the filter | ||
* @param string $sort the sort field | ||
* @param string $order asc/desc | ||
* | ||
* @return array list of users found | ||
*/ | ||
public function users($q, $sort = 'updated', $order = 'desc') | ||
{ | ||
return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api; | ||
|
||
class SearchTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchRepositoriesByQuery() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/repositories', | ||
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->repositories('query text')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchRepositoriesRegardingSortAndOrder() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/repositories', | ||
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals( | ||
$expectedArray, | ||
$api->repositories('query text', 'created', 'asc') | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchIssuesByQuery() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/issues', | ||
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->issues('query text')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchIssuesRegardingSortAndOrder() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/issues', | ||
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals( | ||
$expectedArray, | ||
$api->issues('query text', 'created', 'asc') | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchCodeByQuery() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/code', | ||
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->code('query text')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchCodeRegardingSortAndOrder() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/code', | ||
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals( | ||
$expectedArray, | ||
$api->code('query text', 'created', 'asc') | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchUsersByQuery() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/users', | ||
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->users('query text')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSearchUsersRegardingSortAndOrder() | ||
{ | ||
$expectedArray = array(array('total_count' => '0')); | ||
|
||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with( | ||
'/search/users', | ||
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') | ||
) | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals( | ||
$expectedArray, | ||
$api->users('query text', 'created', 'asc') | ||
); | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Github\Api\Search'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to add the
@method
annotation on the class too