Skip to content

Commit d94da3d

Browse files
mikemilanoacrobat
authored andcommitted
Search topics implementation (#718)
* Added API support for searching by topic. * Added accept header for preview mode. * Fixed parameter definition style.
1 parent 8c1d51b commit d94da3d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/Github/Api/Search.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,21 @@ public function commits($q, $sort = null, $order = 'desc')
9595

9696
return $this->get('/search/commits', ['q' => $q, 'sort' => $sort, 'order' => $order]);
9797
}
98+
99+
/**
100+
* Search commits by filter (q).
101+
*
102+
* @link https://developer.github.com/v3/search/#search-topics
103+
*
104+
* @param string $q the filter
105+
*
106+
* @return array
107+
*/
108+
public function topics($q)
109+
{
110+
//This api is in preview mode, so set the correct accept-header
111+
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
112+
113+
return $this->get('/search/topics', ['q' => $q]);
114+
}
98115
}

test/Github/Tests/Api/SearchTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ public function shouldSearchCommitsRegardingSortAndOrder()
196196
);
197197
}
198198

199+
/**
200+
* @test
201+
*/
202+
public function shouldSearchTopics()
203+
{
204+
$expectedArray = ['total_count' => '0'];
205+
206+
$api = $this->getApiMock();
207+
208+
$api->expects($this->once())
209+
->method('get')
210+
->with('/search/topics', ['q' => 'query text'])
211+
->will($this->returnValue($expectedArray));
212+
213+
$this->assertEquals(
214+
$expectedArray,
215+
$api->topics('query text')
216+
);
217+
}
218+
199219
/**
200220
* @return string
201221
*/

0 commit comments

Comments
 (0)