@@ -156,7 +156,7 @@ |
||
| 156 | 156 | /** |
| 157 | 157 | * Set accept |
| 158 | 158 | * |
| 159 | - * @param array|string $accept |
|
| 159 | + * @param string $accept |
|
| 160 | 160 | * |
| 161 | 161 | * @return AbstractApi |
| 162 | 162 | */ |
@@ -8,572 +8,572 @@ |
||
| 8 | 8 | abstract class AbstractApi |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** API version */ |
|
| 12 | - const API_VERSION = 'v3'; |
|
| 13 | - |
|
| 14 | - /** API constants */ |
|
| 15 | - const API_URL = 'https://api.github.com'; |
|
| 16 | - const API_UPLOADS = 'https://uploads.github.com'; |
|
| 17 | - const API_RAW_URL = 'https://raw.github.com'; |
|
| 18 | - const CONTENT_TYPE = 'application/json'; |
|
| 19 | - const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json'; |
|
| 20 | - const USER_AGENT = 'scion.github-api'; |
|
| 21 | - |
|
| 22 | - /** Archive constants */ |
|
| 23 | - const ARCHIVE_TARBALL = 'tarball'; |
|
| 24 | - const ARCHIVE_ZIPBALL = 'zipball'; |
|
| 25 | - |
|
| 26 | - /** Authentication constants */ |
|
| 27 | - const OAUTH_AUTH = 0; |
|
| 28 | - const OAUTH2_HEADER_AUTH = 1; |
|
| 29 | - const OAUTH2_PARAMETERS_AUTH = 2; |
|
| 30 | - |
|
| 31 | - /** Branch constants */ |
|
| 32 | - const BRANCH_MASTER = 'master'; |
|
| 33 | - const BRANCH_DEVELOP = 'develop'; |
|
| 34 | - |
|
| 35 | - /** Direction constants */ |
|
| 36 | - const DIRECTION_ASC = 'asc'; |
|
| 37 | - const DIRECTION_DESC = 'desc'; |
|
| 38 | - |
|
| 39 | - /** Environment constants */ |
|
| 40 | - const ENVIRONMENT_PRODUCTION = 'production'; |
|
| 41 | - const ENVIRONMENT_STAGING = 'staging'; |
|
| 42 | - const ENVIRONMENT_QA = 'qa'; |
|
| 43 | - |
|
| 44 | - /** Events constants */ |
|
| 45 | - const EVENTS_PULL = 'pull'; |
|
| 46 | - const EVENTS_PULL_REQUEST = 'pull_request'; |
|
| 47 | - const EVENTS_PUSH = 'push'; |
|
| 48 | - |
|
| 49 | - /** Filter constants */ |
|
| 50 | - const FILTER_ALL = 'all'; |
|
| 51 | - const FILTER_ASSIGNED = 'assigned'; |
|
| 52 | - const FILTER_CREATED = 'created'; |
|
| 53 | - const FILTER_MENTIONED = 'mentioned'; |
|
| 54 | - const FILTER_SUBSCRIBED = 'subscribed'; |
|
| 55 | - |
|
| 56 | - /** Media types constants */ |
|
| 57 | - const MEDIA_TYPE_JSON = 'json'; |
|
| 58 | - const MEDIA_TYPE_RAW = 'raw'; |
|
| 59 | - const MEDIA_TYPE_FULL = 'full'; |
|
| 60 | - const MEDIA_TYPE_TEXT = 'text'; |
|
| 61 | - |
|
| 62 | - /** Modes constants */ |
|
| 63 | - const MODE_MARKDOWN = 'markdown'; |
|
| 64 | - const MODE_GFM = 'gfm'; |
|
| 65 | - |
|
| 66 | - /** Permissions constants */ |
|
| 67 | - const PERMISSION_ADMIN = 'admin'; |
|
| 68 | - const PERMISSION_PULL = 'pull'; |
|
| 69 | - const PERMISSION_PUSH = 'push'; |
|
| 70 | - |
|
| 71 | - /** Sort constants */ |
|
| 72 | - const SORT_COMPLETENESS = 'completeness'; |
|
| 73 | - const SORT_CREATED = 'created'; |
|
| 74 | - const SORT_DUE_DATE = 'due_date'; |
|
| 75 | - const SORT_FULL_NAME = 'full_name'; |
|
| 76 | - const SORT_NEWEST = 'newest'; |
|
| 77 | - const SORT_OLDEST = 'oldest'; |
|
| 78 | - const SORT_PUSHED = 'pushed'; |
|
| 79 | - const SORT_STARGAZERS = 'stargazers'; |
|
| 80 | - const SORT_UPDATED = 'updated'; |
|
| 81 | - |
|
| 82 | - /** State constants */ |
|
| 83 | - const STATE_ACTIVE = 'active'; |
|
| 84 | - const STATE_ALL = 'all'; |
|
| 85 | - const STATE_CLOSED = 'closed'; |
|
| 86 | - const STATE_ERROR = 'error'; |
|
| 87 | - const STATE_FAILURE = 'failure'; |
|
| 88 | - const STATE_OPEN = 'open'; |
|
| 89 | - const STATE_PENDING = 'pending'; |
|
| 90 | - const STATE_SUCCESS = 'success'; |
|
| 91 | - |
|
| 92 | - /** Task constants */ |
|
| 93 | - const TASK_DEPLOY = 'deploy'; |
|
| 94 | - const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations'; |
|
| 95 | - |
|
| 96 | - /** Type constants */ |
|
| 97 | - const TYPE_ALL = 'all'; |
|
| 98 | - const TYPE_COMMENTS = 'comments'; |
|
| 99 | - const TYPE_GISTS = 'gists'; |
|
| 100 | - const TYPE_HOOKS = 'hooks'; |
|
| 101 | - const TYPE_ISSUES = 'issues'; |
|
| 102 | - const TYPE_MEMBER = 'member'; |
|
| 103 | - const TYPE_MILESTONES = 'milestones'; |
|
| 104 | - const TYPE_ORGS = 'orgs'; |
|
| 105 | - const TYPE_OWNER = 'owner'; |
|
| 106 | - const TYPE_PAGES = 'pages'; |
|
| 107 | - const TYPE_PUBLIC = 'public'; |
|
| 108 | - const TYPE_PULLS = 'pulls'; |
|
| 109 | - const TYPE_PRIVATE = 'private'; |
|
| 110 | - const TYPE_REPOS = 'repos'; |
|
| 111 | - const TYPE_USERS = 'users'; |
|
| 112 | - |
|
| 113 | - /** Properties */ |
|
| 114 | - protected $accept = self::DEFAULT_ACCEPT; |
|
| 115 | - protected $apiUrl = self::API_URL; |
|
| 116 | - protected $authentication = self::OAUTH_AUTH; |
|
| 117 | - protected $clientId; |
|
| 118 | - protected $clientSecret; |
|
| 119 | - protected $contentType = self::CONTENT_TYPE; |
|
| 120 | - protected $failure; |
|
| 121 | - protected $headers = []; |
|
| 122 | - protected $httpAuth = ['username' => '', 'password' => '']; |
|
| 123 | - protected $success; |
|
| 124 | - protected $timeout = 240; |
|
| 125 | - protected $token = ''; |
|
| 126 | - protected $request; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Constructor |
|
| 130 | - */ |
|
| 131 | - public function __construct() |
|
| 132 | - { |
|
| 133 | - $this->request = Request::createFromGlobals(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Get request |
|
| 138 | - * |
|
| 139 | - * @return Request |
|
| 140 | - */ |
|
| 141 | - public function getRequest(): Request |
|
| 142 | - { |
|
| 143 | - return $this->request; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Get accept |
|
| 148 | - * |
|
| 149 | - * @return mixed |
|
| 150 | - */ |
|
| 151 | - public function getAccept() |
|
| 152 | - { |
|
| 153 | - return $this->accept; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Set accept |
|
| 158 | - * |
|
| 159 | - * @param array|string $accept |
|
| 160 | - * |
|
| 161 | - * @return AbstractApi |
|
| 162 | - */ |
|
| 163 | - public function setAccept($accept): AbstractApi |
|
| 164 | - { |
|
| 165 | - $this->accept = $accept; |
|
| 166 | - |
|
| 167 | - return $this; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Get authentication |
|
| 172 | - * |
|
| 173 | - * @return int |
|
| 174 | - */ |
|
| 175 | - public function getAuthentication(): int |
|
| 176 | - { |
|
| 177 | - return $this->authentication; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Set authentication |
|
| 182 | - * |
|
| 183 | - * @param int $authentication |
|
| 184 | - * |
|
| 185 | - * @return AbstractApi |
|
| 186 | - */ |
|
| 187 | - public function setAuthentication(int $authentication): AbstractApi |
|
| 188 | - { |
|
| 189 | - $this->authentication = $authentication; |
|
| 190 | - |
|
| 191 | - return $this; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Get apiUrl |
|
| 196 | - * |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function getApiUrl(): string |
|
| 200 | - { |
|
| 201 | - return $this->apiUrl; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Set apiUrl |
|
| 206 | - * |
|
| 207 | - * @param mixed $apiUrl |
|
| 208 | - * |
|
| 209 | - * @return AbstractApi |
|
| 210 | - */ |
|
| 211 | - public function setApiUrl($apiUrl): AbstractApi |
|
| 212 | - { |
|
| 213 | - $this->apiUrl = $apiUrl; |
|
| 214 | - |
|
| 215 | - return $this; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Get clientId |
|
| 220 | - * |
|
| 221 | - * @return null|int |
|
| 222 | - */ |
|
| 223 | - public function getClientId() |
|
| 224 | - { |
|
| 225 | - return $this->clientId; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Set clientId |
|
| 230 | - * |
|
| 231 | - * @param mixed $clientId |
|
| 232 | - * |
|
| 233 | - * @return AbstractApi |
|
| 234 | - */ |
|
| 235 | - public function setClientId($clientId): AbstractApi |
|
| 236 | - { |
|
| 237 | - $this->clientId = $clientId; |
|
| 238 | - |
|
| 239 | - return $this; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Get clientSecret |
|
| 244 | - * |
|
| 245 | - * @return null|string |
|
| 246 | - */ |
|
| 247 | - public function getClientSecret() |
|
| 248 | - { |
|
| 249 | - return $this->clientSecret; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Set clientSecret |
|
| 254 | - * |
|
| 255 | - * @param mixed $clientSecret |
|
| 256 | - * |
|
| 257 | - * @return AbstractApi |
|
| 258 | - */ |
|
| 259 | - public function setClientSecret($clientSecret): AbstractApi |
|
| 260 | - { |
|
| 261 | - $this->clientSecret = $clientSecret; |
|
| 262 | - |
|
| 263 | - return $this; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Get httpAuth |
|
| 268 | - * |
|
| 269 | - * @return array |
|
| 270 | - */ |
|
| 271 | - public function getHttpAuth(): array |
|
| 272 | - { |
|
| 273 | - return $this->httpAuth; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Set httpAuth |
|
| 278 | - * |
|
| 279 | - * @param string $username |
|
| 280 | - * @param string $password |
|
| 281 | - * |
|
| 282 | - * @return AbstractApi |
|
| 283 | - */ |
|
| 284 | - public function setHttpAuth(string $username, string $password = ''): AbstractApi |
|
| 285 | - { |
|
| 286 | - $this->httpAuth['username'] = $username; |
|
| 287 | - $this->httpAuth['password'] = $password; |
|
| 288 | - |
|
| 289 | - return $this; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Get token |
|
| 294 | - * |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - public function getToken(): string |
|
| 298 | - { |
|
| 299 | - return $this->token; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Set token |
|
| 304 | - * |
|
| 305 | - * @param string $token |
|
| 306 | - * @param int $authentication |
|
| 307 | - * |
|
| 308 | - * @return AbstractApi |
|
| 309 | - */ |
|
| 310 | - public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi |
|
| 311 | - { |
|
| 312 | - $this->token = $token; |
|
| 313 | - $this->setAuthentication($authentication); |
|
| 314 | - |
|
| 315 | - return $this; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Get timeout |
|
| 320 | - * |
|
| 321 | - * @return int |
|
| 322 | - */ |
|
| 323 | - public function getTimeout(): int |
|
| 324 | - { |
|
| 325 | - return $this->timeout; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Set timeout |
|
| 330 | - * |
|
| 331 | - * @param int $timeout |
|
| 332 | - * |
|
| 333 | - * @return AbstractApi |
|
| 334 | - */ |
|
| 335 | - public function setTimeout(int $timeout): AbstractApi |
|
| 336 | - { |
|
| 337 | - $this->timeout = $timeout; |
|
| 338 | - |
|
| 339 | - return $this; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Get contentType |
|
| 344 | - * |
|
| 345 | - * @return string |
|
| 346 | - */ |
|
| 347 | - public function getContentType(): string |
|
| 348 | - { |
|
| 349 | - return $this->contentType; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Set contentType |
|
| 354 | - * |
|
| 355 | - * @param string $contentType |
|
| 356 | - * |
|
| 357 | - * @return AbstractApi |
|
| 358 | - */ |
|
| 359 | - public function setContentType(string $contentType): AbstractApi |
|
| 360 | - { |
|
| 361 | - $this->contentType = $contentType; |
|
| 362 | - |
|
| 363 | - return $this; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Get headers |
|
| 368 | - * |
|
| 369 | - * @return array |
|
| 370 | - */ |
|
| 371 | - public function getHeaders(): array |
|
| 372 | - { |
|
| 373 | - return $this->headers; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Curl request |
|
| 378 | - * |
|
| 379 | - * @param string $url |
|
| 380 | - * @param string $method |
|
| 381 | - * @param array $postFields |
|
| 382 | - * @param null|string $apiUrl |
|
| 383 | - * |
|
| 384 | - * @return array |
|
| 385 | - */ |
|
| 386 | - public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [], |
|
| 387 | - string $apiUrl = null): array |
|
| 388 | - { |
|
| 389 | - /** Building url */ |
|
| 390 | - if (null === $apiUrl) { |
|
| 391 | - $apiUrl = $this->getApiUrl(); |
|
| 392 | - } |
|
| 393 | - $url = $apiUrl . $url; |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * OAuth2 Key/Secret authentication |
|
| 397 | - * |
|
| 398 | - * @see https://developer.github.com/v3/#oauth2-keysecret |
|
| 399 | - */ |
|
| 400 | - if (null !== $this->getClientId() && null !== $this->getClientSecret()) { |
|
| 401 | - $url .= (strstr($url, '?') !== false ? '&' : '?'); |
|
| 402 | - $url .= http_build_query(['client_id' => $this->getClientId(), |
|
| 403 | - 'client_secret' => $this->getClientSecret() |
|
| 404 | - ]); |
|
| 405 | - } /** |
|
| 406 | - * Basic authentication via OAuth2 Token (sent as a parameter) |
|
| 407 | - * |
|
| 408 | - * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter |
|
| 409 | - */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) { |
|
| 410 | - $url .= http_build_query(['access_token' => $this->getToken()]); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** Call curl */ |
|
| 414 | - $curl = new CurlClient(); |
|
| 415 | - $curl->setOption([ |
|
| 416 | - CURLOPT_USERAGENT => self::USER_AGENT, |
|
| 417 | - CURLOPT_TIMEOUT => $this->getTimeout(), |
|
| 418 | - CURLOPT_HEADER => false, // Use $client->getHeaders() to get full header |
|
| 419 | - CURLOPT_FOLLOWLOCATION => true, |
|
| 420 | - CURLOPT_HTTPHEADER => [ |
|
| 421 | - 'Accept: ' . $this->getAccept(), |
|
| 422 | - 'Content-Type: ' . $this->getContentType() |
|
| 423 | - ], |
|
| 424 | - CURLOPT_URL => $url |
|
| 425 | - ]); |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Basic authentication via username and Password |
|
| 429 | - * |
|
| 430 | - * @see https://developer.github.com/v3/auth/#via-username-and-password |
|
| 431 | - */ |
|
| 432 | - if (!empty($this->getHttpAuth())) { |
|
| 433 | - if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) { |
|
| 434 | - $curl->setOption([ |
|
| 435 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 436 | - CURLOPT_USERPWD => $this->getHttpAuth()['username'] |
|
| 437 | - ]); |
|
| 438 | - } else { |
|
| 439 | - $curl->setOption([ |
|
| 440 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 441 | - CURLOPT_USERPWD => sprintf('%s:%s', $this->getHttpAuth()['username'], |
|
| 442 | - $this->getHttpAuth()['password']) |
|
| 443 | - ]); |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) { |
|
| 448 | - /** |
|
| 449 | - * Basic authentication via OAuth token |
|
| 450 | - * |
|
| 451 | - * @see https://developer.github.com/v3/auth/#via-oauth-tokens |
|
| 452 | - **/ |
|
| 453 | - if ($this->getAuthentication() === self::OAUTH_AUTH) { |
|
| 454 | - $curl->setOption([ |
|
| 455 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 456 | - CURLOPT_USERPWD => sprintf('%s:x-oauth-basic', $this->getToken()) |
|
| 457 | - ]); |
|
| 458 | - } /** |
|
| 459 | - * Basic authentication via OAuth2 Token (sent in a header) |
|
| 460 | - * |
|
| 461 | - * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header |
|
| 462 | - */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) { |
|
| 463 | - $curl->setOption([ |
|
| 464 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 465 | - CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())] |
|
| 466 | - ]); |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** Methods */ |
|
| 471 | - switch ($method) { |
|
| 472 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */ |
|
| 473 | - case Request::METHOD_DELETE: |
|
| 474 | - /** @see http://tools.ietf.org/html/rfc5789 */ |
|
| 475 | - case Request::METHOD_PATCH: |
|
| 476 | - $curl->setOption([ |
|
| 477 | - CURLOPT_CUSTOMREQUEST => $method, |
|
| 478 | - CURLOPT_POST => true, |
|
| 479 | - CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 480 | - ]); |
|
| 481 | - break; |
|
| 482 | - |
|
| 483 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */ |
|
| 484 | - case Request::METHOD_GET: |
|
| 485 | - $curl->setOption(CURLOPT_HTTPGET, true); |
|
| 486 | - break; |
|
| 487 | - |
|
| 488 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */ |
|
| 489 | - case Request::METHOD_HEAD: |
|
| 490 | - $curl->setOption([ |
|
| 491 | - CURLOPT_CUSTOMREQUEST => $method, |
|
| 492 | - CURLOPT_NOBODY => true |
|
| 493 | - ]); |
|
| 494 | - break; |
|
| 495 | - |
|
| 496 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */ |
|
| 497 | - case Request::METHOD_POST: |
|
| 498 | - $curl->setOption([ |
|
| 499 | - CURLOPT_POST => true, |
|
| 500 | - CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 501 | - ]); |
|
| 502 | - break; |
|
| 503 | - |
|
| 504 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */ |
|
| 505 | - case Request::METHOD_PUT: |
|
| 506 | - $curl->setOption([ |
|
| 507 | - CURLOPT_CUSTOMREQUEST => $method, |
|
| 508 | - CURLOPT_PUT => true, |
|
| 509 | - CURLOPT_HTTPHEADER => [ |
|
| 510 | - 'X-HTTP-Method-Override: PUT', |
|
| 511 | - 'Content-type: application/x-www-form-urlencoded' |
|
| 512 | - ] |
|
| 513 | - ]); |
|
| 514 | - break; |
|
| 515 | - |
|
| 516 | - default: |
|
| 517 | - break; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $curl->success(function (CurlClient $instance) { |
|
| 521 | - $this->headers = $instance->getHeaders(); |
|
| 522 | - $this->success = $instance->getResponse(); |
|
| 523 | - $data = json_decode($this->success, true); |
|
| 524 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
| 525 | - $this->success = $data; |
|
| 526 | - } |
|
| 527 | - }); |
|
| 528 | - $curl->error(function (CurlClient $instance) { |
|
| 529 | - $this->headers = $instance->getHeaders(); |
|
| 530 | - $this->failure = $instance->getResponse(); |
|
| 531 | - $data = json_decode($this->failure, true); |
|
| 532 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
| 533 | - $this->failure = $data; |
|
| 534 | - } |
|
| 535 | - }); |
|
| 536 | - $curl->perform(); |
|
| 537 | - |
|
| 538 | - return $this->success ?? $this->failure; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Return a formatted string. Modified version of sprintf using colon(:) |
|
| 543 | - * |
|
| 544 | - * @param string $string |
|
| 545 | - * @param array $params |
|
| 546 | - * |
|
| 547 | - * @return String |
|
| 548 | - * @throws Exception |
|
| 549 | - */ |
|
| 550 | - public function sprintf(string $string, ...$params): string |
|
| 551 | - { |
|
| 552 | - preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches); |
|
| 553 | - $matches = $matches[1]; |
|
| 554 | - |
|
| 555 | - if (count($matches)) { |
|
| 556 | - $tokens = []; |
|
| 557 | - $replaces = []; |
|
| 558 | - |
|
| 559 | - foreach ($matches as $key => $value) { |
|
| 560 | - if (count($params) > 1 || !is_array($params[0])) { |
|
| 561 | - if (!array_key_exists($key, $params)) { |
|
| 562 | - throw new Exception('Too few arguments, missing argument: ' . $key); |
|
| 563 | - } |
|
| 564 | - $replaces[] = $params[$key]; |
|
| 565 | - } else { |
|
| 566 | - if (!array_key_exists($value, $params[0])) { |
|
| 567 | - throw new Exception('Missing array argument: ' . $key); |
|
| 568 | - } |
|
| 569 | - $replaces[] = $params[0][$value]; |
|
| 570 | - } |
|
| 571 | - $tokens[] = ':' . $value; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - $string = str_replace($tokens, $replaces, $string); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return $string; |
|
| 578 | - } |
|
| 11 | + /** API version */ |
|
| 12 | + const API_VERSION = 'v3'; |
|
| 13 | + |
|
| 14 | + /** API constants */ |
|
| 15 | + const API_URL = 'https://api.github.com'; |
|
| 16 | + const API_UPLOADS = 'https://uploads.github.com'; |
|
| 17 | + const API_RAW_URL = 'https://raw.github.com'; |
|
| 18 | + const CONTENT_TYPE = 'application/json'; |
|
| 19 | + const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json'; |
|
| 20 | + const USER_AGENT = 'scion.github-api'; |
|
| 21 | + |
|
| 22 | + /** Archive constants */ |
|
| 23 | + const ARCHIVE_TARBALL = 'tarball'; |
|
| 24 | + const ARCHIVE_ZIPBALL = 'zipball'; |
|
| 25 | + |
|
| 26 | + /** Authentication constants */ |
|
| 27 | + const OAUTH_AUTH = 0; |
|
| 28 | + const OAUTH2_HEADER_AUTH = 1; |
|
| 29 | + const OAUTH2_PARAMETERS_AUTH = 2; |
|
| 30 | + |
|
| 31 | + /** Branch constants */ |
|
| 32 | + const BRANCH_MASTER = 'master'; |
|
| 33 | + const BRANCH_DEVELOP = 'develop'; |
|
| 34 | + |
|
| 35 | + /** Direction constants */ |
|
| 36 | + const DIRECTION_ASC = 'asc'; |
|
| 37 | + const DIRECTION_DESC = 'desc'; |
|
| 38 | + |
|
| 39 | + /** Environment constants */ |
|
| 40 | + const ENVIRONMENT_PRODUCTION = 'production'; |
|
| 41 | + const ENVIRONMENT_STAGING = 'staging'; |
|
| 42 | + const ENVIRONMENT_QA = 'qa'; |
|
| 43 | + |
|
| 44 | + /** Events constants */ |
|
| 45 | + const EVENTS_PULL = 'pull'; |
|
| 46 | + const EVENTS_PULL_REQUEST = 'pull_request'; |
|
| 47 | + const EVENTS_PUSH = 'push'; |
|
| 48 | + |
|
| 49 | + /** Filter constants */ |
|
| 50 | + const FILTER_ALL = 'all'; |
|
| 51 | + const FILTER_ASSIGNED = 'assigned'; |
|
| 52 | + const FILTER_CREATED = 'created'; |
|
| 53 | + const FILTER_MENTIONED = 'mentioned'; |
|
| 54 | + const FILTER_SUBSCRIBED = 'subscribed'; |
|
| 55 | + |
|
| 56 | + /** Media types constants */ |
|
| 57 | + const MEDIA_TYPE_JSON = 'json'; |
|
| 58 | + const MEDIA_TYPE_RAW = 'raw'; |
|
| 59 | + const MEDIA_TYPE_FULL = 'full'; |
|
| 60 | + const MEDIA_TYPE_TEXT = 'text'; |
|
| 61 | + |
|
| 62 | + /** Modes constants */ |
|
| 63 | + const MODE_MARKDOWN = 'markdown'; |
|
| 64 | + const MODE_GFM = 'gfm'; |
|
| 65 | + |
|
| 66 | + /** Permissions constants */ |
|
| 67 | + const PERMISSION_ADMIN = 'admin'; |
|
| 68 | + const PERMISSION_PULL = 'pull'; |
|
| 69 | + const PERMISSION_PUSH = 'push'; |
|
| 70 | + |
|
| 71 | + /** Sort constants */ |
|
| 72 | + const SORT_COMPLETENESS = 'completeness'; |
|
| 73 | + const SORT_CREATED = 'created'; |
|
| 74 | + const SORT_DUE_DATE = 'due_date'; |
|
| 75 | + const SORT_FULL_NAME = 'full_name'; |
|
| 76 | + const SORT_NEWEST = 'newest'; |
|
| 77 | + const SORT_OLDEST = 'oldest'; |
|
| 78 | + const SORT_PUSHED = 'pushed'; |
|
| 79 | + const SORT_STARGAZERS = 'stargazers'; |
|
| 80 | + const SORT_UPDATED = 'updated'; |
|
| 81 | + |
|
| 82 | + /** State constants */ |
|
| 83 | + const STATE_ACTIVE = 'active'; |
|
| 84 | + const STATE_ALL = 'all'; |
|
| 85 | + const STATE_CLOSED = 'closed'; |
|
| 86 | + const STATE_ERROR = 'error'; |
|
| 87 | + const STATE_FAILURE = 'failure'; |
|
| 88 | + const STATE_OPEN = 'open'; |
|
| 89 | + const STATE_PENDING = 'pending'; |
|
| 90 | + const STATE_SUCCESS = 'success'; |
|
| 91 | + |
|
| 92 | + /** Task constants */ |
|
| 93 | + const TASK_DEPLOY = 'deploy'; |
|
| 94 | + const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations'; |
|
| 95 | + |
|
| 96 | + /** Type constants */ |
|
| 97 | + const TYPE_ALL = 'all'; |
|
| 98 | + const TYPE_COMMENTS = 'comments'; |
|
| 99 | + const TYPE_GISTS = 'gists'; |
|
| 100 | + const TYPE_HOOKS = 'hooks'; |
|
| 101 | + const TYPE_ISSUES = 'issues'; |
|
| 102 | + const TYPE_MEMBER = 'member'; |
|
| 103 | + const TYPE_MILESTONES = 'milestones'; |
|
| 104 | + const TYPE_ORGS = 'orgs'; |
|
| 105 | + const TYPE_OWNER = 'owner'; |
|
| 106 | + const TYPE_PAGES = 'pages'; |
|
| 107 | + const TYPE_PUBLIC = 'public'; |
|
| 108 | + const TYPE_PULLS = 'pulls'; |
|
| 109 | + const TYPE_PRIVATE = 'private'; |
|
| 110 | + const TYPE_REPOS = 'repos'; |
|
| 111 | + const TYPE_USERS = 'users'; |
|
| 112 | + |
|
| 113 | + /** Properties */ |
|
| 114 | + protected $accept = self::DEFAULT_ACCEPT; |
|
| 115 | + protected $apiUrl = self::API_URL; |
|
| 116 | + protected $authentication = self::OAUTH_AUTH; |
|
| 117 | + protected $clientId; |
|
| 118 | + protected $clientSecret; |
|
| 119 | + protected $contentType = self::CONTENT_TYPE; |
|
| 120 | + protected $failure; |
|
| 121 | + protected $headers = []; |
|
| 122 | + protected $httpAuth = ['username' => '', 'password' => '']; |
|
| 123 | + protected $success; |
|
| 124 | + protected $timeout = 240; |
|
| 125 | + protected $token = ''; |
|
| 126 | + protected $request; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Constructor |
|
| 130 | + */ |
|
| 131 | + public function __construct() |
|
| 132 | + { |
|
| 133 | + $this->request = Request::createFromGlobals(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Get request |
|
| 138 | + * |
|
| 139 | + * @return Request |
|
| 140 | + */ |
|
| 141 | + public function getRequest(): Request |
|
| 142 | + { |
|
| 143 | + return $this->request; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Get accept |
|
| 148 | + * |
|
| 149 | + * @return mixed |
|
| 150 | + */ |
|
| 151 | + public function getAccept() |
|
| 152 | + { |
|
| 153 | + return $this->accept; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Set accept |
|
| 158 | + * |
|
| 159 | + * @param array|string $accept |
|
| 160 | + * |
|
| 161 | + * @return AbstractApi |
|
| 162 | + */ |
|
| 163 | + public function setAccept($accept): AbstractApi |
|
| 164 | + { |
|
| 165 | + $this->accept = $accept; |
|
| 166 | + |
|
| 167 | + return $this; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Get authentication |
|
| 172 | + * |
|
| 173 | + * @return int |
|
| 174 | + */ |
|
| 175 | + public function getAuthentication(): int |
|
| 176 | + { |
|
| 177 | + return $this->authentication; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Set authentication |
|
| 182 | + * |
|
| 183 | + * @param int $authentication |
|
| 184 | + * |
|
| 185 | + * @return AbstractApi |
|
| 186 | + */ |
|
| 187 | + public function setAuthentication(int $authentication): AbstractApi |
|
| 188 | + { |
|
| 189 | + $this->authentication = $authentication; |
|
| 190 | + |
|
| 191 | + return $this; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Get apiUrl |
|
| 196 | + * |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function getApiUrl(): string |
|
| 200 | + { |
|
| 201 | + return $this->apiUrl; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Set apiUrl |
|
| 206 | + * |
|
| 207 | + * @param mixed $apiUrl |
|
| 208 | + * |
|
| 209 | + * @return AbstractApi |
|
| 210 | + */ |
|
| 211 | + public function setApiUrl($apiUrl): AbstractApi |
|
| 212 | + { |
|
| 213 | + $this->apiUrl = $apiUrl; |
|
| 214 | + |
|
| 215 | + return $this; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Get clientId |
|
| 220 | + * |
|
| 221 | + * @return null|int |
|
| 222 | + */ |
|
| 223 | + public function getClientId() |
|
| 224 | + { |
|
| 225 | + return $this->clientId; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Set clientId |
|
| 230 | + * |
|
| 231 | + * @param mixed $clientId |
|
| 232 | + * |
|
| 233 | + * @return AbstractApi |
|
| 234 | + */ |
|
| 235 | + public function setClientId($clientId): AbstractApi |
|
| 236 | + { |
|
| 237 | + $this->clientId = $clientId; |
|
| 238 | + |
|
| 239 | + return $this; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Get clientSecret |
|
| 244 | + * |
|
| 245 | + * @return null|string |
|
| 246 | + */ |
|
| 247 | + public function getClientSecret() |
|
| 248 | + { |
|
| 249 | + return $this->clientSecret; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Set clientSecret |
|
| 254 | + * |
|
| 255 | + * @param mixed $clientSecret |
|
| 256 | + * |
|
| 257 | + * @return AbstractApi |
|
| 258 | + */ |
|
| 259 | + public function setClientSecret($clientSecret): AbstractApi |
|
| 260 | + { |
|
| 261 | + $this->clientSecret = $clientSecret; |
|
| 262 | + |
|
| 263 | + return $this; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Get httpAuth |
|
| 268 | + * |
|
| 269 | + * @return array |
|
| 270 | + */ |
|
| 271 | + public function getHttpAuth(): array |
|
| 272 | + { |
|
| 273 | + return $this->httpAuth; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Set httpAuth |
|
| 278 | + * |
|
| 279 | + * @param string $username |
|
| 280 | + * @param string $password |
|
| 281 | + * |
|
| 282 | + * @return AbstractApi |
|
| 283 | + */ |
|
| 284 | + public function setHttpAuth(string $username, string $password = ''): AbstractApi |
|
| 285 | + { |
|
| 286 | + $this->httpAuth['username'] = $username; |
|
| 287 | + $this->httpAuth['password'] = $password; |
|
| 288 | + |
|
| 289 | + return $this; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Get token |
|
| 294 | + * |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 297 | + public function getToken(): string |
|
| 298 | + { |
|
| 299 | + return $this->token; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Set token |
|
| 304 | + * |
|
| 305 | + * @param string $token |
|
| 306 | + * @param int $authentication |
|
| 307 | + * |
|
| 308 | + * @return AbstractApi |
|
| 309 | + */ |
|
| 310 | + public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi |
|
| 311 | + { |
|
| 312 | + $this->token = $token; |
|
| 313 | + $this->setAuthentication($authentication); |
|
| 314 | + |
|
| 315 | + return $this; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Get timeout |
|
| 320 | + * |
|
| 321 | + * @return int |
|
| 322 | + */ |
|
| 323 | + public function getTimeout(): int |
|
| 324 | + { |
|
| 325 | + return $this->timeout; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Set timeout |
|
| 330 | + * |
|
| 331 | + * @param int $timeout |
|
| 332 | + * |
|
| 333 | + * @return AbstractApi |
|
| 334 | + */ |
|
| 335 | + public function setTimeout(int $timeout): AbstractApi |
|
| 336 | + { |
|
| 337 | + $this->timeout = $timeout; |
|
| 338 | + |
|
| 339 | + return $this; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Get contentType |
|
| 344 | + * |
|
| 345 | + * @return string |
|
| 346 | + */ |
|
| 347 | + public function getContentType(): string |
|
| 348 | + { |
|
| 349 | + return $this->contentType; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Set contentType |
|
| 354 | + * |
|
| 355 | + * @param string $contentType |
|
| 356 | + * |
|
| 357 | + * @return AbstractApi |
|
| 358 | + */ |
|
| 359 | + public function setContentType(string $contentType): AbstractApi |
|
| 360 | + { |
|
| 361 | + $this->contentType = $contentType; |
|
| 362 | + |
|
| 363 | + return $this; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Get headers |
|
| 368 | + * |
|
| 369 | + * @return array |
|
| 370 | + */ |
|
| 371 | + public function getHeaders(): array |
|
| 372 | + { |
|
| 373 | + return $this->headers; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Curl request |
|
| 378 | + * |
|
| 379 | + * @param string $url |
|
| 380 | + * @param string $method |
|
| 381 | + * @param array $postFields |
|
| 382 | + * @param null|string $apiUrl |
|
| 383 | + * |
|
| 384 | + * @return array |
|
| 385 | + */ |
|
| 386 | + public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [], |
|
| 387 | + string $apiUrl = null): array |
|
| 388 | + { |
|
| 389 | + /** Building url */ |
|
| 390 | + if (null === $apiUrl) { |
|
| 391 | + $apiUrl = $this->getApiUrl(); |
|
| 392 | + } |
|
| 393 | + $url = $apiUrl . $url; |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * OAuth2 Key/Secret authentication |
|
| 397 | + * |
|
| 398 | + * @see https://developer.github.com/v3/#oauth2-keysecret |
|
| 399 | + */ |
|
| 400 | + if (null !== $this->getClientId() && null !== $this->getClientSecret()) { |
|
| 401 | + $url .= (strstr($url, '?') !== false ? '&' : '?'); |
|
| 402 | + $url .= http_build_query(['client_id' => $this->getClientId(), |
|
| 403 | + 'client_secret' => $this->getClientSecret() |
|
| 404 | + ]); |
|
| 405 | + } /** |
|
| 406 | + * Basic authentication via OAuth2 Token (sent as a parameter) |
|
| 407 | + * |
|
| 408 | + * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter |
|
| 409 | + */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) { |
|
| 410 | + $url .= http_build_query(['access_token' => $this->getToken()]); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** Call curl */ |
|
| 414 | + $curl = new CurlClient(); |
|
| 415 | + $curl->setOption([ |
|
| 416 | + CURLOPT_USERAGENT => self::USER_AGENT, |
|
| 417 | + CURLOPT_TIMEOUT => $this->getTimeout(), |
|
| 418 | + CURLOPT_HEADER => false, // Use $client->getHeaders() to get full header |
|
| 419 | + CURLOPT_FOLLOWLOCATION => true, |
|
| 420 | + CURLOPT_HTTPHEADER => [ |
|
| 421 | + 'Accept: ' . $this->getAccept(), |
|
| 422 | + 'Content-Type: ' . $this->getContentType() |
|
| 423 | + ], |
|
| 424 | + CURLOPT_URL => $url |
|
| 425 | + ]); |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Basic authentication via username and Password |
|
| 429 | + * |
|
| 430 | + * @see https://developer.github.com/v3/auth/#via-username-and-password |
|
| 431 | + */ |
|
| 432 | + if (!empty($this->getHttpAuth())) { |
|
| 433 | + if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) { |
|
| 434 | + $curl->setOption([ |
|
| 435 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 436 | + CURLOPT_USERPWD => $this->getHttpAuth()['username'] |
|
| 437 | + ]); |
|
| 438 | + } else { |
|
| 439 | + $curl->setOption([ |
|
| 440 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 441 | + CURLOPT_USERPWD => sprintf('%s:%s', $this->getHttpAuth()['username'], |
|
| 442 | + $this->getHttpAuth()['password']) |
|
| 443 | + ]); |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) { |
|
| 448 | + /** |
|
| 449 | + * Basic authentication via OAuth token |
|
| 450 | + * |
|
| 451 | + * @see https://developer.github.com/v3/auth/#via-oauth-tokens |
|
| 452 | + **/ |
|
| 453 | + if ($this->getAuthentication() === self::OAUTH_AUTH) { |
|
| 454 | + $curl->setOption([ |
|
| 455 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 456 | + CURLOPT_USERPWD => sprintf('%s:x-oauth-basic', $this->getToken()) |
|
| 457 | + ]); |
|
| 458 | + } /** |
|
| 459 | + * Basic authentication via OAuth2 Token (sent in a header) |
|
| 460 | + * |
|
| 461 | + * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header |
|
| 462 | + */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) { |
|
| 463 | + $curl->setOption([ |
|
| 464 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 465 | + CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())] |
|
| 466 | + ]); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** Methods */ |
|
| 471 | + switch ($method) { |
|
| 472 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */ |
|
| 473 | + case Request::METHOD_DELETE: |
|
| 474 | + /** @see http://tools.ietf.org/html/rfc5789 */ |
|
| 475 | + case Request::METHOD_PATCH: |
|
| 476 | + $curl->setOption([ |
|
| 477 | + CURLOPT_CUSTOMREQUEST => $method, |
|
| 478 | + CURLOPT_POST => true, |
|
| 479 | + CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 480 | + ]); |
|
| 481 | + break; |
|
| 482 | + |
|
| 483 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */ |
|
| 484 | + case Request::METHOD_GET: |
|
| 485 | + $curl->setOption(CURLOPT_HTTPGET, true); |
|
| 486 | + break; |
|
| 487 | + |
|
| 488 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */ |
|
| 489 | + case Request::METHOD_HEAD: |
|
| 490 | + $curl->setOption([ |
|
| 491 | + CURLOPT_CUSTOMREQUEST => $method, |
|
| 492 | + CURLOPT_NOBODY => true |
|
| 493 | + ]); |
|
| 494 | + break; |
|
| 495 | + |
|
| 496 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */ |
|
| 497 | + case Request::METHOD_POST: |
|
| 498 | + $curl->setOption([ |
|
| 499 | + CURLOPT_POST => true, |
|
| 500 | + CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 501 | + ]); |
|
| 502 | + break; |
|
| 503 | + |
|
| 504 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */ |
|
| 505 | + case Request::METHOD_PUT: |
|
| 506 | + $curl->setOption([ |
|
| 507 | + CURLOPT_CUSTOMREQUEST => $method, |
|
| 508 | + CURLOPT_PUT => true, |
|
| 509 | + CURLOPT_HTTPHEADER => [ |
|
| 510 | + 'X-HTTP-Method-Override: PUT', |
|
| 511 | + 'Content-type: application/x-www-form-urlencoded' |
|
| 512 | + ] |
|
| 513 | + ]); |
|
| 514 | + break; |
|
| 515 | + |
|
| 516 | + default: |
|
| 517 | + break; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $curl->success(function (CurlClient $instance) { |
|
| 521 | + $this->headers = $instance->getHeaders(); |
|
| 522 | + $this->success = $instance->getResponse(); |
|
| 523 | + $data = json_decode($this->success, true); |
|
| 524 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
| 525 | + $this->success = $data; |
|
| 526 | + } |
|
| 527 | + }); |
|
| 528 | + $curl->error(function (CurlClient $instance) { |
|
| 529 | + $this->headers = $instance->getHeaders(); |
|
| 530 | + $this->failure = $instance->getResponse(); |
|
| 531 | + $data = json_decode($this->failure, true); |
|
| 532 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
| 533 | + $this->failure = $data; |
|
| 534 | + } |
|
| 535 | + }); |
|
| 536 | + $curl->perform(); |
|
| 537 | + |
|
| 538 | + return $this->success ?? $this->failure; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Return a formatted string. Modified version of sprintf using colon(:) |
|
| 543 | + * |
|
| 544 | + * @param string $string |
|
| 545 | + * @param array $params |
|
| 546 | + * |
|
| 547 | + * @return String |
|
| 548 | + * @throws Exception |
|
| 549 | + */ |
|
| 550 | + public function sprintf(string $string, ...$params): string |
|
| 551 | + { |
|
| 552 | + preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches); |
|
| 553 | + $matches = $matches[1]; |
|
| 554 | + |
|
| 555 | + if (count($matches)) { |
|
| 556 | + $tokens = []; |
|
| 557 | + $replaces = []; |
|
| 558 | + |
|
| 559 | + foreach ($matches as $key => $value) { |
|
| 560 | + if (count($params) > 1 || !is_array($params[0])) { |
|
| 561 | + if (!array_key_exists($key, $params)) { |
|
| 562 | + throw new Exception('Too few arguments, missing argument: ' . $key); |
|
| 563 | + } |
|
| 564 | + $replaces[] = $params[$key]; |
|
| 565 | + } else { |
|
| 566 | + if (!array_key_exists($value, $params[0])) { |
|
| 567 | + throw new Exception('Missing array argument: ' . $key); |
|
| 568 | + } |
|
| 569 | + $replaces[] = $params[0][$value]; |
|
| 570 | + } |
|
| 571 | + $tokens[] = ':' . $value; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + $string = str_replace($tokens, $replaces, $string); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return $string; |
|
| 578 | + } |
|
| 579 | 579 | } |
| 580 | 580 | \ No newline at end of file |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | break; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - $curl->success(function (CurlClient $instance) { |
|
| 520 | + $curl->success(function(CurlClient $instance) { |
|
| 521 | 521 | $this->headers = $instance->getHeaders(); |
| 522 | 522 | $this->success = $instance->getResponse(); |
| 523 | 523 | $data = json_decode($this->success, true); |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | $this->success = $data; |
| 526 | 526 | } |
| 527 | 527 | }); |
| 528 | - $curl->error(function (CurlClient $instance) { |
|
| 528 | + $curl->error(function(CurlClient $instance) { |
|
| 529 | 529 | $this->headers = $instance->getHeaders(); |
| 530 | 530 | $this->failure = $instance->getResponse(); |
| 531 | 531 | $data = json_decode($this->failure, true); |
@@ -12,35 +12,35 @@ |
||
| 12 | 12 | class Client extends AbstractApi |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Receiver constants */ |
|
| 16 | - const ACTIVITY = 'Activity'; |
|
| 17 | - const ENTERPRISE = 'Enterprise'; |
|
| 18 | - const GISTS = 'Gists'; |
|
| 19 | - const GIT_DATA = 'GitData'; |
|
| 20 | - const ISSUES = 'Issues'; |
|
| 21 | - const MISCELLANEOUS = 'Miscellaneous'; |
|
| 22 | - const ORGANIZATIONS = 'Organizations'; |
|
| 23 | - const PULL_REQUESTS = 'PullRequests'; |
|
| 24 | - const REPOSITORIES = 'Repositories'; |
|
| 25 | - const SEARCH = 'Search'; |
|
| 26 | - const USERS = 'Users'; |
|
| 15 | + /** Receiver constants */ |
|
| 16 | + const ACTIVITY = 'Activity'; |
|
| 17 | + const ENTERPRISE = 'Enterprise'; |
|
| 18 | + const GISTS = 'Gists'; |
|
| 19 | + const GIT_DATA = 'GitData'; |
|
| 20 | + const ISSUES = 'Issues'; |
|
| 21 | + const MISCELLANEOUS = 'Miscellaneous'; |
|
| 22 | + const ORGANIZATIONS = 'Organizations'; |
|
| 23 | + const PULL_REQUESTS = 'PullRequests'; |
|
| 24 | + const REPOSITORIES = 'Repositories'; |
|
| 25 | + const SEARCH = 'Search'; |
|
| 26 | + const USERS = 'Users'; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Returns receiver object |
|
| 30 | - * |
|
| 31 | - * @param string $receiver |
|
| 32 | - * |
|
| 33 | - * @return null|AbstractReceiver |
|
| 34 | - */ |
|
| 35 | - public function getReceiver(string $receiver) |
|
| 36 | - { |
|
| 37 | - $class = (string)$this->sprintf(':namespace\Receiver\:receiver', __NAMESPACE__, $receiver); |
|
| 28 | + /** |
|
| 29 | + * Returns receiver object |
|
| 30 | + * |
|
| 31 | + * @param string $receiver |
|
| 32 | + * |
|
| 33 | + * @return null|AbstractReceiver |
|
| 34 | + */ |
|
| 35 | + public function getReceiver(string $receiver) |
|
| 36 | + { |
|
| 37 | + $class = (string)$this->sprintf(':namespace\Receiver\:receiver', __NAMESPACE__, $receiver); |
|
| 38 | 38 | |
| 39 | - if (class_exists($class)) { |
|
| 40 | - return new $class($this); |
|
| 41 | - } |
|
| 39 | + if (class_exists($class)) { |
|
| 40 | + return new $class($this); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return null; |
|
| 44 | - } |
|
| 43 | + return null; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |
@@ -11,110 +11,110 @@ |
||
| 11 | 11 | abstract class AbstractReceiver |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** Protected properties */ |
|
| 15 | - protected $api; |
|
| 16 | - protected $owner = ''; |
|
| 17 | - protected $repo = ''; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Constructor |
|
| 21 | - * |
|
| 22 | - * @param AbstractApi $api |
|
| 23 | - */ |
|
| 24 | - public function __construct(AbstractApi $api) |
|
| 25 | - { |
|
| 26 | - $this->setApi($api); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Get api |
|
| 31 | - * |
|
| 32 | - * @return AbstractApi |
|
| 33 | - */ |
|
| 34 | - public function getApi(): AbstractApi |
|
| 35 | - { |
|
| 36 | - return $this->api; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Set api |
|
| 41 | - * |
|
| 42 | - * @param AbstractApi $api |
|
| 43 | - * |
|
| 44 | - * @return AbstractReceiver |
|
| 45 | - */ |
|
| 46 | - public function setApi(AbstractApi $api): AbstractReceiver |
|
| 47 | - { |
|
| 48 | - $this->api = $api; |
|
| 49 | - |
|
| 50 | - return $this; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Get owner |
|
| 55 | - * |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function getOwner(): string |
|
| 59 | - { |
|
| 60 | - return $this->owner; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Set owner |
|
| 65 | - * |
|
| 66 | - * @param string $owner |
|
| 67 | - * |
|
| 68 | - * @return AbstractReceiver |
|
| 69 | - */ |
|
| 70 | - public function setOwner(string $owner): AbstractReceiver |
|
| 71 | - { |
|
| 72 | - $this->owner = $owner; |
|
| 73 | - |
|
| 74 | - return $this; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get repository |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getRepo(): string |
|
| 83 | - { |
|
| 84 | - return $this->repo; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Set repository |
|
| 89 | - * |
|
| 90 | - * @param string $repo |
|
| 91 | - * |
|
| 92 | - * @return AbstractReceiver |
|
| 93 | - */ |
|
| 94 | - public function setRepo(string $repo): AbstractReceiver |
|
| 95 | - { |
|
| 96 | - $this->repo = $repo; |
|
| 97 | - |
|
| 98 | - return $this; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Get a sub-receiver |
|
| 103 | - * |
|
| 104 | - * @param string $name |
|
| 105 | - * |
|
| 106 | - * @return null|object |
|
| 107 | - */ |
|
| 108 | - public function getReceiver(string $name) |
|
| 109 | - { |
|
| 110 | - $classPath = explode('\\', get_called_class()); |
|
| 111 | - $class = (string)$this->getApi() |
|
| 112 | - ->sprintf(':namespace\:class\:method', __NAMESPACE__, end($classPath), $name); |
|
| 113 | - |
|
| 114 | - if (class_exists($class)) { |
|
| 115 | - return new $class($this); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return null; |
|
| 119 | - } |
|
| 14 | + /** Protected properties */ |
|
| 15 | + protected $api; |
|
| 16 | + protected $owner = ''; |
|
| 17 | + protected $repo = ''; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Constructor |
|
| 21 | + * |
|
| 22 | + * @param AbstractApi $api |
|
| 23 | + */ |
|
| 24 | + public function __construct(AbstractApi $api) |
|
| 25 | + { |
|
| 26 | + $this->setApi($api); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Get api |
|
| 31 | + * |
|
| 32 | + * @return AbstractApi |
|
| 33 | + */ |
|
| 34 | + public function getApi(): AbstractApi |
|
| 35 | + { |
|
| 36 | + return $this->api; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Set api |
|
| 41 | + * |
|
| 42 | + * @param AbstractApi $api |
|
| 43 | + * |
|
| 44 | + * @return AbstractReceiver |
|
| 45 | + */ |
|
| 46 | + public function setApi(AbstractApi $api): AbstractReceiver |
|
| 47 | + { |
|
| 48 | + $this->api = $api; |
|
| 49 | + |
|
| 50 | + return $this; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Get owner |
|
| 55 | + * |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function getOwner(): string |
|
| 59 | + { |
|
| 60 | + return $this->owner; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Set owner |
|
| 65 | + * |
|
| 66 | + * @param string $owner |
|
| 67 | + * |
|
| 68 | + * @return AbstractReceiver |
|
| 69 | + */ |
|
| 70 | + public function setOwner(string $owner): AbstractReceiver |
|
| 71 | + { |
|
| 72 | + $this->owner = $owner; |
|
| 73 | + |
|
| 74 | + return $this; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get repository |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getRepo(): string |
|
| 83 | + { |
|
| 84 | + return $this->repo; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Set repository |
|
| 89 | + * |
|
| 90 | + * @param string $repo |
|
| 91 | + * |
|
| 92 | + * @return AbstractReceiver |
|
| 93 | + */ |
|
| 94 | + public function setRepo(string $repo): AbstractReceiver |
|
| 95 | + { |
|
| 96 | + $this->repo = $repo; |
|
| 97 | + |
|
| 98 | + return $this; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Get a sub-receiver |
|
| 103 | + * |
|
| 104 | + * @param string $name |
|
| 105 | + * |
|
| 106 | + * @return null|object |
|
| 107 | + */ |
|
| 108 | + public function getReceiver(string $name) |
|
| 109 | + { |
|
| 110 | + $classPath = explode('\\', get_called_class()); |
|
| 111 | + $class = (string)$this->getApi() |
|
| 112 | + ->sprintf(':namespace\:class\:method', __NAMESPACE__, end($classPath), $name); |
|
| 113 | + |
|
| 114 | + if (class_exists($class)) { |
|
| 115 | + return new $class($this); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return null; |
|
| 119 | + } |
|
| 120 | 120 | } |
| 121 | 121 | \ No newline at end of file |
@@ -12,81 +12,81 @@ |
||
| 12 | 12 | class Users extends AbstractReceiver |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Available sub-Receiver */ |
|
| 16 | - const EMAILS = 'Emails'; |
|
| 17 | - const FOLLOWERS = 'Followers'; |
|
| 18 | - const PUBLIC_KEYS = 'PublicKeys'; |
|
| 15 | + /** Available sub-Receiver */ |
|
| 16 | + const EMAILS = 'Emails'; |
|
| 17 | + const FOLLOWERS = 'Followers'; |
|
| 18 | + const PUBLIC_KEYS = 'PublicKeys'; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Get a single user |
|
| 22 | - * |
|
| 23 | - * @link https://developer.github.com/v3/users/#get-a-single-user |
|
| 24 | - * |
|
| 25 | - * @param string $username |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - * @throws \Exception |
|
| 29 | - */ |
|
| 30 | - public function getSingleUser(string $username): array |
|
| 31 | - { |
|
| 32 | - return $this->getApi()->request($this->getApi()->sprintf('/users/:username', $username)); |
|
| 33 | - } |
|
| 20 | + /** |
|
| 21 | + * Get a single user |
|
| 22 | + * |
|
| 23 | + * @link https://developer.github.com/v3/users/#get-a-single-user |
|
| 24 | + * |
|
| 25 | + * @param string $username |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + * @throws \Exception |
|
| 29 | + */ |
|
| 30 | + public function getSingleUser(string $username): array |
|
| 31 | + { |
|
| 32 | + return $this->getApi()->request($this->getApi()->sprintf('/users/:username', $username)); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get the authenticated user |
|
| 37 | - * |
|
| 38 | - * @link https://developer.github.com/v3/users/#get-the-authenticated-user |
|
| 39 | - * @return array |
|
| 40 | - * @throws \Exception |
|
| 41 | - */ |
|
| 42 | - public function getUser(): array |
|
| 43 | - { |
|
| 44 | - return $this->getApi()->request($this->getApi()->sprintf('/user')); |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * Get the authenticated user |
|
| 37 | + * |
|
| 38 | + * @link https://developer.github.com/v3/users/#get-the-authenticated-user |
|
| 39 | + * @return array |
|
| 40 | + * @throws \Exception |
|
| 41 | + */ |
|
| 42 | + public function getUser(): array |
|
| 43 | + { |
|
| 44 | + return $this->getApi()->request($this->getApi()->sprintf('/user')); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Update the authenticated user |
|
| 49 | - * |
|
| 50 | - * @link https://developer.github.com/v3/users/#update-the-authenticated-user |
|
| 51 | - * |
|
| 52 | - * @param string $name |
|
| 53 | - * @param string $email |
|
| 54 | - * @param string $blog |
|
| 55 | - * @param string $company |
|
| 56 | - * @param string $location |
|
| 57 | - * @param bool $hireable |
|
| 58 | - * @param string $bio |
|
| 59 | - * |
|
| 60 | - * @return array |
|
| 61 | - * @throws \Exception |
|
| 62 | - */ |
|
| 63 | - public function updateUser(string $name = null, string $email = null, string $blog = null, string $company = null, |
|
| 64 | - string $location = null, bool $hireable = false, string $bio = null): array |
|
| 65 | - { |
|
| 66 | - return $this->getApi()->request($this->getApi()->sprintf('/user'), Request::METHOD_PATCH, [ |
|
| 67 | - 'name' => $name, |
|
| 68 | - 'email' => $email, |
|
| 69 | - 'blog' => $blog, |
|
| 70 | - 'company' => $company, |
|
| 71 | - 'location' => $location, |
|
| 72 | - 'hireable' => $hireable, |
|
| 73 | - 'bio' => $bio |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 47 | + /** |
|
| 48 | + * Update the authenticated user |
|
| 49 | + * |
|
| 50 | + * @link https://developer.github.com/v3/users/#update-the-authenticated-user |
|
| 51 | + * |
|
| 52 | + * @param string $name |
|
| 53 | + * @param string $email |
|
| 54 | + * @param string $blog |
|
| 55 | + * @param string $company |
|
| 56 | + * @param string $location |
|
| 57 | + * @param bool $hireable |
|
| 58 | + * @param string $bio |
|
| 59 | + * |
|
| 60 | + * @return array |
|
| 61 | + * @throws \Exception |
|
| 62 | + */ |
|
| 63 | + public function updateUser(string $name = null, string $email = null, string $blog = null, string $company = null, |
|
| 64 | + string $location = null, bool $hireable = false, string $bio = null): array |
|
| 65 | + { |
|
| 66 | + return $this->getApi()->request($this->getApi()->sprintf('/user'), Request::METHOD_PATCH, [ |
|
| 67 | + 'name' => $name, |
|
| 68 | + 'email' => $email, |
|
| 69 | + 'blog' => $blog, |
|
| 70 | + 'company' => $company, |
|
| 71 | + 'location' => $location, |
|
| 72 | + 'hireable' => $hireable, |
|
| 73 | + 'bio' => $bio |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Get all users |
|
| 79 | - * |
|
| 80 | - * @link https://developer.github.com/v3/users/#get-all-users |
|
| 81 | - * |
|
| 82 | - * @param string $since |
|
| 83 | - * |
|
| 84 | - * @return array |
|
| 85 | - * @throws \Exception |
|
| 86 | - */ |
|
| 87 | - public function getAllUsers(string $since = null): array |
|
| 88 | - { |
|
| 89 | - return $this->getApi()->request($this->getApi() |
|
| 90 | - ->sprintf('/users?:args', http_build_query(['since' => $since]))); |
|
| 91 | - } |
|
| 77 | + /** |
|
| 78 | + * Get all users |
|
| 79 | + * |
|
| 80 | + * @link https://developer.github.com/v3/users/#get-all-users |
|
| 81 | + * |
|
| 82 | + * @param string $since |
|
| 83 | + * |
|
| 84 | + * @return array |
|
| 85 | + * @throws \Exception |
|
| 86 | + */ |
|
| 87 | + public function getAllUsers(string $since = null): array |
|
| 88 | + { |
|
| 89 | + return $this->getApi()->request($this->getApi() |
|
| 90 | + ->sprintf('/users?:args', http_build_query(['since' => $since]))); |
|
| 91 | + } |
|
| 92 | 92 | } |
| 93 | 93 | \ No newline at end of file |
@@ -12,83 +12,83 @@ |
||
| 12 | 12 | class Search extends AbstractReceiver |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Available sub-Receiver */ |
|
| 16 | - const REPOSITORIES = 'Repositories'; |
|
| 17 | - const CODE = 'Code'; |
|
| 18 | - const ISSUES = 'Issues'; |
|
| 19 | - const USERS = 'Users'; |
|
| 20 | - const LEGACY_SEARCH = 'LegacySearch'; |
|
| 15 | + /** Available sub-Receiver */ |
|
| 16 | + const REPOSITORIES = 'Repositories'; |
|
| 17 | + const CODE = 'Code'; |
|
| 18 | + const ISSUES = 'Issues'; |
|
| 19 | + const USERS = 'Users'; |
|
| 20 | + const LEGACY_SEARCH = 'LegacySearch'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Search repositories |
|
| 24 | - * |
|
| 25 | - * @link https://developer.github.com/v3/search/#search-repositories |
|
| 26 | - * |
|
| 27 | - * @param string $q |
|
| 28 | - * @param string $sort |
|
| 29 | - * @param string $order |
|
| 30 | - * |
|
| 31 | - * @return array |
|
| 32 | - * @throws \Exception |
|
| 33 | - */ |
|
| 34 | - public function searchRepositories(string $q, string $sort = null, |
|
| 35 | - string $order = AbstractApi::DIRECTION_DESC): array |
|
| 36 | - { |
|
| 37 | - return $this->getApi()->request($this->getApi()->sprintf('/search/repositories?:args', |
|
| 38 | - http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 39 | - } |
|
| 22 | + /** |
|
| 23 | + * Search repositories |
|
| 24 | + * |
|
| 25 | + * @link https://developer.github.com/v3/search/#search-repositories |
|
| 26 | + * |
|
| 27 | + * @param string $q |
|
| 28 | + * @param string $sort |
|
| 29 | + * @param string $order |
|
| 30 | + * |
|
| 31 | + * @return array |
|
| 32 | + * @throws \Exception |
|
| 33 | + */ |
|
| 34 | + public function searchRepositories(string $q, string $sort = null, |
|
| 35 | + string $order = AbstractApi::DIRECTION_DESC): array |
|
| 36 | + { |
|
| 37 | + return $this->getApi()->request($this->getApi()->sprintf('/search/repositories?:args', |
|
| 38 | + http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Search code |
|
| 43 | - * |
|
| 44 | - * @link https://developer.github.com/v3/search/#search-code |
|
| 45 | - * |
|
| 46 | - * @param string $q |
|
| 47 | - * @param string $sort |
|
| 48 | - * @param string $order |
|
| 49 | - * |
|
| 50 | - * @return array |
|
| 51 | - * @throws \Exception |
|
| 52 | - */ |
|
| 53 | - public function searchCode(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array |
|
| 54 | - { |
|
| 55 | - return $this->getApi()->request($this->getApi()->sprintf('/search/code?:args', |
|
| 56 | - http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 57 | - } |
|
| 41 | + /** |
|
| 42 | + * Search code |
|
| 43 | + * |
|
| 44 | + * @link https://developer.github.com/v3/search/#search-code |
|
| 45 | + * |
|
| 46 | + * @param string $q |
|
| 47 | + * @param string $sort |
|
| 48 | + * @param string $order |
|
| 49 | + * |
|
| 50 | + * @return array |
|
| 51 | + * @throws \Exception |
|
| 52 | + */ |
|
| 53 | + public function searchCode(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array |
|
| 54 | + { |
|
| 55 | + return $this->getApi()->request($this->getApi()->sprintf('/search/code?:args', |
|
| 56 | + http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Search issues |
|
| 61 | - * |
|
| 62 | - * @link https://developer.github.com/v3/search/#search-issues |
|
| 63 | - * |
|
| 64 | - * @param string $q |
|
| 65 | - * @param string $sort |
|
| 66 | - * @param string $order |
|
| 67 | - * |
|
| 68 | - * @return array |
|
| 69 | - * @throws \Exception |
|
| 70 | - */ |
|
| 71 | - public function searchIssues(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array |
|
| 72 | - { |
|
| 73 | - return $this->getApi()->request($this->getApi()->sprintf('/search/issues?:args', |
|
| 74 | - http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 75 | - } |
|
| 59 | + /** |
|
| 60 | + * Search issues |
|
| 61 | + * |
|
| 62 | + * @link https://developer.github.com/v3/search/#search-issues |
|
| 63 | + * |
|
| 64 | + * @param string $q |
|
| 65 | + * @param string $sort |
|
| 66 | + * @param string $order |
|
| 67 | + * |
|
| 68 | + * @return array |
|
| 69 | + * @throws \Exception |
|
| 70 | + */ |
|
| 71 | + public function searchIssues(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array |
|
| 72 | + { |
|
| 73 | + return $this->getApi()->request($this->getApi()->sprintf('/search/issues?:args', |
|
| 74 | + http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Search users |
|
| 79 | - * |
|
| 80 | - * @link https://developer.github.com/v3/search/#search-users |
|
| 81 | - * |
|
| 82 | - * @param string $q |
|
| 83 | - * @param string $sort |
|
| 84 | - * @param string $order |
|
| 85 | - * |
|
| 86 | - * @return array |
|
| 87 | - * @throws \Exception |
|
| 88 | - */ |
|
| 89 | - public function searchUsers(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array |
|
| 90 | - { |
|
| 91 | - return $this->getApi()->request($this->getApi()->sprintf('/search/users?:args', |
|
| 92 | - http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 93 | - } |
|
| 77 | + /** |
|
| 78 | + * Search users |
|
| 79 | + * |
|
| 80 | + * @link https://developer.github.com/v3/search/#search-users |
|
| 81 | + * |
|
| 82 | + * @param string $q |
|
| 83 | + * @param string $sort |
|
| 84 | + * @param string $order |
|
| 85 | + * |
|
| 86 | + * @return array |
|
| 87 | + * @throws \Exception |
|
| 88 | + */ |
|
| 89 | + public function searchUsers(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array |
|
| 90 | + { |
|
| 91 | + return $this->getApi()->request($this->getApi()->sprintf('/search/users?:args', |
|
| 92 | + http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order]))); |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | \ No newline at end of file |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | class Enterprise extends AbstractReceiver |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Available sub-Receiver */ |
|
| 16 | - const ADMIN_STATS = 'AdminStats'; |
|
| 17 | - const LDAP = 'Ldap'; |
|
| 18 | - const LICENSE = 'License'; |
|
| 19 | - const MANAGEMENT_CONSOLE = 'ManagementConsole'; |
|
| 20 | - const SEARCH_INDEXING = 'SearchIndexing'; |
|
| 15 | + /** Available sub-Receiver */ |
|
| 16 | + const ADMIN_STATS = 'AdminStats'; |
|
| 17 | + const LDAP = 'Ldap'; |
|
| 18 | + const LICENSE = 'License'; |
|
| 19 | + const MANAGEMENT_CONSOLE = 'ManagementConsole'; |
|
| 20 | + const SEARCH_INDEXING = 'SearchIndexing'; |
|
| 21 | 21 | } |
| 22 | 22 | \ No newline at end of file |
@@ -12,66 +12,66 @@ |
||
| 12 | 12 | abstract class AbstractUsers |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Properties */ |
|
| 16 | - protected $users; |
|
| 17 | - protected $api; |
|
| 15 | + /** Properties */ |
|
| 16 | + protected $users; |
|
| 17 | + protected $api; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Constructor |
|
| 21 | - * |
|
| 22 | - * @param Users $users |
|
| 23 | - */ |
|
| 24 | - public function __construct(Users $users) |
|
| 25 | - { |
|
| 26 | - $this->setUsers($users); |
|
| 27 | - $this->setApi($users->getApi()); |
|
| 28 | - } |
|
| 19 | + /** |
|
| 20 | + * Constructor |
|
| 21 | + * |
|
| 22 | + * @param Users $users |
|
| 23 | + */ |
|
| 24 | + public function __construct(Users $users) |
|
| 25 | + { |
|
| 26 | + $this->setUsers($users); |
|
| 27 | + $this->setApi($users->getApi()); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Get users |
|
| 32 | - * |
|
| 33 | - * @return Users |
|
| 34 | - */ |
|
| 35 | - public function getUsers(): Users |
|
| 36 | - { |
|
| 37 | - return $this->users; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Get users |
|
| 32 | + * |
|
| 33 | + * @return Users |
|
| 34 | + */ |
|
| 35 | + public function getUsers(): Users |
|
| 36 | + { |
|
| 37 | + return $this->users; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Set users |
|
| 42 | - * |
|
| 43 | - * @param Users $users |
|
| 44 | - * |
|
| 45 | - * @return AbstractUsers |
|
| 46 | - */ |
|
| 47 | - public function setUsers(Users $users): AbstractUsers |
|
| 48 | - { |
|
| 49 | - $this->users = $users; |
|
| 40 | + /** |
|
| 41 | + * Set users |
|
| 42 | + * |
|
| 43 | + * @param Users $users |
|
| 44 | + * |
|
| 45 | + * @return AbstractUsers |
|
| 46 | + */ |
|
| 47 | + public function setUsers(Users $users): AbstractUsers |
|
| 48 | + { |
|
| 49 | + $this->users = $users; |
|
| 50 | 50 | |
| 51 | - return $this; |
|
| 52 | - } |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get api |
|
| 56 | - * |
|
| 57 | - * @return AbstractApi |
|
| 58 | - */ |
|
| 59 | - public function getApi(): AbstractApi |
|
| 60 | - { |
|
| 61 | - return $this->api; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Get api |
|
| 56 | + * |
|
| 57 | + * @return AbstractApi |
|
| 58 | + */ |
|
| 59 | + public function getApi(): AbstractApi |
|
| 60 | + { |
|
| 61 | + return $this->api; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Set api |
|
| 66 | - * |
|
| 67 | - * @param AbstractApi $api |
|
| 68 | - * |
|
| 69 | - * @return AbstractUsers |
|
| 70 | - */ |
|
| 71 | - public function setApi(AbstractApi $api): AbstractUsers |
|
| 72 | - { |
|
| 73 | - $this->api = $api; |
|
| 64 | + /** |
|
| 65 | + * Set api |
|
| 66 | + * |
|
| 67 | + * @param AbstractApi $api |
|
| 68 | + * |
|
| 69 | + * @return AbstractUsers |
|
| 70 | + */ |
|
| 71 | + public function setApi(AbstractApi $api): AbstractUsers |
|
| 72 | + { |
|
| 73 | + $this->api = $api; |
|
| 74 | 74 | |
| 75 | - return $this; |
|
| 76 | - } |
|
| 75 | + return $this; |
|
| 76 | + } |
|
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -12,130 +12,130 @@ |
||
| 12 | 12 | class Followers extends AbstractUsers |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * List followers of a user |
|
| 17 | - * |
|
| 18 | - * @link https://developer.github.com/v3/users/followers/#list-followers-of-a-user |
|
| 19 | - * |
|
| 20 | - * @param null|string $username |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - * @throws \Exception |
|
| 24 | - */ |
|
| 25 | - public function listFollowers(string $username = null): array |
|
| 26 | - { |
|
| 27 | - $url = '/user/followers'; |
|
| 28 | - if (null !== $username) { |
|
| 29 | - $url = $this->getApi()->sprintf('/users/:username/followers', $username); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - return $this->getApi()->request($url); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * List users followed by another user |
|
| 37 | - * |
|
| 38 | - * @link https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user |
|
| 39 | - * |
|
| 40 | - * @param null|string $username |
|
| 41 | - * |
|
| 42 | - * @return array |
|
| 43 | - * @throws \Exception |
|
| 44 | - */ |
|
| 45 | - public function listUsersFollowedBy(string $username = null): array |
|
| 46 | - { |
|
| 47 | - $url = '/user/following'; |
|
| 48 | - if (null !== $username) { |
|
| 49 | - $url = $this->getApi()->sprintf('/users/:username/following', $username); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - return $this->getApi()->request($url); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Check if you are following a user |
|
| 57 | - * |
|
| 58 | - * @link https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user |
|
| 59 | - * |
|
| 60 | - * @param string $username |
|
| 61 | - * |
|
| 62 | - * @return bool |
|
| 63 | - * @throws \Exception |
|
| 64 | - */ |
|
| 65 | - public function checkFollowingUser(string $username): bool |
|
| 66 | - { |
|
| 67 | - $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username)); |
|
| 68 | - |
|
| 69 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 70 | - return true; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return false; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Check if one user follows another |
|
| 78 | - * |
|
| 79 | - * @link https://developer.github.com/v3/users/followers/#check-if-one-user-follows-another |
|
| 80 | - * |
|
| 81 | - * @param string $username |
|
| 82 | - * @param string $targetUser |
|
| 83 | - * |
|
| 84 | - * @return bool |
|
| 85 | - * @throws \Exception |
|
| 86 | - */ |
|
| 87 | - public function checkUserFollowsAnother(string $username, string $targetUser): bool |
|
| 88 | - { |
|
| 89 | - $this->getApi()->request($this->getApi() |
|
| 90 | - ->sprintf('/users/:username/following/:target_user', $username, $targetUser)); |
|
| 91 | - |
|
| 92 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 93 | - return true; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return false; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Follow a user |
|
| 101 | - * |
|
| 102 | - * @link https://developer.github.com/v3/users/followers/#follow-a-user |
|
| 103 | - * |
|
| 104 | - * @param string $username |
|
| 105 | - * |
|
| 106 | - * @return bool |
|
| 107 | - * @throws \Exception |
|
| 108 | - */ |
|
| 109 | - public function followUser(string $username): bool |
|
| 110 | - { |
|
| 111 | - $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username), Request::METHOD_PUT); |
|
| 112 | - |
|
| 113 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Unfollow a user |
|
| 122 | - * |
|
| 123 | - * @link https://developer.github.com/v3/users/followers/#unfollow-a-user |
|
| 124 | - * |
|
| 125 | - * @param string $username |
|
| 126 | - * |
|
| 127 | - * @return bool |
|
| 128 | - * @throws \Exception |
|
| 129 | - */ |
|
| 130 | - public function unfollowUser(string $username): bool |
|
| 131 | - { |
|
| 132 | - $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username), |
|
| 133 | - Request::METHOD_DELETE); |
|
| 134 | - |
|
| 135 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return false; |
|
| 140 | - } |
|
| 15 | + /** |
|
| 16 | + * List followers of a user |
|
| 17 | + * |
|
| 18 | + * @link https://developer.github.com/v3/users/followers/#list-followers-of-a-user |
|
| 19 | + * |
|
| 20 | + * @param null|string $username |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + * @throws \Exception |
|
| 24 | + */ |
|
| 25 | + public function listFollowers(string $username = null): array |
|
| 26 | + { |
|
| 27 | + $url = '/user/followers'; |
|
| 28 | + if (null !== $username) { |
|
| 29 | + $url = $this->getApi()->sprintf('/users/:username/followers', $username); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + return $this->getApi()->request($url); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * List users followed by another user |
|
| 37 | + * |
|
| 38 | + * @link https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user |
|
| 39 | + * |
|
| 40 | + * @param null|string $username |
|
| 41 | + * |
|
| 42 | + * @return array |
|
| 43 | + * @throws \Exception |
|
| 44 | + */ |
|
| 45 | + public function listUsersFollowedBy(string $username = null): array |
|
| 46 | + { |
|
| 47 | + $url = '/user/following'; |
|
| 48 | + if (null !== $username) { |
|
| 49 | + $url = $this->getApi()->sprintf('/users/:username/following', $username); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + return $this->getApi()->request($url); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Check if you are following a user |
|
| 57 | + * |
|
| 58 | + * @link https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user |
|
| 59 | + * |
|
| 60 | + * @param string $username |
|
| 61 | + * |
|
| 62 | + * @return bool |
|
| 63 | + * @throws \Exception |
|
| 64 | + */ |
|
| 65 | + public function checkFollowingUser(string $username): bool |
|
| 66 | + { |
|
| 67 | + $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username)); |
|
| 68 | + |
|
| 69 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 70 | + return true; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Check if one user follows another |
|
| 78 | + * |
|
| 79 | + * @link https://developer.github.com/v3/users/followers/#check-if-one-user-follows-another |
|
| 80 | + * |
|
| 81 | + * @param string $username |
|
| 82 | + * @param string $targetUser |
|
| 83 | + * |
|
| 84 | + * @return bool |
|
| 85 | + * @throws \Exception |
|
| 86 | + */ |
|
| 87 | + public function checkUserFollowsAnother(string $username, string $targetUser): bool |
|
| 88 | + { |
|
| 89 | + $this->getApi()->request($this->getApi() |
|
| 90 | + ->sprintf('/users/:username/following/:target_user', $username, $targetUser)); |
|
| 91 | + |
|
| 92 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 93 | + return true; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return false; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Follow a user |
|
| 101 | + * |
|
| 102 | + * @link https://developer.github.com/v3/users/followers/#follow-a-user |
|
| 103 | + * |
|
| 104 | + * @param string $username |
|
| 105 | + * |
|
| 106 | + * @return bool |
|
| 107 | + * @throws \Exception |
|
| 108 | + */ |
|
| 109 | + public function followUser(string $username): bool |
|
| 110 | + { |
|
| 111 | + $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username), Request::METHOD_PUT); |
|
| 112 | + |
|
| 113 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Unfollow a user |
|
| 122 | + * |
|
| 123 | + * @link https://developer.github.com/v3/users/followers/#unfollow-a-user |
|
| 124 | + * |
|
| 125 | + * @param string $username |
|
| 126 | + * |
|
| 127 | + * @return bool |
|
| 128 | + * @throws \Exception |
|
| 129 | + */ |
|
| 130 | + public function unfollowUser(string $username): bool |
|
| 131 | + { |
|
| 132 | + $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username), |
|
| 133 | + Request::METHOD_DELETE); |
|
| 134 | + |
|
| 135 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | \ No newline at end of file |
@@ -12,51 +12,51 @@ |
||
| 12 | 12 | class Emails extends AbstractUsers |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * List email addresses for a user |
|
| 17 | - * |
|
| 18 | - * @link https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user |
|
| 19 | - * @return array |
|
| 20 | - * @throws \Exception |
|
| 21 | - */ |
|
| 22 | - public function listEmailAddresses(): array |
|
| 23 | - { |
|
| 24 | - return $this->getApi()->request($this->getApi()->sprintf('/user/emails')); |
|
| 25 | - } |
|
| 15 | + /** |
|
| 16 | + * List email addresses for a user |
|
| 17 | + * |
|
| 18 | + * @link https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user |
|
| 19 | + * @return array |
|
| 20 | + * @throws \Exception |
|
| 21 | + */ |
|
| 22 | + public function listEmailAddresses(): array |
|
| 23 | + { |
|
| 24 | + return $this->getApi()->request($this->getApi()->sprintf('/user/emails')); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Add email address(es) |
|
| 29 | - * |
|
| 30 | - * @link https://developer.github.com/v3/users/emails/#add-email-addresses |
|
| 31 | - * |
|
| 32 | - * @param array $addresses |
|
| 33 | - * |
|
| 34 | - * @return array |
|
| 35 | - * @throws \Exception |
|
| 36 | - */ |
|
| 37 | - public function addEmailAddress(array $addresses = []): array |
|
| 38 | - { |
|
| 39 | - return $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_POST, $addresses); |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * Add email address(es) |
|
| 29 | + * |
|
| 30 | + * @link https://developer.github.com/v3/users/emails/#add-email-addresses |
|
| 31 | + * |
|
| 32 | + * @param array $addresses |
|
| 33 | + * |
|
| 34 | + * @return array |
|
| 35 | + * @throws \Exception |
|
| 36 | + */ |
|
| 37 | + public function addEmailAddress(array $addresses = []): array |
|
| 38 | + { |
|
| 39 | + return $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_POST, $addresses); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Delete email address(es) |
|
| 44 | - * |
|
| 45 | - * @link https://developer.github.com/v3/users/emails/#delete-email-addresses |
|
| 46 | - * |
|
| 47 | - * @param array $addresses |
|
| 48 | - * |
|
| 49 | - * @return bool |
|
| 50 | - * @throws \Exception |
|
| 51 | - */ |
|
| 52 | - public function deleteEmailAddress(array $addresses = []): bool |
|
| 53 | - { |
|
| 54 | - $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_DELETE, $addresses); |
|
| 42 | + /** |
|
| 43 | + * Delete email address(es) |
|
| 44 | + * |
|
| 45 | + * @link https://developer.github.com/v3/users/emails/#delete-email-addresses |
|
| 46 | + * |
|
| 47 | + * @param array $addresses |
|
| 48 | + * |
|
| 49 | + * @return bool |
|
| 50 | + * @throws \Exception |
|
| 51 | + */ |
|
| 52 | + public function deleteEmailAddress(array $addresses = []): bool |
|
| 53 | + { |
|
| 54 | + $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_DELETE, $addresses); |
|
| 55 | 55 | |
| 56 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 57 | - return true; |
|
| 58 | - } |
|
| 56 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
| 57 | + return true; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return false; |
|
| 61 | - } |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |