PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Joomla/Github/Package/Repositories/Statuses.php

https://github.com/piotr-cz/joomla-framework
PHP | 90 lines | 34 code | 10 blank | 46 comment | 3 complexity | f32aa7b832d6e9394200420741ace82b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Part of the Joomla Framework Github Package
  4. *
  5. * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE
  7. */
  8. namespace Joomla\Github\Package\Repositories;
  9. use Joomla\Github\AbstractPackage;
  10. /**
  11. * GitHub API References class for the Joomla Framework.
  12. *
  13. * @documentation http://developer.github.com/v3/repos/statuses
  14. *
  15. * @since 1.0
  16. */
  17. class Statuses extends AbstractPackage
  18. {
  19. /**
  20. * Method to create a status.
  21. *
  22. * @param string $user The name of the owner of the GitHub repository.
  23. * @param string $repo The name of the GitHub repository.
  24. * @param string $sha The SHA1 value for which to set the status.
  25. * @param string $state The state (pending, success, error or failure).
  26. * @param string $targetUrl Optional target URL.
  27. * @param string $description Optional description for the status.
  28. *
  29. * @throws \InvalidArgumentException
  30. * @throws \DomainException
  31. *
  32. * @since 1.0
  33. *
  34. * @return object
  35. */
  36. public function create($user, $repo, $sha, $state, $targetUrl = null, $description = null)
  37. {
  38. // Build the request path.
  39. $path = '/repos/' . $user . '/' . $repo . '/statuses/' . $sha;
  40. if (!in_array($state, array('pending', 'success', 'error', 'failure')))
  41. {
  42. throw new \InvalidArgumentException('State must be one of pending, success, error or failure.');
  43. }
  44. // Build the request data.
  45. $data = array(
  46. 'state' => $state
  47. );
  48. if (!is_null($targetUrl))
  49. {
  50. $data['target_url'] = $targetUrl;
  51. }
  52. if (!is_null($description))
  53. {
  54. $data['description'] = $description;
  55. }
  56. // Send the request.
  57. return $this->processResponse(
  58. $this->client->post($this->fetchUrl($path), json_encode($data)),
  59. 201
  60. );
  61. }
  62. /**
  63. * Method to list statuses for an SHA.
  64. *
  65. * @param string $user The name of the owner of the GitHub repository.
  66. * @param string $repo The name of the GitHub repository.
  67. * @param string $sha SHA1 for which to get the statuses.
  68. *
  69. * @return array
  70. *
  71. * @since 1.0
  72. */
  73. public function getList($user, $repo, $sha)
  74. {
  75. // Build the request path.
  76. $path = '/repos/' . $user . '/' . $repo . '/statuses/' . $sha;
  77. // Send the request.
  78. return $this->processResponse($this->client->get($this->fetchUrl($path)));
  79. }
  80. }