add subscriber endpoint

This commit is contained in:
Daniel Seifert 2024-12-20 23:46:48 +01:00
bovenliggende 7608d39af8
commit e1e08ee313
Getekend door: DanielS
GPG sleutel-ID: 6A513E13AEE66170
2 gewijzigde bestanden met toevoegingen van 78 en 0 verwijderingen

Bestand weergeven

@ -0,0 +1,19 @@
<?php
namespace D3\KlicktippPhpClient\Entities;
use Doctrine\Common\Collections\ArrayCollection;
class Subscriber extends ArrayCollection
{
public function getId(): string
{
return $this->get('id');
}
public function isSubscribed(): bool
{
// ToDo: adjust request
return $this->get('isSubscribed');
}
}

Bestand weergeven

@ -0,0 +1,59 @@
<?php
namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
use D3\KlicktippPhpClient\Exceptions\BaseException;
use GuzzleHttp\Exception\GuzzleException;
class Subscriber extends Model
{
/**
* @throws BaseException|GuzzleException
*/
public function index(): array
{
return $this->connection->requestAndParse(
'GET',
'subscriber',
[
'query' => $this->getQuery()
]
);
}
/**
* @throws BaseException|GuzzleException
*/
public function get(string $subscriberId): SubscriberEntity
{
$data = $this->connection->requestAndParse(
'GET',
'subscriber/'.urlencode(trim($subscriberId)),
[
'query' => $this->getQuery()
]
);
return new SubscriberEntity($data);
}
/**
* @throws BaseException|GuzzleException
*/
public function search(string $mailAddress): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/search',
[
'query' => $this->getQuery(),
'form_params' => [
'email' => trim($mailAddress)
]
]
)
);
}
}