mirror of
https://github.com/avency/Gitea.git
synced 2025-10-28 18:24:58 +01:00
feat: Add user endpoint
This commit is contained in:
@ -9,6 +9,7 @@ use Avency\Gitea\Endpoint\EndpointInterface;
|
|||||||
use Avency\Gitea\Endpoint\Miscellaneous;
|
use Avency\Gitea\Endpoint\Miscellaneous;
|
||||||
use Avency\Gitea\Endpoint\Organizations;
|
use Avency\Gitea\Endpoint\Organizations;
|
||||||
use Avency\Gitea\Endpoint\Repositories;
|
use Avency\Gitea\Endpoint\Repositories;
|
||||||
|
use Avency\Gitea\Endpoint\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ use Psr\Http\Message\ResponseInterface;
|
|||||||
* @method Miscellaneous miscellaneous()
|
* @method Miscellaneous miscellaneous()
|
||||||
* @method Organizations organizations()
|
* @method Organizations organizations()
|
||||||
* @method Repositories repositories()
|
* @method Repositories repositories()
|
||||||
|
* @method User user()
|
||||||
*/
|
*/
|
||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
|
|||||||
37
Classes/Endpoint/User.php
Normal file
37
Classes/Endpoint/User.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Avency\Gitea\Endpoint;
|
||||||
|
|
||||||
|
use Avency\Gitea\Client;
|
||||||
|
use Avency\Gitea\Endpoint\User\RepositoriesTrait;
|
||||||
|
use Avency\Gitea\Endpoint\User\UserTrait;
|
||||||
|
use Avency\Gitea\Endpoint\User\FollowersTrait;
|
||||||
|
use Avency\Gitea\Endpoint\User\KeysTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User endpoint
|
||||||
|
*/
|
||||||
|
class User extends AbstractEndpoint implements EndpointInterface
|
||||||
|
{
|
||||||
|
use FollowersTrait;
|
||||||
|
use KeysTrait;
|
||||||
|
use RepositoriesTrait;
|
||||||
|
use UserTrait;
|
||||||
|
|
||||||
|
const BASE_URI = '/user';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Client
|
||||||
|
*/
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Client $client
|
||||||
|
*/
|
||||||
|
public function __construct(Client $client)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
}
|
||||||
66
Classes/Endpoint/User/FollowersTrait.php
Normal file
66
Classes/Endpoint/User/FollowersTrait.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Avency\Gitea\Endpoint\User;
|
||||||
|
|
||||||
|
use Avency\Gitea\Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Users Followers Trait
|
||||||
|
*/
|
||||||
|
trait FollowersTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getFollowers(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/followers');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getFollowing(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/following');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function checkFollowing(string $username): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/following/' . $username);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function addFollowing(string $username): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/following/' . $username, 'PUT');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteFollowing(string $username): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/following/' . $username, 'DELETE');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
112
Classes/Endpoint/User/KeysTrait.php
Normal file
112
Classes/Endpoint/User/KeysTrait.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Avency\Gitea\Endpoint\User;
|
||||||
|
|
||||||
|
use Avency\Gitea\Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Users Keys Trait
|
||||||
|
*/
|
||||||
|
trait KeysTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getGPGKeys(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/gpg_keys');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addGPGKey(string $key): array
|
||||||
|
{
|
||||||
|
$options['json'] = [
|
||||||
|
'armored_public_key' => $key
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/gpg_keys', 'POST', $options);
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getGPGKey(int $id): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/gpg_keys/' . $id);
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteGPGKey(int $id): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/gpg_keys/' . $id, 'DELETE');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getKeys(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/keys');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $title
|
||||||
|
* @param string $key
|
||||||
|
* @param bool|null $readOnly
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addKey(string $title, string $key, bool $readOnly = null): array
|
||||||
|
{
|
||||||
|
$options['json'] = [
|
||||||
|
'key' => $key,
|
||||||
|
'read_only' => $readOnly,
|
||||||
|
'title' => $title,
|
||||||
|
];
|
||||||
|
$options['json'] = $this->removeNullValues($options['json']);
|
||||||
|
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/keys', 'POST', $options);
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getKey(int $id): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/keys/' . $id);
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteKey(int $id): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/keys/' . $id, 'DELETE');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
79
Classes/Endpoint/User/RepositoriesTrait.php
Normal file
79
Classes/Endpoint/User/RepositoriesTrait.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Avency\Gitea\Endpoint\User;
|
||||||
|
|
||||||
|
use Avency\Gitea\Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Users Repositories Trait
|
||||||
|
*/
|
||||||
|
trait RepositoriesTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getRepositories(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/repos');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getStarredRepositories(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/starred');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $owner
|
||||||
|
* @param string $repositoryName
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function checkStarredRepository(string $owner, string $repositoryName): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/starred/' . $owner . '/' . $repositoryName);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $owner
|
||||||
|
* @param string $repositoryName
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function addStarredRepository(string $owner, string $repositoryName): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/starred/' . $owner . '/' . $repositoryName, 'PUT');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $owner
|
||||||
|
* @param string $repositoryName
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteStarredRepository(string $owner, string $repositoryName): bool
|
||||||
|
{
|
||||||
|
$this->client->request(self::BASE_URI . '/starred/' . $owner . '/' . $repositoryName, 'DELETE');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSubscriptions(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/subscriptions');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
93
Classes/Endpoint/User/UserTrait.php
Normal file
93
Classes/Endpoint/User/UserTrait.php
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Avency\Gitea\Endpoint\User;
|
||||||
|
|
||||||
|
use Avency\Gitea\Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Users User Trait
|
||||||
|
*/
|
||||||
|
trait UserTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI);
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getEmails(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/emails');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $emails
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addEmails(array $emails): array
|
||||||
|
{
|
||||||
|
$options['json'] = [
|
||||||
|
'emails' => $emails
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/emails', 'POST', $options);
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $emails
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteEmails(array $emails): bool
|
||||||
|
{
|
||||||
|
$options['json'] = [
|
||||||
|
'emails' => $emails
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->client->request(self::BASE_URI . '/emails', 'DELETE', $options);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getStopwatches(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/stopwatches');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTeams(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/teams');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTimes(): array
|
||||||
|
{
|
||||||
|
$response = $this->client->request(self::BASE_URI . '/times');
|
||||||
|
|
||||||
|
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
README.md
59
README.md
@ -278,34 +278,39 @@ Status | Method | Endpoint | Comment
|
|||||||
|
|
||||||
Status | Method | Endpoint | Comment
|
Status | Method | Endpoint | Comment
|
||||||
--- | --- | --- | ---
|
--- | --- | --- | ---
|
||||||
|
✅ | GET | /user |
|
||||||
|
✅ | GET | /user/emails |
|
||||||
|
✅ | POST | /user/emails |
|
||||||
|
✅ | DELETE | /user/emails |
|
||||||
|
✅ | GET | /user/followers |
|
||||||
|
✅ | GET | /user/following |
|
||||||
|
✅ | GET | /user/following/{username} |
|
||||||
|
✅ | PUT | /user/following/{username} |
|
||||||
|
✅ | DELETE | /user/following/{username} |
|
||||||
|
✅ | GET | /user/gpg_keys |
|
||||||
|
✅ | POST | /user/gpg_keys |
|
||||||
|
✅ | GET | /user/gpg_keys/{id} |
|
||||||
|
✅ | DELETE | /user/gpg_keys/{id} |
|
||||||
|
✅ | GET | /user/keys |
|
||||||
|
✅ | POST | /user/keys |
|
||||||
|
✅ | GET | /user/keys/{id} |
|
||||||
|
✅ | DELETE | /user/keys/{id} |
|
||||||
|
✅ | GET | /user/repos |
|
||||||
|
✅ | POST | /user/repos |
|
||||||
|
✅ | GET | /user/starred |
|
||||||
|
✅ | GET | /user/starred/{owner}/{repo} |
|
||||||
|
✅ | PUT | /user/starred/{owner}/{repo} |
|
||||||
|
✅ | DELETE | /user/starred/{owner}/{repo} |
|
||||||
|
✅ | GET | /user/stopwatches |
|
||||||
|
✅ | GET | /user/subscriptions |
|
||||||
|
✅ | GET | /user/teams |
|
||||||
|
✅ | GET | /user/times |
|
||||||
|
|
||||||
|
#### Users
|
||||||
|
|
||||||
|
Status | Method | Endpoint | Comment
|
||||||
|
--- | --- | --- | ---
|
||||||
❌ | GET | /repos/{owner}/{repo}/times/{user} |
|
❌ | GET | /repos/{owner}/{repo}/times/{user} |
|
||||||
❌ | GET | /user |
|
|
||||||
❌ | GET | /user/emails |
|
|
||||||
❌ | POST | /user/emails |
|
|
||||||
❌ | DELETE | /user/emails |
|
|
||||||
❌ | GET | /user/followers |
|
|
||||||
❌ | GET | /user/following |
|
|
||||||
❌ | GET | /user/following/{username} |
|
|
||||||
❌ | PUT | /user/following/{username} |
|
|
||||||
❌ | DELETE | /user/following/{username} |
|
|
||||||
❌ | GET | /user/gpg_keys |
|
|
||||||
❌ | POST | /user/gpg_keys |
|
|
||||||
❌ | GET | /user/gpg_keys/{id} |
|
|
||||||
❌ | DELETE | /user/gpg_keys/{id} |
|
|
||||||
❌ | GET | /user/keys |
|
|
||||||
❌ | POST | /user/keys |
|
|
||||||
❌ | GET | /user/keys/{id} |
|
|
||||||
❌ | DELETE | /user/keys/{id} |
|
|
||||||
❌ | GET | /user/repos |
|
|
||||||
❌ | POST | /user/repos |
|
|
||||||
❌ | GET | /user/starred |
|
|
||||||
❌ | GET | /user/starred/{owner}/{repo} |
|
|
||||||
❌ | PUT | /user/starred/{owner}/{repo} |
|
|
||||||
❌ | DELETE | /user/starred/{owner}/{repo} |
|
|
||||||
❌ | GET | /user/stopwatches |
|
|
||||||
❌ | GET | /user/subscriptions |
|
|
||||||
❌ | GET | /user/teams |
|
|
||||||
❌ | GET | /user/times |
|
|
||||||
❌ | GET | /users/search |
|
❌ | GET | /users/search |
|
||||||
❌ | GET | /users/{follower}/following/{followee} |
|
❌ | GET | /users/{follower}/following/{followee} |
|
||||||
❌ | GET | /users/{username} |
|
❌ | GET | /users/{username} |
|
||||||
|
|||||||
Reference in New Issue
Block a user