Skip to content

Commit 1e929f3

Browse files
committed
#178 - adds a basic search api implementation.
1 parent 7574e92 commit 1e929f3

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/Github/Api/Search.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Github\Api;
4+
5+
use Github\Api\Issue\Comments;
6+
use Github\Api\Issue\Events;
7+
use Github\Api\Issue\Labels;
8+
use Github\Api\Issue\Milestones;
9+
use Github\Exception\MissingArgumentException;
10+
11+
/**
12+
* Implement the Search API.
13+
*
14+
* @link https://developer.github.com/v3/search/
15+
* @author Greg Payne <[email protected]>
16+
*/
17+
class Search extends AbstractApi
18+
{
19+
/**
20+
* Search by filter (q)
21+
* @link http://developer.github.com/v3/search/
22+
*
23+
* @param string $type the search type
24+
* @param string $q the filter
25+
* @param string $sort the sort field
26+
* @param string $order asc/desc
27+
*
28+
* @return array list of issues found
29+
*/
30+
public function find($type = 'issues', $q = '', $sort = 'updated', $order = 'desc')
31+
{
32+
if (!in_array($type, array('issues', 'repositories', 'code', 'users'))) {
33+
$type = 'issues';
34+
}
35+
return $this->get("/search/$type", array('q' => $q, 'sort' => $sort, 'order' => $order));
36+
}
37+
38+
}

lib/Github/Client.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public function api($name)
162162
$api = new Api\Repo($this);
163163
break;
164164

165+
case 'search':
166+
$api = new Api\Search($this);
167+
break;
168+
165169
case 'team':
166170
case 'teams':
167171
$api = new Api\Organization\Teams($this);
@@ -310,7 +314,7 @@ public function getSupportedApiVersions()
310314

311315
/**
312316
* @param string $name
313-
*
317+
*
314318
* @return ApiInterface
315319
*
316320
* @throws InvalidArgumentException

0 commit comments

Comments
 (0)