Client.php 2.3 KB

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