From 8fa3a3d32f685d0c6a6a33d7e6c2212e929470f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20K=C4=B1l=C4=B1=C3=A7da=C4=9F=C4=B1?= Date: Thu, 14 Nov 2019 18:45:04 +0300 Subject: [PATCH] Update by email method added, some example additions done. --- MailWizzApi/Endpoint/ListSubscribers.php | 31 ++++++++++++++++++++++++ examples/list_subscribers.php | 27 +++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/MailWizzApi/Endpoint/ListSubscribers.php b/MailWizzApi/Endpoint/ListSubscribers.php index 6318c50..6f1575f 100644 --- a/MailWizzApi/Endpoint/ListSubscribers.php +++ b/MailWizzApi/Endpoint/ListSubscribers.php @@ -120,6 +120,37 @@ public function update($listUid, $subscriberUid, array $data) return $response = $client->request(); } + /** + * Update existing subscriber by email address + * + * @param string $listUid + * @param string emailAddress + * @param array $data + * @return MailWizzApi_Http_Response + */ + public function updateByEmail($listUid, $emailAddress, array $data) + { + $response = $this->emailSearch($listUid, $emailAddress); + + // the request failed. + if ($response->isCurlError) { + return $response; + } + + $bodyData = $response->body->itemAt('data'); + + // subscriber not found. + if ($response->isError && $response->httpCode == 404) { + return $response; + } + + if (empty($bodyData['subscriber_uid'])) { + return $response; + } + + return $this->update($listUid, $bodyData['subscriber_uid'], $data); + } + /** * Unsubscribe existing subscriber from given list * diff --git a/examples/list_subscribers.php b/examples/list_subscribers.php index d90a863..b2186da 100644 --- a/examples/list_subscribers.php +++ b/examples/list_subscribers.php @@ -119,6 +119,22 @@ echo '
'; echo '
';
 print_r($response->body);
+echo '
'; + +/*===================================================================================*/ + +// UPDATE EXISTING SUBSCRIBER BY EMAIL +$response = $endpoint->updateByEmail('LIST-UNIQUE-ID', 'john@doe.com', array( + 'EMAIL' => 'john.doe@doe.com', + 'FNAME' => 'John', + 'LNAME' => 'Doe Updated' +)); + +// DISPLAY RESPONSE +echo '
'; +echo '
';
+print_r($response->body);
+echo '
'; /*===================================================================================*/ @@ -155,6 +171,17 @@ echo ''; /*===================================================================================*/ + +// UNSUBSCRIBE existing subscriber from all lists, no email is sent, unsubscribe is silent +$response = $endpoint->unsubscribeByEmailFromAllLists('john@doe.com'); + +// DISPLAY RESPONSE +echo '
';
+print_r($response->body);
+echo '
'; + +/*===================================================================================*/ + // DELETE SUBSCRIBER, no email is sent, delete is silent $response = $endpoint->delete('LIST-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID');