clean up requests from unused options
This commit is contained in:
bovenliggende
58a20c3387
commit
b080b1a64c
@ -4,6 +4,7 @@ namespace D3\KlicktippPhpClient\Resources;
|
|||||||
|
|
||||||
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use GuzzleHttp\RequestOptions;
|
||||||
|
|
||||||
class Account extends Model
|
class Account extends Model
|
||||||
{
|
{
|
||||||
@ -16,8 +17,7 @@ class Account extends Model
|
|||||||
'POST',
|
'POST',
|
||||||
'account/login',
|
'account/login',
|
||||||
[
|
[
|
||||||
'query' => $this->getQuery(),
|
RequestOptions::FORM_PARAMS => [
|
||||||
'form_params' => [
|
|
||||||
'username' => $this->connection->getClientKey(),
|
'username' => $this->connection->getClientKey(),
|
||||||
'password' => $this->connection->getSecretKey()
|
'password' => $this->connection->getSecretKey()
|
||||||
]
|
]
|
||||||
@ -34,8 +34,7 @@ class Account extends Model
|
|||||||
{
|
{
|
||||||
$response = $this->connection->requestAndParse(
|
$response = $this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'account/logout',
|
'account/logout'
|
||||||
['query' => $this->getQuery()]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (bool) current($response);
|
return (bool) current($response);
|
||||||
|
@ -3,78 +3,13 @@
|
|||||||
namespace D3\KlicktippPhpClient\Resources;
|
namespace D3\KlicktippPhpClient\Resources;
|
||||||
|
|
||||||
use D3\KlicktippPhpClient\Connection;
|
use D3\KlicktippPhpClient\Connection;
|
||||||
use GuzzleHttp\RequestOptions;
|
|
||||||
|
|
||||||
abstract class Model
|
abstract class Model
|
||||||
{
|
{
|
||||||
protected Connection $connection;
|
protected Connection $connection;
|
||||||
|
|
||||||
protected array $filters = [];
|
|
||||||
|
|
||||||
protected ?int $limit = null;
|
|
||||||
|
|
||||||
protected ?int $offset = null;
|
|
||||||
|
|
||||||
protected array $query = [];
|
|
||||||
|
|
||||||
public function __construct(Connection $connection)
|
public function __construct(Connection $connection)
|
||||||
{
|
{
|
||||||
$this->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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace D3\KlicktippPhpClient\Resources;
|
|||||||
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
|
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
|
||||||
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use GuzzleHttp\RequestOptions;
|
||||||
|
|
||||||
class Subscriber extends Model
|
class Subscriber extends Model
|
||||||
{
|
{
|
||||||
@ -15,10 +16,7 @@ class Subscriber extends Model
|
|||||||
{
|
{
|
||||||
return $this->connection->requestAndParse(
|
return $this->connection->requestAndParse(
|
||||||
'GET',
|
'GET',
|
||||||
'subscriber',
|
'subscriber'
|
||||||
[
|
|
||||||
'query' => $this->getQuery()
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,10 +27,7 @@ class Subscriber extends Model
|
|||||||
{
|
{
|
||||||
$data = $this->connection->requestAndParse(
|
$data = $this->connection->requestAndParse(
|
||||||
'GET',
|
'GET',
|
||||||
'subscriber/'.urlencode(trim($subscriberId)),
|
'subscriber/'.urlencode(trim($subscriberId))
|
||||||
[
|
|
||||||
'query' => $this->getQuery()
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return new SubscriberEntity($data);
|
return new SubscriberEntity($data);
|
||||||
@ -48,8 +43,7 @@ class Subscriber extends Model
|
|||||||
'POST',
|
'POST',
|
||||||
'subscriber/search',
|
'subscriber/search',
|
||||||
[
|
[
|
||||||
'query' => $this->getQuery(),
|
RequestOptions::FORM_PARAMS => [
|
||||||
'form_params' => [
|
|
||||||
'email' => trim($mailAddress)
|
'email' => trim($mailAddress)
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
@ -16,10 +16,7 @@ class Tag extends Model
|
|||||||
{
|
{
|
||||||
return $this->connection->requestAndParse(
|
return $this->connection->requestAndParse(
|
||||||
'GET',
|
'GET',
|
||||||
'tag',
|
'tag'
|
||||||
[
|
|
||||||
'query' => $this->getQuery()
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
x
Verwijs in nieuw issue
Block a user