mirror of
https://github.com/avency/Gitea.git
synced 2025-10-28 18:24:58 +01:00
feat: Add users endpoint
This commit is contained in:
@ -10,6 +10,7 @@ use Avency\Gitea\Endpoint\Miscellaneous;
|
||||
use Avency\Gitea\Endpoint\Organizations;
|
||||
use Avency\Gitea\Endpoint\Repositories;
|
||||
use Avency\Gitea\Endpoint\User;
|
||||
use Avency\Gitea\Endpoint\Users;
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
@ -21,6 +22,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
* @method Organizations organizations()
|
||||
* @method Repositories repositories()
|
||||
* @method User user()
|
||||
* @method Users users()
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
|
||||
33
Classes/Endpoint/Users.php
Normal file
33
Classes/Endpoint/Users.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Avency\Gitea\Endpoint;
|
||||
|
||||
use Avency\Gitea\Client;
|
||||
use Avency\Gitea\Endpoint\Users\TokensTrait;
|
||||
use Avency\Gitea\Endpoint\Users\UsersTrait;
|
||||
|
||||
/**
|
||||
* Users endpoint
|
||||
*/
|
||||
class Users extends AbstractEndpoint implements EndpointInterface
|
||||
{
|
||||
use TokensTrait;
|
||||
use UsersTrait;
|
||||
|
||||
const BASE_URI = '/users';
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
*/
|
||||
public function __construct(Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
}
|
||||
52
Classes/Endpoint/Users/TokensTrait.php
Normal file
52
Classes/Endpoint/Users/TokensTrait.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Avency\Gitea\Endpoint\Users;
|
||||
|
||||
use Avency\Gitea\Client;
|
||||
|
||||
/**
|
||||
* Users Tokens Trait
|
||||
*/
|
||||
trait TokensTrait
|
||||
{
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getTokens(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' .$username . '/tokens');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function addToken(string $username, string $name): array
|
||||
{
|
||||
$options['json'] = [
|
||||
'name' => $name
|
||||
];
|
||||
|
||||
$response = $this->client->request(self::BASE_URI . '/' .$username . '/tokens', 'POST', $options);
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param int $token
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteToken(string $username, int $token): bool
|
||||
{
|
||||
$this->client->request(self::BASE_URI . '/' .$username . '/tokens/' . $token, 'DELETE');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
157
Classes/Endpoint/Users/UsersTrait.php
Normal file
157
Classes/Endpoint/Users/UsersTrait.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Avency\Gitea\Endpoint\Users;
|
||||
|
||||
use Avency\Gitea\Client;
|
||||
|
||||
/**
|
||||
* Users Users Trait
|
||||
*/
|
||||
trait UsersTrait
|
||||
{
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function get(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username);
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $searchTerm
|
||||
* @param int|null $id
|
||||
* @param int|null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function search(string $searchTerm, int $id = null, int $limit = null): array
|
||||
{
|
||||
$options['query'] = [
|
||||
'q' => $searchTerm,
|
||||
'id' => $id,
|
||||
'limit' => $limit,
|
||||
];
|
||||
$options['query'] = $this->removeNullValues($options['query']);
|
||||
|
||||
$response = $this->client->request(self::BASE_URI . '/search', 'GET', $options);
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $followee
|
||||
* @return bool
|
||||
*/
|
||||
public function checkFollowing(string $username, string $followee): bool
|
||||
{
|
||||
$this->client->request(self::BASE_URI . '/' . $username . '/following/' . $followee);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getFollowers(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/followers');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getFollowing(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/following');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getGPGKeys(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/gpg_keys');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getHeatmap(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/heatmap');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getKeys(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/keys');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getRepositories(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/repos');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getStarred(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/starred');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptions(string $username): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $username . '/subscriptions');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $owner
|
||||
* @param string $repositoryName
|
||||
* @return array
|
||||
*/
|
||||
public function getTimes(string $username, string $owner, string $repositoryName): array
|
||||
{
|
||||
$response = $this->client->request('/repos/' . $owner . '/' . $repositoryName . '/times/' . $username);
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
}
|
||||
30
README.md
30
README.md
@ -310,18 +310,18 @@ Status | Method | Endpoint | Comment
|
||||
|
||||
Status | Method | Endpoint | Comment
|
||||
--- | --- | --- | ---
|
||||
❌ | GET | /repos/{owner}/{repo}/times/{user} |
|
||||
❌ | GET | /users/search |
|
||||
❌ | GET | /users/{follower}/following/{followee} |
|
||||
❌ | GET | /users/{username} |
|
||||
❌ | GET | /users/{username}/followers |
|
||||
❌ | GET | /users/{username}/following |
|
||||
❌ | GET | /users/{username}/gpg_keys |
|
||||
❌ | GET | /users/{username}/heatmap |
|
||||
❌ | GET | /users/{username}/keys |
|
||||
❌ | GET | /users/{username}/repos |
|
||||
❌ | GET | /users/{username}/starred |
|
||||
❌ | GET | /users/{username}/subscriptions |
|
||||
❌ | GET | /users/{username}/tokens |
|
||||
❌ | POST | /users/{username}/tokens |
|
||||
❌ | DELETE | /users/{username}/tokens/{token} |
|
||||
✅ | GET | /repos/{owner}/{repo}/times/{user} |
|
||||
✅ | GET | /users/search |
|
||||
✅ | GET | /users/{follower}/following/{followee} |
|
||||
✅ | GET | /users/{username} |
|
||||
✅ | GET | /users/{username}/followers |
|
||||
✅ | GET | /users/{username}/following |
|
||||
✅ | GET | /users/{username}/gpg_keys |
|
||||
✅ | GET | /users/{username}/heatmap |
|
||||
✅ | GET | /users/{username}/keys |
|
||||
✅ | GET | /users/{username}/repos |
|
||||
✅ | GET | /users/{username}/starred |
|
||||
✅ | GET | /users/{username}/subscriptions |
|
||||
✅ | GET | /users/{username}/tokens |
|
||||
✅ | POST | /users/{username}/tokens |
|
||||
✅ | DELETE | /users/{username}/tokens/{token} |
|
||||
|
||||
Reference in New Issue
Block a user