Client.php 2.3 KB

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