Client.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * @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. */
  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. }
  66. }
  67. ?>