* @link https://www.oxidmodule.com */ namespace D3\KlicktippPhpClient\Resources; use D3\KlicktippPhpClient\Entities\Tag as TagEntity; use D3\KlicktippPhpClient\Entities\TagList; use D3\KlicktippPhpClient\Exceptions\BaseException; use GuzzleHttp\RequestOptions; class Tag extends Model { /** * @throws BaseException */ public function index(): TagList { $data = $this->connection->requestAndParse( 'GET', 'tag.json' ); return new TagList($data); } /** * @throws BaseException */ public function get(string $tagId): TagEntity { $data = $this->connection->requestAndParse( 'GET', 'tag/'.urlencode(trim($tagId)).'.json' ); return new TagEntity($data, $this); } /** * @return string - new tag id * @throws BaseException */ public function create(string $name): string { return current( $this->connection->requestAndParse( 'POST', 'tag.json', [ RequestOptions::FORM_PARAMS => [ 'name' => trim($name), ], ] ) ); } /** * @throws BaseException */ public function update(string $tagId, ?string $name = null, ?string $text = null): bool { return (bool) current( $this->connection->requestAndParse( 'PUT', 'tag/'.urlencode(trim($tagId)).'.json', [ RequestOptions::FORM_PARAMS => array_filter([ 'name' => trim($name ?? ''), 'text' => trim($text ?? ''), ]), ] ) ); } /** * @throws BaseException */ public function delete(string $tagId): bool { return (bool) current( $this->connection->requestAndParse( 'DELETE', 'tag/'.urlencode(trim($tagId)).'.json' ) ); } }