2024-12-20 23:46:30 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace D3\KlicktippPhpClient\Resources;
|
|
|
|
|
|
|
|
use D3\KlicktippPhpClient\Entities\Tag as TagEntity;
|
2024-12-22 23:36:29 +01:00
|
|
|
use D3\KlicktippPhpClient\Entities\TagList;
|
2024-12-20 23:46:30 +01:00
|
|
|
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
2024-12-21 19:17:08 +01:00
|
|
|
use GuzzleHttp\RequestOptions;
|
2024-12-20 23:46:30 +01:00
|
|
|
|
|
|
|
class Tag extends Model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
2024-12-22 23:36:29 +01:00
|
|
|
public function index(): TagList
|
2024-12-20 23:46:30 +01:00
|
|
|
{
|
2024-12-22 23:36:29 +01:00
|
|
|
$data = $this->connection->requestAndParse(
|
2024-12-20 23:46:30 +01:00
|
|
|
'GET',
|
2024-12-21 19:25:33 +01:00
|
|
|
'tag'
|
2024-12-20 23:46:30 +01:00
|
|
|
);
|
2024-12-22 23:36:29 +01:00
|
|
|
|
|
|
|
return new TagList($data);
|
2024-12-20 23:46:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function get(string $tagId): TagEntity
|
|
|
|
{
|
|
|
|
$data = $this->connection->requestAndParse(
|
|
|
|
'GET',
|
2024-12-22 13:54:42 +01:00
|
|
|
'tag/'.urlencode(trim($tagId))
|
|
|
|
);
|
|
|
|
|
|
|
|
return new TagEntity($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function create(string $name): array
|
|
|
|
{
|
|
|
|
return $this->connection->requestAndParse(
|
|
|
|
'POST',
|
|
|
|
'tag/',
|
|
|
|
[
|
|
|
|
RequestOptions::FORM_PARAMS => [
|
|
|
|
'name' => trim($name)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function update(string $tagId, string $newName): array
|
|
|
|
{
|
|
|
|
return $this->connection->requestAndParse(
|
|
|
|
'PUT',
|
2024-12-20 23:46:30 +01:00
|
|
|
'tag/'.urlencode(trim($tagId)),
|
|
|
|
[
|
2024-12-22 13:54:42 +01:00
|
|
|
RequestOptions::FORM_PARAMS => [
|
|
|
|
'name' => trim($newName)
|
|
|
|
]
|
2024-12-20 23:46:30 +01:00
|
|
|
]
|
|
|
|
);
|
2024-12-22 13:54:42 +01:00
|
|
|
}
|
2024-12-20 23:46:30 +01:00
|
|
|
|
2024-12-22 13:54:42 +01:00
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function delete(string $tagId): array
|
|
|
|
{
|
|
|
|
return $this->connection->requestAndParse(
|
|
|
|
'DELETE',
|
|
|
|
'tag/'.urlencode(trim($tagId))
|
|
|
|
);
|
2024-12-20 23:46:30 +01:00
|
|
|
}
|
|
|
|
}
|