@@ 125-135 (lines=11) @@ | ||
122 | * |
|
123 | * @return Answer |
|
124 | */ |
|
125 | public function accept($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
126 | { |
|
127 | if (!$this->authentication instanceof Authentication) { |
|
128 | throw new \Exception('Authentication is required'); |
|
129 | } |
|
130 | $response = HttpClient::instance()->put( |
|
131 | self::URL . $id . '/accept', array_merge($params, $this->authentication->toArray()) |
|
132 | ); |
|
133 | ||
134 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
135 | } |
|
136 | ||
137 | /** |
|
138 | * Undoes an accept vote on the given answer. |
|
@@ 150-160 (lines=11) @@ | ||
147 | * |
|
148 | * @return Answer |
|
149 | */ |
|
150 | public function undoAccept($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
151 | { |
|
152 | if (!$this->authentication instanceof Authentication) { |
|
153 | throw new \Exception('Authentication is required'); |
|
154 | } |
|
155 | $response = HttpClient::instance()->put( |
|
156 | self::URL . $id . '/accept/undo', array_merge($params, $this->authentication->toArray()) |
|
157 | ); |
|
158 | ||
159 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
160 | } |
|
161 | ||
162 | /** |
|
163 | * Deletes an answer. |
|
@@ 175-185 (lines=11) @@ | ||
172 | * |
|
173 | * @return Answer |
|
174 | */ |
|
175 | public function delete($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
176 | { |
|
177 | if (!$this->authentication instanceof Authentication) { |
|
178 | throw new \Exception('Authentication is required'); |
|
179 | } |
|
180 | $response = HttpClient::instance()->delete( |
|
181 | self::URL . $id . '/delete', array_merge($params, $this->authentication->toArray()) |
|
182 | ); |
|
183 | ||
184 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
185 | } |
|
186 | ||
187 | /** |
|
188 | * Downvotes an answer. |
|
@@ 200-210 (lines=11) @@ | ||
197 | * |
|
198 | * @return Answer |
|
199 | */ |
|
200 | public function downvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
201 | { |
|
202 | if (!$this->authentication instanceof Authentication) { |
|
203 | throw new \Exception('Authentication is required'); |
|
204 | } |
|
205 | $response = HttpClient::instance()->put( |
|
206 | self::URL . $id . '/downvote', array_merge($params, $this->authentication->toArray()) |
|
207 | ); |
|
208 | ||
209 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
210 | } |
|
211 | ||
212 | /** |
|
213 | * Undoes an downvote on an answer. |
|
@@ 225-235 (lines=11) @@ | ||
222 | * |
|
223 | * @return Answer |
|
224 | */ |
|
225 | public function undoDownvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
226 | { |
|
227 | if (!$this->authentication instanceof Authentication) { |
|
228 | throw new \Exception('Authentication is required'); |
|
229 | } |
|
230 | $response = HttpClient::instance()->put( |
|
231 | self::URL . $id . '/downvote/undo', array_merge($params, $this->authentication->toArray()) |
|
232 | ); |
|
233 | ||
234 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
235 | } |
|
236 | ||
237 | /** |
|
238 | * Edit an existing answer. |
|
@@ 251-261 (lines=11) @@ | ||
248 | * |
|
249 | * @return Answer |
|
250 | */ |
|
251 | public function update($id, $body, array $params = self::QUERY_PARAMS, $serialize = true) |
|
252 | { |
|
253 | if (!$this->authentication instanceof Authentication) { |
|
254 | throw new \Exception('Authentication is required'); |
|
255 | } |
|
256 | $response = HttpClient::instance()->put( |
|
257 | self::URL . $id . '/edit', array_merge(['body' => $body], $params, $this->authentication->toArray()) |
|
258 | ); |
|
259 | ||
260 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
261 | } |
|
262 | ||
263 | /** |
|
264 | * Upvotes an answer. |
|
@@ 276-286 (lines=11) @@ | ||
273 | * |
|
274 | * @return Answer |
|
275 | */ |
|
276 | public function upvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
277 | { |
|
278 | if (!$this->authentication instanceof Authentication) { |
|
279 | throw new \Exception('Authentication is required'); |
|
280 | } |
|
281 | $response = HttpClient::instance()->put( |
|
282 | self::URL . $id . '/upvote', array_merge($params, $this->authentication->toArray()) |
|
283 | ); |
|
284 | ||
285 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
286 | } |
|
287 | ||
288 | /** |
|
289 | * Undoes an upvote on an answer. |
|
@@ 301-311 (lines=11) @@ | ||
298 | * |
|
299 | * @return Answer |
|
300 | */ |
|
301 | public function undoUpvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
302 | { |
|
303 | if (!$this->authentication instanceof Authentication) { |
|
304 | throw new \Exception('Authentication is required'); |
|
305 | } |
|
306 | $response = HttpClient::instance()->put( |
|
307 | self::URL . $id . '/upvote/undo', array_merge($params, $this->authentication->toArray()) |
|
308 | ); |
|
309 | ||
310 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
311 | } |
|
312 | ||
313 | /** |
|
314 | * Casts a flag against the answer identified by id. |
|
@@ 326-336 (lines=11) @@ | ||
323 | * |
|
324 | * @return Answer |
|
325 | */ |
|
326 | public function addFlag($id, array $params = self::QUERY_PARAMS, $serialize = true) |
|
327 | { |
|
328 | if (!$this->authentication instanceof Authentication) { |
|
329 | throw new \Exception('Authentication is required'); |
|
330 | } |
|
331 | $response = HttpClient::instance()->put( |
|
332 | self::URL . $id . '/flags/add', array_merge($params, $this->authentication->toArray()) |
|
333 | ); |
|
334 | ||
335 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
336 | } |
|
337 | ||
338 | /** |
|
339 | * Gets the answers to a set of questions identified in id. |
|
@@ 378-390 (lines=13) @@ | ||
375 | * |
|
376 | * @return Answer |
|
377 | */ |
|
378 | public function addOfQuestionId($id, $body, array $params = self::QUERY_PARAMS, $serialize = true) |
|
379 | { |
|
380 | if (!$this->authentication instanceof Authentication) { |
|
381 | throw new \Exception('Authentication is required'); |
|
382 | } |
|
383 | $response = HttpClient::instance()->post( |
|
384 | 'questions/' . $id . '/' . self::URL . 'add', array_merge( |
|
385 | ['body' => $body], $params, $this->authentication->toArray() |
|
386 | ) |
|
387 | ); |
|
388 | ||
389 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
390 | } |
|
391 | ||
392 | /** |
|
393 | * Render an answer given it's body and the question it's on. |
|
@@ 461-471 (lines=11) @@ | ||
458 | * |
|
459 | * @return array|Answer |
|
460 | */ |
|
461 | public function myAnswers(array $params = self::QUERY_PARAMS, $serialize = true) |
|
462 | { |
|
463 | if (!$this->authentication instanceof Authentication) { |
|
464 | throw new \Exception('Authentication is required'); |
|
465 | } |
|
466 | $response = HttpClient::instance()->get( |
|
467 | 'me/' . self::URL, array_merge($params, $this->authentication->toArray()) |
|
468 | ); |
|
469 | ||
470 | return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
471 | } |
|
472 | ||
473 | /** |
|
474 | * Returns the top 30 answers a user has posted in response to questions with the given tags. |