mirror of
https://github.com/avency/Gitea.git
synced 2025-10-29 18:52:33 +01:00
Merge branch 'feature/mg-Defaults' of AVENCY/Gitea into master
Reviewed-by: Lisa Kampert <lisa.kampert@avency.de>
This commit is contained in:
@ -5,12 +5,16 @@ declare(strict_types=1);
|
|||||||
namespace Avency\Gitea;
|
namespace Avency\Gitea;
|
||||||
|
|
||||||
use Avency\Gitea\Endpoint\EndpointInterface;
|
use Avency\Gitea\Endpoint\EndpointInterface;
|
||||||
|
use Avency\Gitea\Endpoint\Miscellaneous;
|
||||||
use Avency\Gitea\Endpoint\Repositories;
|
use Avency\Gitea\Endpoint\Repositories;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gitea Client
|
* Gitea Client
|
||||||
|
*
|
||||||
|
* @method Repositories repositories()
|
||||||
|
* @method Miscellaneous miscellaneous()
|
||||||
*/
|
*/
|
||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
@ -45,18 +49,20 @@ class Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $api
|
* @param $method
|
||||||
|
* @param $args
|
||||||
* @return EndpointInterface
|
* @return EndpointInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function api(string $api): EndpointInterface
|
public function __call($method, $args)
|
||||||
{
|
{
|
||||||
switch ($api) {
|
$interfaceName = EndpointInterface::class;
|
||||||
case 'repositories':
|
$endpointClassName = str_replace('\\EndpointInterface', '\\' . ucfirst($method), $interfaceName);
|
||||||
return new Repositories($this);
|
if (class_exists($endpointClassName)) {
|
||||||
|
return new $endpointClassName($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception('Endpoint not found', 1579246217);
|
throw new Exception('Endpoint "' . ucfirst($method) . '" not found!', 1579274712);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
37
Classes/Endpoint/Miscellaneous.php
Normal file
37
Classes/Endpoint/Miscellaneous.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Avency\Gitea\Endpoint;
|
||||||
|
|
||||||
|
use Avency\Gitea\Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Miscellaneous endpoint
|
||||||
|
*/
|
||||||
|
class Miscellaneous implements EndpointInterface
|
||||||
|
{
|
||||||
|
const BASE_URI = 'api/v1';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Client
|
||||||
|
*/
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Client $client
|
||||||
|
*/
|
||||||
|
public function __construct(Client $client)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function version(): string
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/version');
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true)['version'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -53,7 +53,10 @@ $giteaClient = new Avency\Gitea\Client(
|
|||||||
// - - - - -
|
// - - - - -
|
||||||
|
|
||||||
// Get a single repository
|
// Get a single repository
|
||||||
$repository = $giteaClient->api('repositories')->get('owner', 'repoName');
|
$repository = $giteaClient->repositories()->get('owner', 'repoName');
|
||||||
|
|
||||||
|
// Get version
|
||||||
|
$repository = $giteaClient->miscellaneous()->version();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Versioning
|
## Versioning
|
||||||
@ -95,7 +98,7 @@ Status | Method | Endpoint
|
|||||||
❌ | POST | /markdown
|
❌ | POST | /markdown
|
||||||
❌ | POST | /markdown/raw
|
❌ | POST | /markdown/raw
|
||||||
❌ | GET | /signing-key.gpg
|
❌ | GET | /signing-key.gpg
|
||||||
❌ | GET | /version
|
✅ | GET | /version
|
||||||
|
|
||||||
#### Organization
|
#### Organization
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user