From da7e3bf38bb3800c0365489f1f035e352c24c595 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 22 Dec 2024 13:54:42 +0100 Subject: [PATCH] complete endpoint tasks --- README.md | 2 +- src/Resources/Subscriber.php | 84 ++++++++++++++++++++++++++++++++++++ src/Resources/Tag.php | 48 +++++++++++++++++++-- 3 files changed, 129 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 44ed92f..98b2f27 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,4 @@ $subscriber = $klicktipp->subscriber()->search($subscriberId); |--------------------------------------------------------------------------------------|-------------------------| | account | :ballot_box_with_check: | | subscriber | :ballot_box_with_check: | -| tag | :white_check_mark: | +| tag | :ballot_box_with_check: | diff --git a/src/Resources/Subscriber.php b/src/Resources/Subscriber.php index f98f4d5..106c08b 100644 --- a/src/Resources/Subscriber.php +++ b/src/Resources/Subscriber.php @@ -50,4 +50,88 @@ class Subscriber extends Model ) ); } + + /** + * @throws BaseException|GuzzleException + */ + public function subscribe( + string $mailAddress, + string $listId, + string $tagId, + array $fields, + string $smsNumber + ): string + { + return current( + $this->connection->requestAndParse( + 'POST', + 'subscriber', + [ + RequestOptions::FORM_PARAMS => [ + 'email' => trim($mailAddress), + 'listid' => trim($listId), + 'tagid' => trim($tagId), + 'fields' => array_filter($fields), + 'smsnumber' => trim($smsNumber), + ] + ] + ) + ); + } + + /** + * @throws BaseException|GuzzleException + */ + public function unsubscribe(string $mailAddress): string + { + return current( + $this->connection->requestAndParse( + 'POST', + 'subscriber/unsubscribe', + [ + RequestOptions::FORM_PARAMS => [ + 'email' => trim($mailAddress) + ] + ] + ) + ); + } + + /** + * @throws BaseException|GuzzleException + */ + public function tag(string $mailAddress, string $tagId): string + { + return current( + $this->connection->requestAndParse( + 'POST', + 'subscriber/tag', + [ + RequestOptions::FORM_PARAMS => [ + 'email' => trim($mailAddress), + 'tagid' => trim($tagId) + ] + ] + ) + ); + } + + /** + * @throws BaseException|GuzzleException + */ + public function untag(string $mailAddress, string $tagId): string + { + return current( + $this->connection->requestAndParse( + 'POST', + 'subscriber/search', + [ + RequestOptions::FORM_PARAMS => [ + 'email' => trim($mailAddress), + 'tagid' => trim($tagId) + ] + ] + ) + ); + } } diff --git a/src/Resources/Tag.php b/src/Resources/Tag.php index 39706c2..182ad71 100644 --- a/src/Resources/Tag.php +++ b/src/Resources/Tag.php @@ -27,12 +27,52 @@ class Tag extends Model { $data = $this->connection->requestAndParse( 'GET', - 'tag/'.urlencode(trim($tagId)), - [ - RequestOptions::QUERY => $this->getQuery() - ] + 'tag/'.urlencode(trim($tagId)) ); return new TagEntity($data); } + + /** + * @throws BaseException|GuzzleException + */ + public function create(string $name): array + { + return $this->connection->requestAndParse( + 'POST', + 'tag/', + [ + RequestOptions::FORM_PARAMS => [ + 'name' => trim($name) + ] + ] + ); + } + + /** + * @throws BaseException|GuzzleException + */ + public function update(string $tagId, string $newName): array + { + return $this->connection->requestAndParse( + 'PUT', + 'tag/'.urlencode(trim($tagId)), + [ + RequestOptions::FORM_PARAMS => [ + 'name' => trim($newName) + ] + ] + ); + } + + /** + * @throws BaseException|GuzzleException + */ + public function delete(string $tagId): array + { + return $this->connection->requestAndParse( + 'DELETE', + 'tag/'.urlencode(trim($tagId)) + ); + } }