clean up requests from unused options

Cette révision appartient à :
Daniel Seifert 2024-12-21 19:25:33 +01:00
Parent 58a20c3387
révision b080b1a64c
Signé par: DanielS
ID de la clé GPG: 6A513E13AEE66170
4 fichiers modifiés avec 8 ajouts et 83 suppressions

Voir le fichier

@ -4,6 +4,7 @@ namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Exceptions\BaseException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
class Account extends Model
{
@ -16,8 +17,7 @@ class Account extends Model
'POST',
'account/login',
[
'query' => $this->getQuery(),
'form_params' => [
RequestOptions::FORM_PARAMS => [
'username' => $this->connection->getClientKey(),
'password' => $this->connection->getSecretKey()
]
@ -34,8 +34,7 @@ class Account extends Model
{
$response = $this->connection->requestAndParse(
'POST',
'account/logout',
['query' => $this->getQuery()]
'account/logout'
);
return (bool) current($response);

Voir le fichier

@ -3,78 +3,13 @@
namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Connection;
use GuzzleHttp\RequestOptions;
abstract class Model
{
protected Connection $connection;
protected array $filters = [];
protected ?int $limit = null;
protected ?int $offset = null;
protected array $query = [];
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
public function getLimit(): ?int
{
return $this->limit;
}
public function setLimit(int $limit): static
{
$this->limit = $limit;
return $this;
}
public function getOffset(): ?int
{
return $this->offset;
}
public function setOffset(int $offset): static
{
$this->offset = $offset;
return $this;
}
public function setFilter(string $column, $operation, $value = null): static
{
if (is_null($value)) {
$value = $operation;
$operation = 'eq';
}
$this->filters[$column][$operation] = $value;
return $this;
}
public function getQuery(): array
{
return array_filter(array_merge(
$this->query,
$this->filters,
[
'limit' => $this->getLimit(),
'offset' => $this->getOffset()
]
));
}
public function setQuery(string|array $key, mixed $value = null): static
{
if (is_array($key)) {
$this->query = $key;
} else {
$this->query[$key] = $value;
}
return $this;
}
}

Voir le fichier

@ -5,6 +5,7 @@ namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
use D3\KlicktippPhpClient\Exceptions\BaseException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
class Subscriber extends Model
{
@ -15,10 +16,7 @@ class Subscriber extends Model
{
return $this->connection->requestAndParse(
'GET',
'subscriber',
[
'query' => $this->getQuery()
]
'subscriber'
);
}
@ -29,10 +27,7 @@ class Subscriber extends Model
{
$data = $this->connection->requestAndParse(
'GET',
'subscriber/'.urlencode(trim($subscriberId)),
[
'query' => $this->getQuery()
]
'subscriber/'.urlencode(trim($subscriberId))
);
return new SubscriberEntity($data);
@ -48,8 +43,7 @@ class Subscriber extends Model
'POST',
'subscriber/search',
[
'query' => $this->getQuery(),
'form_params' => [
RequestOptions::FORM_PARAMS => [
'email' => trim($mailAddress)
]
]

Voir le fichier

@ -16,10 +16,7 @@ class Tag extends Model
{
return $this->connection->requestAndParse(
'GET',
'tag',
[
'query' => $this->getQuery()
]
'tag'
);
}