Client.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php namespace Gogs\API;
  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 Client {
  12. use \Gogs\Lib\Curl\Client;
  13. /**
  14. * Constructor of the class to store the api data.
  15. *
  16. * @deprecated "No longer user"
  17. * @param string $api_url
  18. * @param string $api_token
  19. * @return null
  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 an object to fetch users from the
  27. * Gogs installation. See \Request\Users class
  28. * to understand usage (e.g ->load() to fetch all,
  29. * ->search(array params) to search for one or several
  30. * users etc).
  31. *
  32. * @return \Request\Users
  33. */
  34. public function users() {
  35. return new Request\Users($this->url, $this->token);
  36. }
  37. /**
  38. * Returns an object to fetch the repositories
  39. * on the Gogs installation. See \Request\Repos to
  40. * understand usage. Inherits the same class as \R\Users,
  41. * but the usage may differ!
  42. *
  43. * Note! To fetch a particular repo under a user, you
  44. * should go through the user (see method below).
  45. *
  46. * @return \Request\Repos
  47. */
  48. public function repos() {
  49. return new Request\Repos($this->url, $this->token);
  50. }
  51. /**
  52. * Returns either
  53. * * the authorized user ($name = "" or "me")
  54. * * the specified user ($name = anything else)
  55. *
  56. * @return \Request\User
  57. */
  58. public function user(string $name = "me") {
  59. return new Request\User($this->url, $this->token, $name);
  60. }
  61. /**
  62. * Nothing to "destruct" at this time.
  63. *
  64. * @return null
  65. */
  66. public function __destruct() {}
  67. }
  68. ?>