@@ -12,24 +12,24 @@ |
||
| 12 | 12 | class WebHook extends AbstractApi |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Constants */ |
|
| 16 | - const PAYLOAD = 'Payload'; |
|
| 15 | + /** Constants */ |
|
| 16 | + const PAYLOAD = 'Payload'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns Event object |
|
| 20 | - * |
|
| 21 | - * @param string $event |
|
| 22 | - * |
|
| 23 | - * @return null|EventInterface |
|
| 24 | - */ |
|
| 25 | - public function getEvent(string $event) |
|
| 26 | - { |
|
| 27 | - $class = (string)$this->sprintf(':namespace\Event\:event', __NAMESPACE__, $event); |
|
| 18 | + /** |
|
| 19 | + * Returns Event object |
|
| 20 | + * |
|
| 21 | + * @param string $event |
|
| 22 | + * |
|
| 23 | + * @return null|EventInterface |
|
| 24 | + */ |
|
| 25 | + public function getEvent(string $event) |
|
| 26 | + { |
|
| 27 | + $class = (string)$this->sprintf(':namespace\Event\:event', __NAMESPACE__, $event); |
|
| 28 | 28 | |
| 29 | - if (class_exists($class)) { |
|
| 30 | - return new $class($this); |
|
| 31 | - } |
|
| 29 | + if (class_exists($class)) { |
|
| 30 | + return new $class($this); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return null; |
|
| 34 | - } |
|
| 33 | + return null; |
|
| 34 | + } |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -11,17 +11,17 @@ |
||
| 11 | 11 | interface EventInterface |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Constructor, pass a WebHook object |
|
| 16 | - * |
|
| 17 | - * @param WebHook $webHook |
|
| 18 | - */ |
|
| 19 | - public function __construct(WebHook $webHook); |
|
| 14 | + /** |
|
| 15 | + * Constructor, pass a WebHook object |
|
| 16 | + * |
|
| 17 | + * @param WebHook $webHook |
|
| 18 | + */ |
|
| 19 | + public function __construct(WebHook $webHook); |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Parse raw data |
|
| 23 | - * |
|
| 24 | - * @return Payload |
|
| 25 | - */ |
|
| 26 | - public function parse(): Payload; |
|
| 21 | + /** |
|
| 22 | + * Parse raw data |
|
| 23 | + * |
|
| 24 | + * @return Payload |
|
| 25 | + */ |
|
| 26 | + public function parse(): Payload; |
|
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -13,190 +13,190 @@ |
||
| 13 | 13 | class Payload implements EventInterface |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** Protected properties */ |
|
| 17 | - protected $webHook; |
|
| 18 | - protected $secret = null; |
|
| 19 | - protected $rawData; |
|
| 20 | - protected $parsedData; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Constructor, pass a WebHook object |
|
| 24 | - * |
|
| 25 | - * @param WebHook $webHook |
|
| 26 | - */ |
|
| 27 | - public function __construct(WebHook $webHook) |
|
| 28 | - { |
|
| 29 | - $this->setWebHook($webHook); |
|
| 30 | - $this->setRawData($webHook->getRequest()->getContent()); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Get webHook |
|
| 35 | - * |
|
| 36 | - * @return null|WebHook |
|
| 37 | - */ |
|
| 38 | - public function getWebHook() |
|
| 39 | - { |
|
| 40 | - return $this->webHook; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Set webHook |
|
| 45 | - * |
|
| 46 | - * @param mixed $webHook |
|
| 47 | - * |
|
| 48 | - * @return Payload |
|
| 49 | - */ |
|
| 50 | - public function setWebHook($webHook): Payload |
|
| 51 | - { |
|
| 52 | - $this->webHook = $webHook; |
|
| 53 | - |
|
| 54 | - return $this; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Set secret, encode this secret with Hmac, SHA1 method |
|
| 59 | - * |
|
| 60 | - * @param string $secret |
|
| 61 | - * |
|
| 62 | - * @return Payload |
|
| 63 | - */ |
|
| 64 | - public function setSecret(string $secret): Payload |
|
| 65 | - { |
|
| 66 | - $this->secret = hash_hmac('sha1', $this->rawData, $secret); |
|
| 67 | - |
|
| 68 | - return $this; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Get secret |
|
| 73 | - * |
|
| 74 | - * @return null|string |
|
| 75 | - */ |
|
| 76 | - public function getSecret() |
|
| 77 | - { |
|
| 78 | - return $this->secret; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Get rawData |
|
| 83 | - * |
|
| 84 | - * @return resource|string |
|
| 85 | - */ |
|
| 86 | - public function getRawData() |
|
| 87 | - { |
|
| 88 | - return $this->rawData; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set rawData |
|
| 93 | - * |
|
| 94 | - * @param resource|string $rawData |
|
| 95 | - * |
|
| 96 | - * @return Payload |
|
| 97 | - */ |
|
| 98 | - public function setRawData($rawData): Payload |
|
| 99 | - { |
|
| 100 | - $this->rawData = $rawData; |
|
| 101 | - |
|
| 102 | - return $this; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Get parsedData |
|
| 107 | - * |
|
| 108 | - * @return mixed |
|
| 109 | - */ |
|
| 110 | - public function getData() |
|
| 111 | - { |
|
| 112 | - return $this->parsedData; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Set parsedData |
|
| 117 | - * |
|
| 118 | - * @param mixed $parsedData |
|
| 119 | - * |
|
| 120 | - * @return Payload |
|
| 121 | - */ |
|
| 122 | - protected function setParsedData($parsedData): Payload |
|
| 123 | - { |
|
| 124 | - $data = json_decode($parsedData); |
|
| 125 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
| 126 | - $this->parsedData = $data; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return $this; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Debugger |
|
| 134 | - * |
|
| 135 | - * @return array |
|
| 136 | - */ |
|
| 137 | - public function __debugInfo(): array |
|
| 138 | - { |
|
| 139 | - return [ |
|
| 140 | - 'ramData' => (array)$this->getRawData(), |
|
| 141 | - 'jsonEncoded' => json_decode($this->getRawData()) |
|
| 142 | - ]; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Parse raw data |
|
| 147 | - * |
|
| 148 | - * @return Payload |
|
| 149 | - * @throws BadSignatureException |
|
| 150 | - * @throws \Exception |
|
| 151 | - */ |
|
| 152 | - public function parse(): Payload |
|
| 153 | - { |
|
| 154 | - /** Check signature from header */ |
|
| 155 | - if (!$this->_checkSignature()) { |
|
| 156 | - throw new BadSignatureException('Hook secret does not match.'); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** Get data from different locations according to content-type */ |
|
| 160 | - switch ($_SERVER['CONTENT_TYPE']) { |
|
| 161 | - case 'application/json': |
|
| 162 | - $data = $this->getRawData(); |
|
| 163 | - break; |
|
| 164 | - |
|
| 165 | - case 'application/x-www-form-urlencoded': |
|
| 166 | - $data = $_POST['payload']; |
|
| 167 | - break; |
|
| 168 | - |
|
| 169 | - default: |
|
| 170 | - throw new \Exception('Unsupported content type: "' . $_SERVER['CONTENT_TYPE'] . '"'); |
|
| 171 | - } |
|
| 172 | - $this->setParsedData($data); |
|
| 173 | - |
|
| 174 | - return $this; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Check X-Hub-Signature |
|
| 179 | - * |
|
| 180 | - * @throws BadSignatureException |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - private function _checkSignature(): bool |
|
| 184 | - { |
|
| 185 | - if (null !== $this->secret) { |
|
| 186 | - if ($this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE')) { |
|
| 187 | - /** |
|
| 188 | - * Split signature into algorithm and hash |
|
| 189 | - * |
|
| 190 | - * @link http://isometriks.com/verify-github-webhooks-with-php |
|
| 191 | - */ |
|
| 192 | - list(, $hash) = explode('=', $this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE'), 2); |
|
| 193 | - |
|
| 194 | - return $this->secret == $hash; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - throw new BadSignatureException('HTTP header "X-Hub-Signature" is missing.'); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return true; |
|
| 201 | - } |
|
| 16 | + /** Protected properties */ |
|
| 17 | + protected $webHook; |
|
| 18 | + protected $secret = null; |
|
| 19 | + protected $rawData; |
|
| 20 | + protected $parsedData; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Constructor, pass a WebHook object |
|
| 24 | + * |
|
| 25 | + * @param WebHook $webHook |
|
| 26 | + */ |
|
| 27 | + public function __construct(WebHook $webHook) |
|
| 28 | + { |
|
| 29 | + $this->setWebHook($webHook); |
|
| 30 | + $this->setRawData($webHook->getRequest()->getContent()); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Get webHook |
|
| 35 | + * |
|
| 36 | + * @return null|WebHook |
|
| 37 | + */ |
|
| 38 | + public function getWebHook() |
|
| 39 | + { |
|
| 40 | + return $this->webHook; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Set webHook |
|
| 45 | + * |
|
| 46 | + * @param mixed $webHook |
|
| 47 | + * |
|
| 48 | + * @return Payload |
|
| 49 | + */ |
|
| 50 | + public function setWebHook($webHook): Payload |
|
| 51 | + { |
|
| 52 | + $this->webHook = $webHook; |
|
| 53 | + |
|
| 54 | + return $this; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Set secret, encode this secret with Hmac, SHA1 method |
|
| 59 | + * |
|
| 60 | + * @param string $secret |
|
| 61 | + * |
|
| 62 | + * @return Payload |
|
| 63 | + */ |
|
| 64 | + public function setSecret(string $secret): Payload |
|
| 65 | + { |
|
| 66 | + $this->secret = hash_hmac('sha1', $this->rawData, $secret); |
|
| 67 | + |
|
| 68 | + return $this; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Get secret |
|
| 73 | + * |
|
| 74 | + * @return null|string |
|
| 75 | + */ |
|
| 76 | + public function getSecret() |
|
| 77 | + { |
|
| 78 | + return $this->secret; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Get rawData |
|
| 83 | + * |
|
| 84 | + * @return resource|string |
|
| 85 | + */ |
|
| 86 | + public function getRawData() |
|
| 87 | + { |
|
| 88 | + return $this->rawData; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set rawData |
|
| 93 | + * |
|
| 94 | + * @param resource|string $rawData |
|
| 95 | + * |
|
| 96 | + * @return Payload |
|
| 97 | + */ |
|
| 98 | + public function setRawData($rawData): Payload |
|
| 99 | + { |
|
| 100 | + $this->rawData = $rawData; |
|
| 101 | + |
|
| 102 | + return $this; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Get parsedData |
|
| 107 | + * |
|
| 108 | + * @return mixed |
|
| 109 | + */ |
|
| 110 | + public function getData() |
|
| 111 | + { |
|
| 112 | + return $this->parsedData; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Set parsedData |
|
| 117 | + * |
|
| 118 | + * @param mixed $parsedData |
|
| 119 | + * |
|
| 120 | + * @return Payload |
|
| 121 | + */ |
|
| 122 | + protected function setParsedData($parsedData): Payload |
|
| 123 | + { |
|
| 124 | + $data = json_decode($parsedData); |
|
| 125 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
| 126 | + $this->parsedData = $data; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return $this; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Debugger |
|
| 134 | + * |
|
| 135 | + * @return array |
|
| 136 | + */ |
|
| 137 | + public function __debugInfo(): array |
|
| 138 | + { |
|
| 139 | + return [ |
|
| 140 | + 'ramData' => (array)$this->getRawData(), |
|
| 141 | + 'jsonEncoded' => json_decode($this->getRawData()) |
|
| 142 | + ]; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Parse raw data |
|
| 147 | + * |
|
| 148 | + * @return Payload |
|
| 149 | + * @throws BadSignatureException |
|
| 150 | + * @throws \Exception |
|
| 151 | + */ |
|
| 152 | + public function parse(): Payload |
|
| 153 | + { |
|
| 154 | + /** Check signature from header */ |
|
| 155 | + if (!$this->_checkSignature()) { |
|
| 156 | + throw new BadSignatureException('Hook secret does not match.'); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** Get data from different locations according to content-type */ |
|
| 160 | + switch ($_SERVER['CONTENT_TYPE']) { |
|
| 161 | + case 'application/json': |
|
| 162 | + $data = $this->getRawData(); |
|
| 163 | + break; |
|
| 164 | + |
|
| 165 | + case 'application/x-www-form-urlencoded': |
|
| 166 | + $data = $_POST['payload']; |
|
| 167 | + break; |
|
| 168 | + |
|
| 169 | + default: |
|
| 170 | + throw new \Exception('Unsupported content type: "' . $_SERVER['CONTENT_TYPE'] . '"'); |
|
| 171 | + } |
|
| 172 | + $this->setParsedData($data); |
|
| 173 | + |
|
| 174 | + return $this; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Check X-Hub-Signature |
|
| 179 | + * |
|
| 180 | + * @throws BadSignatureException |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + private function _checkSignature(): bool |
|
| 184 | + { |
|
| 185 | + if (null !== $this->secret) { |
|
| 186 | + if ($this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE')) { |
|
| 187 | + /** |
|
| 188 | + * Split signature into algorithm and hash |
|
| 189 | + * |
|
| 190 | + * @link http://isometriks.com/verify-github-webhooks-with-php |
|
| 191 | + */ |
|
| 192 | + list(, $hash) = explode('=', $this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE'), 2); |
|
| 193 | + |
|
| 194 | + return $this->secret == $hash; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + throw new BadSignatureException('HTTP header "X-Hub-Signature" is missing.'); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return true; |
|
| 201 | + } |
|
| 202 | 202 | } |
| 203 | 203 | \ No newline at end of file |
@@ -13,253 +13,253 @@ |
||
| 13 | 13 | class Gists extends AbstractReceiver |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** Available sub-Receiver */ |
|
| 17 | - const COMMENTS = 'Comments'; |
|
| 16 | + /** Available sub-Receiver */ |
|
| 17 | + const COMMENTS = 'Comments'; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * List a user's gists |
|
| 21 | - * |
|
| 22 | - * @link https://developer.github.com/v3/gists/#list-a-users-gists |
|
| 23 | - * |
|
| 24 | - * @param string $username |
|
| 25 | - * @param string $since |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - public function listGists(string $username = null, string $since = '1970-01-01'): array |
|
| 30 | - { |
|
| 31 | - $url = '/gists'; |
|
| 32 | - if (null !== $username) { |
|
| 33 | - $url = '/users/:username/gists'; |
|
| 34 | - } |
|
| 19 | + /** |
|
| 20 | + * List a user's gists |
|
| 21 | + * |
|
| 22 | + * @link https://developer.github.com/v3/gists/#list-a-users-gists |
|
| 23 | + * |
|
| 24 | + * @param string $username |
|
| 25 | + * @param string $since |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + public function listGists(string $username = null, string $since = '1970-01-01'): array |
|
| 30 | + { |
|
| 31 | + $url = '/gists'; |
|
| 32 | + if (null !== $username) { |
|
| 33 | + $url = '/users/:username/gists'; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - return $this->getApi()->request($this->getApi()->sprintf(':url?:arg', $url, $username, |
|
| 37 | - http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
| 38 | - } |
|
| 36 | + return $this->getApi()->request($this->getApi()->sprintf(':url?:arg', $url, $username, |
|
| 37 | + http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * List all public gists: |
|
| 42 | - * |
|
| 43 | - * @link https://developer.github.com/v3/gists/#list-all-public-gists |
|
| 44 | - * |
|
| 45 | - * @param string $since |
|
| 46 | - * |
|
| 47 | - * @return array |
|
| 48 | - */ |
|
| 49 | - public function listPublicGists(string $since = '1970-01-01'): array |
|
| 50 | - { |
|
| 51 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/public?:arg', |
|
| 52 | - http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
| 53 | - } |
|
| 40 | + /** |
|
| 41 | + * List all public gists: |
|
| 42 | + * |
|
| 43 | + * @link https://developer.github.com/v3/gists/#list-all-public-gists |
|
| 44 | + * |
|
| 45 | + * @param string $since |
|
| 46 | + * |
|
| 47 | + * @return array |
|
| 48 | + */ |
|
| 49 | + public function listPublicGists(string $since = '1970-01-01'): array |
|
| 50 | + { |
|
| 51 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/public?:arg', |
|
| 52 | + http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * List the authenticated user’s starred gists |
|
| 57 | - * |
|
| 58 | - * @link https://developer.github.com/v3/gists/#list-starred-gists |
|
| 59 | - * |
|
| 60 | - * @param string $since |
|
| 61 | - * |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 64 | - public function listUsersStarredGists(string $since = '1970-01-01'): array |
|
| 65 | - { |
|
| 66 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/starred?:arg', |
|
| 67 | - http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
| 68 | - } |
|
| 55 | + /** |
|
| 56 | + * List the authenticated user’s starred gists |
|
| 57 | + * |
|
| 58 | + * @link https://developer.github.com/v3/gists/#list-starred-gists |
|
| 59 | + * |
|
| 60 | + * @param string $since |
|
| 61 | + * |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | + public function listUsersStarredGists(string $since = '1970-01-01'): array |
|
| 65 | + { |
|
| 66 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/starred?:arg', |
|
| 67 | + http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Get a single gist |
|
| 72 | - * |
|
| 73 | - * @link https://developer.github.com/v3/gists/#get-a-single-gist |
|
| 74 | - * |
|
| 75 | - * @param int $id |
|
| 76 | - * |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public function getGist(int $id): array |
|
| 80 | - { |
|
| 81 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id)); |
|
| 82 | - } |
|
| 70 | + /** |
|
| 71 | + * Get a single gist |
|
| 72 | + * |
|
| 73 | + * @link https://developer.github.com/v3/gists/#get-a-single-gist |
|
| 74 | + * |
|
| 75 | + * @param int $id |
|
| 76 | + * |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public function getGist(int $id): array |
|
| 80 | + { |
|
| 81 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id)); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Get a specific revision of a gist |
|
| 86 | - * |
|
| 87 | - * @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist |
|
| 88 | - * |
|
| 89 | - * @param string $id |
|
| 90 | - * @param string $sha |
|
| 91 | - * |
|
| 92 | - * @return array |
|
| 93 | - * @throws \Exception |
|
| 94 | - */ |
|
| 95 | - public function getGistRevision(string $id, string $sha): array |
|
| 96 | - { |
|
| 97 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/:sha', $id, $sha)); |
|
| 98 | - } |
|
| 84 | + /** |
|
| 85 | + * Get a specific revision of a gist |
|
| 86 | + * |
|
| 87 | + * @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist |
|
| 88 | + * |
|
| 89 | + * @param string $id |
|
| 90 | + * @param string $sha |
|
| 91 | + * |
|
| 92 | + * @return array |
|
| 93 | + * @throws \Exception |
|
| 94 | + */ |
|
| 95 | + public function getGistRevision(string $id, string $sha): array |
|
| 96 | + { |
|
| 97 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/:sha', $id, $sha)); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Create a gist |
|
| 102 | - * |
|
| 103 | - * @link https://developer.github.com/v3/gists/#create-a-gist |
|
| 104 | - * |
|
| 105 | - * @param string $files |
|
| 106 | - * @param string $description |
|
| 107 | - * @param bool $public |
|
| 108 | - * |
|
| 109 | - * @return array |
|
| 110 | - */ |
|
| 111 | - public function createGist(string $files, string $description = null, bool $public = false): array |
|
| 112 | - { |
|
| 113 | - return $this->getApi()->request($this->getApi()->sprintf('/gists'), Request::METHOD_POST, [ |
|
| 114 | - 'files' => $files, |
|
| 115 | - 'description' => $description, |
|
| 116 | - 'public' => $public |
|
| 117 | - ]); |
|
| 118 | - } |
|
| 100 | + /** |
|
| 101 | + * Create a gist |
|
| 102 | + * |
|
| 103 | + * @link https://developer.github.com/v3/gists/#create-a-gist |
|
| 104 | + * |
|
| 105 | + * @param string $files |
|
| 106 | + * @param string $description |
|
| 107 | + * @param bool $public |
|
| 108 | + * |
|
| 109 | + * @return array |
|
| 110 | + */ |
|
| 111 | + public function createGist(string $files, string $description = null, bool $public = false): array |
|
| 112 | + { |
|
| 113 | + return $this->getApi()->request($this->getApi()->sprintf('/gists'), Request::METHOD_POST, [ |
|
| 114 | + 'files' => $files, |
|
| 115 | + 'description' => $description, |
|
| 116 | + 'public' => $public |
|
| 117 | + ]); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Edit a gist |
|
| 122 | - * |
|
| 123 | - * @link https://developer.github.com/v3/gists/#edit-a-gist |
|
| 124 | - * |
|
| 125 | - * @param int $id |
|
| 126 | - * @param string $description |
|
| 127 | - * @param string $files |
|
| 128 | - * @param string $content |
|
| 129 | - * @param string $filename |
|
| 130 | - * |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - public function editGist(int $id, string $description = '', string $files = '{}', string $content = '', |
|
| 134 | - string $filename = ''): array |
|
| 135 | - { |
|
| 136 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_PATCH, [ |
|
| 137 | - 'description' => $description, |
|
| 138 | - 'files' => $files, |
|
| 139 | - 'content' => $content, |
|
| 140 | - 'filename' => $filename |
|
| 141 | - ]); |
|
| 142 | - } |
|
| 120 | + /** |
|
| 121 | + * Edit a gist |
|
| 122 | + * |
|
| 123 | + * @link https://developer.github.com/v3/gists/#edit-a-gist |
|
| 124 | + * |
|
| 125 | + * @param int $id |
|
| 126 | + * @param string $description |
|
| 127 | + * @param string $files |
|
| 128 | + * @param string $content |
|
| 129 | + * @param string $filename |
|
| 130 | + * |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + public function editGist(int $id, string $description = '', string $files = '{}', string $content = '', |
|
| 134 | + string $filename = ''): array |
|
| 135 | + { |
|
| 136 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_PATCH, [ |
|
| 137 | + 'description' => $description, |
|
| 138 | + 'files' => $files, |
|
| 139 | + 'content' => $content, |
|
| 140 | + 'filename' => $filename |
|
| 141 | + ]); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * List gist commits |
|
| 146 | - * |
|
| 147 | - * @link https://developer.github.com/v3/gists/#list-gist-commits |
|
| 148 | - * |
|
| 149 | - * @param int $id |
|
| 150 | - * |
|
| 151 | - * @return array |
|
| 152 | - */ |
|
| 153 | - public function listGistsCommits(int $id): array |
|
| 154 | - { |
|
| 155 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/commits', $id)); |
|
| 156 | - } |
|
| 144 | + /** |
|
| 145 | + * List gist commits |
|
| 146 | + * |
|
| 147 | + * @link https://developer.github.com/v3/gists/#list-gist-commits |
|
| 148 | + * |
|
| 149 | + * @param int $id |
|
| 150 | + * |
|
| 151 | + * @return array |
|
| 152 | + */ |
|
| 153 | + public function listGistsCommits(int $id): array |
|
| 154 | + { |
|
| 155 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/commits', $id)); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Star a gist |
|
| 160 | - * |
|
| 161 | - * @link https://developer.github.com/v3/gists/#star-a-gist |
|
| 162 | - * |
|
| 163 | - * @param int $id |
|
| 164 | - * |
|
| 165 | - * @return bool |
|
| 166 | - */ |
|
| 167 | - public function starGist(int $id): bool |
|
| 168 | - { |
|
| 169 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_PUT); |
|
| 158 | + /** |
|
| 159 | + * Star a gist |
|
| 160 | + * |
|
| 161 | + * @link https://developer.github.com/v3/gists/#star-a-gist |
|
| 162 | + * |
|
| 163 | + * @param int $id |
|
| 164 | + * |
|
| 165 | + * @return bool |
|
| 166 | + */ |
|
| 167 | + public function starGist(int $id): bool |
|
| 168 | + { |
|
| 169 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_PUT); |
|
| 170 | 170 | |
| 171 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 172 | - return true; |
|
| 173 | - } |
|
| 171 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 172 | + return true; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - return false; |
|
| 176 | - } |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Unstar a gist |
|
| 180 | - * |
|
| 181 | - * @link https://developer.github.com/v3/gists/#unstar-a-gist |
|
| 182 | - * |
|
| 183 | - * @param int $id |
|
| 184 | - * |
|
| 185 | - * @return bool |
|
| 186 | - */ |
|
| 187 | - public function unStarGist(int $id): bool |
|
| 188 | - { |
|
| 189 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_DELETE); |
|
| 178 | + /** |
|
| 179 | + * Unstar a gist |
|
| 180 | + * |
|
| 181 | + * @link https://developer.github.com/v3/gists/#unstar-a-gist |
|
| 182 | + * |
|
| 183 | + * @param int $id |
|
| 184 | + * |
|
| 185 | + * @return bool |
|
| 186 | + */ |
|
| 187 | + public function unStarGist(int $id): bool |
|
| 188 | + { |
|
| 189 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_DELETE); |
|
| 190 | 190 | |
| 191 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 192 | - return true; |
|
| 193 | - } |
|
| 191 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - return false; |
|
| 196 | - } |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Check if a gist is starred |
|
| 200 | - * |
|
| 201 | - * @link https://developer.github.com/v3/gists/#check-if-a-gist-is-starred |
|
| 202 | - * |
|
| 203 | - * @param int $id |
|
| 204 | - * |
|
| 205 | - * @return bool |
|
| 206 | - */ |
|
| 207 | - public function checkGistIsStarred(int $id): bool |
|
| 208 | - { |
|
| 209 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id)); |
|
| 198 | + /** |
|
| 199 | + * Check if a gist is starred |
|
| 200 | + * |
|
| 201 | + * @link https://developer.github.com/v3/gists/#check-if-a-gist-is-starred |
|
| 202 | + * |
|
| 203 | + * @param int $id |
|
| 204 | + * |
|
| 205 | + * @return bool |
|
| 206 | + */ |
|
| 207 | + public function checkGistIsStarred(int $id): bool |
|
| 208 | + { |
|
| 209 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id)); |
|
| 210 | 210 | |
| 211 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 212 | - return true; |
|
| 213 | - } |
|
| 211 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 212 | + return true; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return false; |
|
| 216 | - } |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * Fork a gist |
|
| 220 | - * |
|
| 221 | - * @link https://developer.github.com/v3/gists/#fork-a-gist |
|
| 222 | - * |
|
| 223 | - * @param int $id |
|
| 224 | - * |
|
| 225 | - * @return array |
|
| 226 | - */ |
|
| 227 | - public function forkGist(int $id): array |
|
| 228 | - { |
|
| 229 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id), Request::METHOD_POST); |
|
| 230 | - } |
|
| 218 | + /** |
|
| 219 | + * Fork a gist |
|
| 220 | + * |
|
| 221 | + * @link https://developer.github.com/v3/gists/#fork-a-gist |
|
| 222 | + * |
|
| 223 | + * @param int $id |
|
| 224 | + * |
|
| 225 | + * @return array |
|
| 226 | + */ |
|
| 227 | + public function forkGist(int $id): array |
|
| 228 | + { |
|
| 229 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id), Request::METHOD_POST); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * List gist forks |
|
| 234 | - * |
|
| 235 | - * @link https://developer.github.com/v3/gists/#list-gist-forks |
|
| 236 | - * |
|
| 237 | - * @param int $id |
|
| 238 | - * |
|
| 239 | - * @return array |
|
| 240 | - */ |
|
| 241 | - public function listGistForks(int $id): array |
|
| 242 | - { |
|
| 243 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id)); |
|
| 244 | - } |
|
| 232 | + /** |
|
| 233 | + * List gist forks |
|
| 234 | + * |
|
| 235 | + * @link https://developer.github.com/v3/gists/#list-gist-forks |
|
| 236 | + * |
|
| 237 | + * @param int $id |
|
| 238 | + * |
|
| 239 | + * @return array |
|
| 240 | + */ |
|
| 241 | + public function listGistForks(int $id): array |
|
| 242 | + { |
|
| 243 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id)); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * Delete a gist |
|
| 248 | - * |
|
| 249 | - * @link https://developer.github.com/v3/gists/#delete-a-gist |
|
| 250 | - * |
|
| 251 | - * @param int $id |
|
| 252 | - * |
|
| 253 | - * @return bool |
|
| 254 | - */ |
|
| 255 | - public function deleteGist(int $id): bool |
|
| 256 | - { |
|
| 257 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_DELETE); |
|
| 246 | + /** |
|
| 247 | + * Delete a gist |
|
| 248 | + * |
|
| 249 | + * @link https://developer.github.com/v3/gists/#delete-a-gist |
|
| 250 | + * |
|
| 251 | + * @param int $id |
|
| 252 | + * |
|
| 253 | + * @return bool |
|
| 254 | + */ |
|
| 255 | + public function deleteGist(int $id): bool |
|
| 256 | + { |
|
| 257 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_DELETE); |
|
| 258 | 258 | |
| 259 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 259 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - return false; |
|
| 264 | - } |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | 265 | } |
| 266 | 266 | \ No newline at end of file |