Skip to content

Commit ed39b47

Browse files
committed
Merge pull request #258 from kayladnls/gistComments
Gist comments
2 parents b7b6f29 + 6bbe4d8 commit ed39b47

File tree

4 files changed

+155
-2
lines changed

4 files changed

+155
-2
lines changed

lib/Github/Api/Gist/Comments.php

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

lib/Github/Api/Gists.php

+13-1
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,16 @@ public function unstar($id)
7373
{
7474
return $this->delete('gists/'.rawurlencode($id).'/star');
7575
}
76+
77+
/**
78+
* Get a gist's 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+
}
7688
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
public function shouldGetAllGistComments()
13+
{
14+
$expectedValue = array(array('comment1data'), array('comment2data'));
15+
16+
$api = $this->getApiMock();
17+
$api->expects($this->once())
18+
->method('get')
19+
->with('gists/123/comments')
20+
->will($this->returnValue($expectedValue));
21+
22+
$this->assertEquals($expectedValue, $api->all('123'));
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function shouldShowGistComment()
29+
{
30+
$expectedValue = array('comment1');
31+
32+
$api = $this->getApiMock();
33+
$api->expects($this->once())
34+
->method('get')
35+
->with('gists/123/comments/123')
36+
->will($this->returnValue($expectedValue));
37+
38+
$this->assertEquals($expectedValue, $api->show(123, 123));
39+
}
40+
41+
/**
42+
* @test
43+
*/
44+
public function shouldCreateGistComment()
45+
{
46+
$expectedValue = array('comment1data');
47+
48+
$api = $this->getApiMock();
49+
$api->expects($this->once())
50+
->method('post')
51+
->with('gists/123/comments', array('Test body'))
52+
->will($this->returnValue($expectedValue));
53+
54+
$this->assertEquals($expectedValue, $api->create('123', 'Test body'));
55+
}
56+
57+
/**
58+
* @test
59+
*/
60+
public function shouldUpdateGistComment()
61+
{
62+
$expectedValue = array('comment1data');
63+
$data = array('body test');
64+
65+
$api = $this->getApiMock();
66+
$api->expects($this->once())
67+
->method('patch')
68+
->with('gists/123/comments/233', $data)
69+
->will($this->returnValue($expectedValue));
70+
71+
$this->assertEquals($expectedValue, $api->update(123, 233, 'body test'));
72+
}
73+
74+
/**
75+
* @test
76+
*/
77+
public function shouldRemoveComment()
78+
{
79+
$expectedValue = array('someOutput');
80+
81+
$api = $this->getApiMock();
82+
$api->expects($this->once())
83+
->method('delete')
84+
->with('gists/123/comments/233')
85+
->will($this->returnValue($expectedValue));
86+
87+
$this->assertEquals($expectedValue, $api->remove(123, 233));
88+
}
89+
90+
protected function getApiClass()
91+
{
92+
return 'Github\Api\Gist\Comments';
93+
}
94+
}

test/Github/Tests/Api/GistsTest.php

+11-1
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
*/
@@ -216,4 +226,4 @@ protected function getApiClass()
216226
{
217227
return 'Github\Api\Gists';
218228
}
219-
}
229+
}

0 commit comments

Comments
 (0)