1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Github Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Github\Package\Gists; |
10
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* GitHub API Gists Comments class for the Joomla Framework. |
15
|
|
|
* |
16
|
|
|
* @documentation http://developer.github.com/v3/gists/comments/ |
17
|
|
|
* |
18
|
|
|
* @since 1.0 |
19
|
|
|
*/ |
20
|
|
|
class Comments extends AbstractPackage |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Create a comment. |
24
|
|
|
* |
25
|
|
|
* @param integer $gistId The gist number. |
26
|
|
|
* @param string $body The comment body text. |
27
|
|
|
* |
28
|
|
|
* @return object |
29
|
|
|
* |
30
|
|
|
* @since 1.0 |
31
|
|
|
* @throws \DomainException |
32
|
|
|
*/ |
33
|
|
|
public function create($gistId, $body) |
34
|
|
|
{ |
35
|
|
|
// Build the request path. |
36
|
|
|
$path = '/gists/' . (int) $gistId . '/comments'; |
37
|
|
|
|
38
|
|
|
// Build the request data. |
39
|
|
|
$data = json_encode( |
40
|
|
|
array( |
41
|
|
|
'body' => $body, |
42
|
|
|
) |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
// Send the request. |
46
|
|
|
return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Delete a comment. |
51
|
|
|
* |
52
|
|
|
* @param integer $commentId The id of the comment to delete. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
* |
56
|
|
|
* @since 1.0 |
57
|
|
|
* @throws \DomainException |
58
|
|
|
*/ |
59
|
|
|
public function delete($commentId) |
60
|
|
|
{ |
61
|
|
|
// Build the request path. |
62
|
|
|
$path = '/gists/comments/' . (int) $commentId; |
63
|
|
|
|
64
|
|
|
// Send the request. |
65
|
|
|
$this->processResponse($this->client->delete($this->fetchUrl($path)), 204); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Edit a comment. |
70
|
|
|
* |
71
|
|
|
* @param integer $commentId The id of the comment to update. |
72
|
|
|
* @param string $body The new body text for the comment. |
73
|
|
|
* |
74
|
|
|
* @return object |
75
|
|
|
* |
76
|
|
|
* @since 1.0 |
77
|
|
|
* @throws \DomainException |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function edit($commentId, $body) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
// Build the request path. |
82
|
|
|
$path = '/gists/comments/' . (int) $commentId; |
83
|
|
|
|
84
|
|
|
// Build the request data. |
85
|
|
|
$data = json_encode( |
86
|
|
|
array( |
87
|
|
|
'body' => $body |
88
|
|
|
) |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
// Send the request. |
92
|
|
|
return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get a single comment. |
97
|
|
|
* |
98
|
|
|
* @param integer $commentId The comment id to get. |
99
|
|
|
* |
100
|
|
|
* @return object |
101
|
|
|
* |
102
|
|
|
* @since 1.0 |
103
|
|
|
* @throws \DomainException |
104
|
|
|
*/ |
105
|
|
|
public function get($commentId) |
106
|
|
|
{ |
107
|
|
|
// Build the request path. |
108
|
|
|
$path = '/gists/comments/' . (int) $commentId; |
109
|
|
|
|
110
|
|
|
// Send the request. |
111
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* List comments on a gist. |
116
|
|
|
* |
117
|
|
|
* @param integer $gistId The gist number. |
118
|
|
|
* @param integer $page The page number from which to get items. |
119
|
|
|
* @param integer $limit The number of items on a page. |
120
|
|
|
* |
121
|
|
|
* @return object |
122
|
|
|
* |
123
|
|
|
* @since 1.0 |
124
|
|
|
* @throws \DomainException |
125
|
|
|
*/ |
126
|
|
|
public function getList($gistId, $page = 0, $limit = 0) |
127
|
|
|
{ |
128
|
|
|
// Build the request path. |
129
|
|
|
$path = '/gists/' . (int) $gistId . '/comments'; |
130
|
|
|
|
131
|
|
|
// Send the request. |
132
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.