feat: Add user endpoint

This commit is contained in:
Michael Gerdemann
2020-01-19 15:53:23 +01:00
parent 6e6b0b6a29
commit 5c2450116b
7 changed files with 421 additions and 27 deletions

View 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;
}
}