Skip to content

Commit 25bdb5c

Browse files
committed
Added support for gist comments
1 parent 3e777b4 commit 25bdb5c

File tree

4 files changed

+166
-1
lines changed

4 files changed

+166
-1
lines changed

lib/Github/Api/Gist/Comments.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Github\Api\Gist;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
*
9+
* @link https://developer.github.com/v3/gists/comments/
10+
* @author Kayla Daniels <[email protected]>
11+
* @author Edoardo Rivello <edoardo.rivello at gmail dot com>
12+
*/
13+
class Comments extends AbstractApi
14+
{
15+
// GET /gists/:gist_id/comments
16+
public function all($gist)
17+
{
18+
return $this->get('gists/'.rawurlencode($gist)."/comments");
19+
}
20+
21+
//GET /gists/:gist_id/comments/:id
22+
public function show($gist, $comment)
23+
{
24+
return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment));
25+
}
26+
27+
//POST /gists/:gist_id/comments
28+
public function create($gist, $body)
29+
{
30+
return $this->post('gists/'.rawurlencode($gist)."/comments", array($body));
31+
}
32+
33+
//PATCH /gists/:gist_id/comments/:id
34+
public function update($gist, $comment_id, $body)
35+
{
36+
return $this->patch('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment_id), array($body));
37+
}
38+
39+
//DELETE /gists/:gist_id/comments/:id
40+
public function remove($gist, $comment)
41+
{
42+
return $this->delete('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment));
43+
}
44+
}

lib/Github/Api/Gists.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Github\Api;
44

5-
use Github\Api\AbstractApi;
65
use Github\Exception\MissingArgumentException;
6+
use Github\Api\Gist\Comments;
77

88
/**
99
* Creating, editing, deleting and listing gists.
@@ -73,4 +73,17 @@ public function unstar($id)
7373
{
7474
return $this->delete('gists/'.rawurlencode($id).'/star');
7575
}
76+
77+
/**
78+
* List an gists comments.
79+
*
80+
* @link http://developer.github.com/v3/gists/comments/
81+
*
82+
* @return Comments
83+
*/
84+
public function comments()
85+
{
86+
return new Comments($this->client);
87+
}
88+
7689
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Gist;
4+
5+
use Github\Tests\Api\TestCase;
6+
7+
class CommentsTest extends TestCase
8+
{
9+
/**
10+
* @test
11+
*/
12+
13+
// GET /gists/:gist_id/comments
14+
public function shouldGetAllGistComments()
15+
{
16+
$expectedValue = array(array('comment1data'), array('comment2data'));
17+
18+
$api = $this->getApiMock();
19+
$api->expects($this->once())
20+
->method('get')
21+
->with('gists/123/comments')
22+
->will($this->returnValue($expectedValue));
23+
24+
$this->assertEquals($expectedValue, $api->all('123'));
25+
}
26+
27+
/**
28+
* @test
29+
*/
30+
public function shouldShowGistComment()
31+
{
32+
$expectedValue = array('comment1');
33+
34+
$api = $this->getApiMock();
35+
$api->expects($this->once())
36+
->method('get')
37+
->with('gists/123/comments/123')
38+
->will($this->returnValue($expectedValue));
39+
40+
$this->assertEquals($expectedValue, $api->show(123, 123));
41+
}
42+
43+
44+
/**
45+
* @test
46+
*/
47+
public function shouldCreateGistComment()
48+
{
49+
$expectedValue = array('comment1data');
50+
51+
$api = $this->getApiMock();
52+
$api->expects($this->once())
53+
->method('post')
54+
->with('gists/123/comments', array("Test body"))
55+
->will($this->returnValue($expectedValue));
56+
57+
$this->assertEquals($expectedValue, $api->create('123', "Test body"));
58+
}
59+
60+
61+
/**
62+
* @test
63+
*/
64+
public function shouldUpdateGistComment()
65+
{
66+
$expectedValue = array('comment1data');
67+
$data = array('body test');
68+
69+
$api = $this->getApiMock();
70+
$api->expects($this->once())
71+
->method('patch')
72+
->with('gists/123/comments/233', $data)
73+
->will($this->returnValue($expectedValue));
74+
75+
$this->assertEquals($expectedValue, $api->update(123, 233, 'body test'));
76+
}
77+
78+
/**
79+
* @test
80+
*/
81+
public function shouldRemoveComment()
82+
{
83+
$expectedValue = array('someOutput');
84+
85+
$api = $this->getApiMock();
86+
$api->expects($this->once())
87+
->method('delete')
88+
->with('gists/123/comments/233')
89+
->will($this->returnValue($expectedValue));
90+
91+
$this->assertEquals($expectedValue, $api->remove(123, 233));
92+
}
93+
94+
protected function getApiClass()
95+
{
96+
return 'Github\Api\Gist\Comments';
97+
}
98+
}

test/Github/Tests/Api/GistsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public function shouldShowCommits()
6868
$this->assertEquals($expectedArray, $api->commits(123));
6969
}
7070

71+
/**
72+
* @test
73+
*/
74+
public function shouldGetCommentsApiObject()
75+
{
76+
$api = $this->getApiMock();
77+
78+
$this->assertInstanceOf('Github\Api\Gist\Comments', $api->comments());
79+
}
80+
7181
/**
7282
* @test
7383
*/

0 commit comments

Comments
 (0)