From b080b1a64c0d2c4eb043e5eebdcedfbc905bf197 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sat, 21 Dec 2024 19:25:33 +0100 Subject: [PATCH] clean up requests from unused options --- src/Resources/Account.php | 7 ++-- src/Resources/Model.php | 65 ------------------------------------ src/Resources/Subscriber.php | 14 +++----- src/Resources/Tag.php | 5 +-- 4 files changed, 8 insertions(+), 83 deletions(-) diff --git a/src/Resources/Account.php b/src/Resources/Account.php index 7677959..4ba2a07 100644 --- a/src/Resources/Account.php +++ b/src/Resources/Account.php @@ -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); diff --git a/src/Resources/Model.php b/src/Resources/Model.php index 262af67..fbc52d0 100644 --- a/src/Resources/Model.php +++ b/src/Resources/Model.php @@ -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; - } } diff --git a/src/Resources/Subscriber.php b/src/Resources/Subscriber.php index 69ba496..f98f4d5 100644 --- a/src/Resources/Subscriber.php +++ b/src/Resources/Subscriber.php @@ -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) ] ] diff --git a/src/Resources/Tag.php b/src/Resources/Tag.php index 282ff55..39706c2 100644 --- a/src/Resources/Tag.php +++ b/src/Resources/Tag.php @@ -16,10 +16,7 @@ class Tag extends Model { return $this->connection->requestAndParse( 'GET', - 'tag', - [ - 'query' => $this->getQuery() - ] + 'tag' ); }