Skip to content

Commit

Permalink
Merge pull request #30 from Ardakilic/master
Browse files Browse the repository at this point in the history
Update subscriber by email method added, some example additions done.
  • Loading branch information
twisted1919 authored Nov 19, 2019
2 parents 96c6ea8 + 8fa3a3d commit 32c1d10
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
31 changes: 31 additions & 0 deletions MailWizzApi/Endpoint/ListSubscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
27 changes: 27 additions & 0 deletions examples/list_subscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@
echo '<hr />';
echo '<pre>';
print_r($response->body);
echo '</pre>';

/*===================================================================================*/

// UPDATE EXISTING SUBSCRIBER BY EMAIL
$response = $endpoint->updateByEmail('LIST-UNIQUE-ID', '[email protected]', array(
'EMAIL' => '[email protected]',
'FNAME' => 'John',
'LNAME' => 'Doe Updated'
));

// DISPLAY RESPONSE
echo '<hr />';
echo '<pre>';
print_r($response->body);
echo '</pre>';

/*===================================================================================*/

Expand Down Expand Up @@ -155,6 +171,17 @@
echo '</pre>';
/*===================================================================================*/


// UNSUBSCRIBE existing subscriber from all lists, no email is sent, unsubscribe is silent
$response = $endpoint->unsubscribeByEmailFromAllLists('[email protected]');

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';

/*===================================================================================*/

// DELETE SUBSCRIBER, no email is sent, delete is silent
$response = $endpoint->delete('LIST-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID');

Expand Down

0 comments on commit 32c1d10

Please sign in to comment.