From 774c0ff8bfcc4029f76f832633a159fa64af4e12 Mon Sep 17 00:00:00 2001 From: Michael Gerdemann Date: Fri, 17 Jan 2020 16:32:02 +0100 Subject: [PATCH 1/2] feat: Change endpoint calls Change the endpoint call so that there is an autocompletion. --- Classes/Client.php | 16 ++++++++++------ README.md | 5 ++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Classes/Client.php b/Classes/Client.php index c0d170c..89d5dd7 100644 --- a/Classes/Client.php +++ b/Classes/Client.php @@ -11,6 +11,8 @@ use Psr\Http\Message\ResponseInterface; /** * Gitea Client + * + * @method Repositories repositories() */ class Client { @@ -45,18 +47,20 @@ class Client } /** - * @param string $api + * @param $method + * @param $args * @return EndpointInterface * @throws Exception */ - public function api(string $api): EndpointInterface + public function __call($method, $args) { - switch ($api) { - case 'repositories': - return new Repositories($this); + $interfaceName = EndpointInterface::class; + $endpointClassName = str_replace('\\EndpointInterface', '\\' . ucfirst($method), $interfaceName); + if (class_exists($endpointClassName)) { + return new $endpointClassName($this); } - throw new Exception('Endpoint not found', 1579246217); + throw new Exception('Endpoint "' . ucfirst($method) . '" not found!', 1579274712); } /** diff --git a/README.md b/README.md index a2580ba..1631af4 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,10 @@ $giteaClient = new Avency\Gitea\Client( // - - - - - // Get a single repository -$repository = $giteaClient->api('repositories')->get('owner', 'repoName'); +$repository = $giteaClient->repositories()->get('owner', 'repoName'); + +// Get version +$repository = $giteaClient->miscellaneous()->version(); ``` ## Versioning From 95e565d6a091ea3897c90974f50daf2be9dcad67 Mon Sep 17 00:00:00 2001 From: Michael Gerdemann Date: Fri, 17 Jan 2020 16:32:50 +0100 Subject: [PATCH 2/2] feat: Add miscellaaneous endpoint --- Classes/Client.php | 2 ++ Classes/Endpoint/Miscellaneous.php | 37 ++++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Classes/Endpoint/Miscellaneous.php diff --git a/Classes/Client.php b/Classes/Client.php index 89d5dd7..6a710f7 100644 --- a/Classes/Client.php +++ b/Classes/Client.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Avency\Gitea; use Avency\Gitea\Endpoint\EndpointInterface; +use Avency\Gitea\Endpoint\Miscellaneous; use Avency\Gitea\Endpoint\Repositories; use Exception; use Psr\Http\Message\ResponseInterface; @@ -13,6 +14,7 @@ use Psr\Http\Message\ResponseInterface; * Gitea Client * * @method Repositories repositories() + * @method Miscellaneous miscellaneous() */ class Client { diff --git a/Classes/Endpoint/Miscellaneous.php b/Classes/Endpoint/Miscellaneous.php new file mode 100644 index 0000000..c4c0baf --- /dev/null +++ b/Classes/Endpoint/Miscellaneous.php @@ -0,0 +1,37 @@ +client = $client; + } + + /** + * @return string + */ + public function version(): string + { + $response = $this->client->request(self::BASE_URI . '/version'); + return \GuzzleHttp\json_decode($response->getBody(), true)['version']; + } +} diff --git a/README.md b/README.md index 1631af4..37fca7a 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Status | Method | Endpoint ❌ | POST | /markdown ❌ | POST | /markdown/raw ❌ | GET | /signing-key.gpg -❌ | GET | /version +✅ | GET | /version #### Organization