diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php new file mode 100644 index 00000000000..2d889650015 --- /dev/null +++ b/lib/Github/Api/Gist/Comments.php @@ -0,0 +1,37 @@ + + */ +class Comments extends AbstractApi +{ + public function all($gist) + { + return $this->get('gists/'.rawurlencode($gist).'/comments'); + } + + public function show($gist, $comment) + { + return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + } + + public function create($gist, $body) + { + return $this->post('gists/'.rawurlencode($gist).'/comments', array($body)); + } + + public function update($gist, $comment_id, $body) + { + return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array($body)); + } + + public function remove($gist, $comment) + { + return $this->delete('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + } +} \ No newline at end of file diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 12fe9ec5d00..eb24f0b3fdf 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -2,8 +2,8 @@ namespace Github\Api; -use Github\Api\AbstractApi; use Github\Exception\MissingArgumentException; +use Github\Api\Gist\Comments; /** * Creating, editing, deleting and listing gists. @@ -73,4 +73,16 @@ public function unstar($id) { return $this->delete('gists/'.rawurlencode($id).'/star'); } + + /** + * Get a gist's comments. + * + * @link http://developer.github.com/v3/gists/comments/ + * + * @return Comments + */ + public function comments() + { + return new Comments($this->client); + } } diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php new file mode 100644 index 00000000000..77f3ca50faa --- /dev/null +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -0,0 +1,94 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('gists/123/comments') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('123')); + } + + /** + * @test + */ + public function shouldShowGistComment() + { + $expectedValue = array('comment1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('gists/123/comments/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show(123, 123)); + } + + /** + * @test + */ + public function shouldCreateGistComment() + { + $expectedValue = array('comment1data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('gists/123/comments', array('Test body')) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('123', 'Test body')); + } + + /** + * @test + */ + public function shouldUpdateGistComment() + { + $expectedValue = array('comment1data'); + $data = array('body test'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('gists/123/comments/233', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update(123, 233, 'body test')); + } + + /** + * @test + */ + public function shouldRemoveComment() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('gists/123/comments/233') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove(123, 233)); + } + + protected function getApiClass() + { + return 'Github\Api\Gist\Comments'; + } +} \ No newline at end of file diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 8a01dca3ddd..4d2cdf7f346 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -68,6 +68,16 @@ public function shouldShowCommits() $this->assertEquals($expectedArray, $api->commits(123)); } + /** + * @test + */ + public function shouldGetCommentsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Gist\Comments', $api->comments()); + } + /** * @test */ @@ -216,4 +226,4 @@ protected function getApiClass() { return 'Github\Api\Gists'; } -} +} \ No newline at end of file