gogsapi.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php namespace Client;
  2. /**
  3. * Gogs API client. This class initially provide
  4. * the programmer with a starting point and a kind
  5. * of an interface to start from, to keep track of
  6. * the context.
  7. *
  8. * @author Joachim M. Giaever (joachim[]giaever.org)
  9. * @version 0.1
  10. */
  11. class GogsAPI {
  12. use \Lib\Curl;
  13. /**
  14. * Constructor of the class to store the api data.
  15. *
  16. * @param string $api_url
  17. * @param string $api_token
  18. * @return null
  19. */
  20. public function __construct(string $api_url, string $api_token) {
  21. $this->url = $api_url;
  22. $this->token = $api_token;
  23. }
  24. /**
  25. * Returns an object to fetch users from the
  26. * Gogs installation. See \Request\Users class
  27. * to understand usage (e.g ->load() to fetch all,
  28. * ->search(array params) to search for one or several
  29. * users etc).
  30. *
  31. * @return \Request\Users
  32. */
  33. public function users() {
  34. return new Request\Users($this->url, $this->token);
  35. }
  36. /**
  37. * Returns an object to fetch the repositories
  38. * on the Gogs installation. See \Request\Repos to
  39. * understand usage. Inherits the same class as \R\Users,
  40. * but the usage may differ!
  41. *
  42. * Note! To fetch a particular repo under a user, you
  43. * should go through the user (see method below).
  44. *
  45. * @return \Request\Repos
  46. */
  47. public function repos() {
  48. return new Request\Repos($this->url, $this->token);
  49. }
  50. /**
  51. * Returns either
  52. * * the authorized user ($name = "" or "me")
  53. * * the specified user ($name = anything else)
  54. *
  55. * @return \Request\User
  56. */
  57. public function user(string $name = "me") {
  58. return new Request\User($this->url, $this->token, $name);
  59. }
  60. /**
  61. * Nothing to "destruct" at this time.
  62. *
  63. * @return null
  64. */
  65. public function __destruct() {}
  66. }
  67. ?>