diff --git a/Classes/Client.php b/Classes/Client.php index 031fc47..0ba1c00 100644 --- a/Classes/Client.php +++ b/Classes/Client.php @@ -9,6 +9,7 @@ use Avency\Gitea\Endpoint\EndpointInterface; use Avency\Gitea\Endpoint\Miscellaneous; use Avency\Gitea\Endpoint\Organizations; use Avency\Gitea\Endpoint\Repositories; +use Avency\Gitea\Endpoint\User; use Exception; use Psr\Http\Message\ResponseInterface; @@ -19,6 +20,7 @@ use Psr\Http\Message\ResponseInterface; * @method Miscellaneous miscellaneous() * @method Organizations organizations() * @method Repositories repositories() + * @method User user() */ class Client { diff --git a/Classes/Endpoint/User.php b/Classes/Endpoint/User.php new file mode 100644 index 0000000..8de026a --- /dev/null +++ b/Classes/Endpoint/User.php @@ -0,0 +1,37 @@ +client = $client; + } +} diff --git a/Classes/Endpoint/User/FollowersTrait.php b/Classes/Endpoint/User/FollowersTrait.php new file mode 100644 index 0000000..01e6ff6 --- /dev/null +++ b/Classes/Endpoint/User/FollowersTrait.php @@ -0,0 +1,66 @@ +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; + } +} diff --git a/Classes/Endpoint/User/KeysTrait.php b/Classes/Endpoint/User/KeysTrait.php new file mode 100644 index 0000000..a1f6e42 --- /dev/null +++ b/Classes/Endpoint/User/KeysTrait.php @@ -0,0 +1,112 @@ +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; + } +} diff --git a/Classes/Endpoint/User/RepositoriesTrait.php b/Classes/Endpoint/User/RepositoriesTrait.php new file mode 100644 index 0000000..4c52ace --- /dev/null +++ b/Classes/Endpoint/User/RepositoriesTrait.php @@ -0,0 +1,79 @@ +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); + } +} diff --git a/Classes/Endpoint/User/UserTrait.php b/Classes/Endpoint/User/UserTrait.php new file mode 100644 index 0000000..a2b1fef --- /dev/null +++ b/Classes/Endpoint/User/UserTrait.php @@ -0,0 +1,93 @@ +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); + } +} diff --git a/README.md b/README.md index 851ae32..a0b60c9 100644 --- a/README.md +++ b/README.md @@ -278,34 +278,39 @@ 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 | /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/{follower}/following/{followee} | ❌ | GET | /users/{username} |