1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage GitHub
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * GitHub API Gists Comments class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/gists/comments/
16 *
17 * @since 3.3 (CMS)
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageGistsComments extends JGithubPackage
21 {
22 /**
23 * Method to create a comment on a gist.
24 *
25 * @param integer $gistId The gist number.
26 * @param string $body The comment body text.
27 *
28 * @throws DomainException
29 * @since 11.3
30 *
31 * @return object
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 $response = $this->client->post($this->fetchUrl($path), $data);
47
48 // Validate the response code.
49 if ($response->code != 201)
50 {
51 // Decode the error response and throw an exception.
52 $error = json_decode($response->body);
53 throw new DomainException($error->message, $response->code);
54 }
55
56 return json_decode($response->body);
57 }
58
59 /**
60 * Method to delete a comment on a gist.
61 *
62 * @param integer $commentId The id of the comment to delete.
63 *
64 * @throws DomainException
65 * @since 11.3
66 *
67 * @return void
68 */
69 public function delete($commentId)
70 {
71 // Build the request path.
72 $path = '/gists/comments/' . (int) $commentId;
73
74 // Send the request.
75 $response = $this->client->delete($this->fetchUrl($path));
76
77 // Validate the response code.
78 if ($response->code != 204)
79 {
80 // Decode the error response and throw an exception.
81 $error = json_decode($response->body);
82 throw new DomainException($error->message, $response->code);
83 }
84 }
85
86 /**
87 * Method to update a comment on a gist.
88 *
89 * @param integer $commentId The id of the comment to update.
90 * @param string $body The new body text for the comment.
91 *
92 * @throws DomainException
93 * @since 11.3
94 *
95 * @return object
96 */
97 public function edit($commentId, $body)
98 {
99 // Build the request path.
100 $path = '/gists/comments/' . (int) $commentId;
101
102 // Build the request data.
103 $data = json_encode(
104 array(
105 'body' => $body,
106 )
107 );
108
109 // Send the request.
110 $response = $this->client->patch($this->fetchUrl($path), $data);
111
112 // Validate the response code.
113 if ($response->code != 200)
114 {
115 // Decode the error response and throw an exception.
116 $error = json_decode($response->body);
117 throw new DomainException($error->message, $response->code);
118 }
119
120 return json_decode($response->body);
121 }
122
123 /**
124 * Method to get a specific comment on a gist.
125 *
126 * @param integer $commentId The comment id to get.
127 *
128 * @throws DomainException
129 * @since 11.3
130 *
131 * @return object
132 */
133 public function get($commentId)
134 {
135 // Build the request path.
136 $path = '/gists/comments/' . (int) $commentId;
137
138 // Send the request.
139 $response = $this->client->get($this->fetchUrl($path));
140
141 // Validate the response code.
142 if ($response->code != 200)
143 {
144 // Decode the error response and throw an exception.
145 $error = json_decode($response->body);
146 throw new DomainException($error->message, $response->code);
147 }
148
149 return json_decode($response->body);
150 }
151
152 /**
153 * Method to get the list of comments on a gist.
154 *
155 * @param integer $gistId The gist number.
156 * @param integer $page The page number from which to get items.
157 * @param integer $limit The number of items on a page.
158 *
159 * @throws DomainException
160 * @since 11.3
161 *
162 * @return array
163 */
164 public function getList($gistId, $page = 0, $limit = 0)
165 {
166 // Build the request path.
167 $path = '/gists/' . (int) $gistId . '/comments';
168
169 // Send the request.
170 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
171
172 // Validate the response code.
173 if ($response->code != 200)
174 {
175 // Decode the error response and throw an exception.
176 $error = json_decode($response->body);
177 throw new DomainException($error->message, $response->code);
178 }
179
180 return json_decode($response->body);
181 }
182 }
183