|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Api; |
| 4 | + |
| 5 | +use Github\Exception\MissingArgumentException; |
| 6 | + |
| 7 | +abstract class AbstractReactionsApi extends AbstractApi |
| 8 | +{ |
| 9 | + /** |
| 10 | + * List reactions for a resource. |
| 11 | + * |
| 12 | + * @param string $username |
| 13 | + * @param string $repository |
| 14 | + * @param string $id |
| 15 | + * @param array $params |
| 16 | + * |
| 17 | + * @return array |
| 18 | + */ |
| 19 | + public function all($username, $repository, $id, array $params = []) |
| 20 | + { |
| 21 | + return $this->get($this->getReactionsPath($username, $repository, $id), $params); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Create a reaction for a resource. |
| 26 | + * |
| 27 | + * @param string $username |
| 28 | + * @param string $repository |
| 29 | + * @param string $id |
| 30 | + * @param array $params |
| 31 | + * |
| 32 | + * @throws MissingArgumentException |
| 33 | + * |
| 34 | + * @return array |
| 35 | + */ |
| 36 | + public function create($username, $repository, $id, array $params) |
| 37 | + { |
| 38 | + if (!isset($params['content'])) { |
| 39 | + throw new MissingArgumentException('content'); |
| 40 | + } |
| 41 | + |
| 42 | + return $this->post($this->getReactionsPath($username, $repository, $id), $params); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Delete a reaction from a resource. |
| 47 | + * |
| 48 | + * @param string $username |
| 49 | + * @param string $repository |
| 50 | + * @param string $id |
| 51 | + * @param string $reaction |
| 52 | + * |
| 53 | + * @return array|string |
| 54 | + */ |
| 55 | + public function remove($username, $repository, $id, $reaction) |
| 56 | + { |
| 57 | + return $this->delete($this->getReactionsPath($username, $repository, $id).'/'.rawurlencode($reaction)); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @param string $username |
| 62 | + * @param string $repository |
| 63 | + * @param string $id |
| 64 | + * |
| 65 | + * @return string |
| 66 | + */ |
| 67 | + abstract protected function getReactionsPath($username, $repository, $id); |
| 68 | +} |
0 commit comments