From e1e08ee313638d364bc57b6873a741c43081760a Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 20 Dec 2024 23:46:48 +0100 Subject: [PATCH] add subscriber endpoint --- src/Entities/Subscriber.php | 19 ++++++++++++ src/Resources/Subscriber.php | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/Entities/Subscriber.php create mode 100644 src/Resources/Subscriber.php diff --git a/src/Entities/Subscriber.php b/src/Entities/Subscriber.php new file mode 100644 index 0000000..4c1d880 --- /dev/null +++ b/src/Entities/Subscriber.php @@ -0,0 +1,19 @@ +get('id'); + } + + public function isSubscribed(): bool + { + // ToDo: adjust request + return $this->get('isSubscribed'); + } +} \ No newline at end of file diff --git a/src/Resources/Subscriber.php b/src/Resources/Subscriber.php new file mode 100644 index 0000000..69ba496 --- /dev/null +++ b/src/Resources/Subscriber.php @@ -0,0 +1,59 @@ +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) + ] + ] + ) + ); + } +}