Skip to content

Commit

Permalink
Merge pull request #18 from nikolayevalexey/master
Browse files Browse the repository at this point in the history
New Sendy API Integration to Fully Remove Users from List
  • Loading branch information
hocza authored Jan 15, 2024
2 parents d1e7b8e + 4fc6556 commit 0e1b53e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Sendy.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,46 @@ public function unsubscribe($email)
return $notice;
}

/**
* Method to delete a user from a list
*
* @param $email
*
* @return array
*/
public function delete($email)
{
$result = $this->buildAndSend('/api/subscribers/delete.php', ['email' => $email]);

/**
* Prepare the array to return
*/
$notice = [
'status' => true,
'message' => '',
];

/**
* Handle results
*/
switch (strval($result)) {
case '1':
$notice['message'] = 'Deleted';

break;
default:
$notice = [
'status' => false,
'message' => $result
];

break;
}

return $notice;
}


/**
* Method to get the current status of a subscriber.
* Success: Subscribed, Unsubscribed, Unconfirmed, Bounced, Soft bounced, Complained
Expand Down
18 changes: 18 additions & 0 deletions tests/SendyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,22 @@ public function testUpdate()
$this->assertEquals(true, $subscriber['status']);
$this->assertEquals('Already subscribed.', $subscriber['message']);
}

public function testDelete()
{
$subscriber = new Sendy($this->config);
$subscriber->subscribe([
'name' => 'Mark',
'email' => '[email protected]',
]);
$currentStatus = $subscriber->status('[email protected]');
$this->assertEquals('Subscribed', $currentStatus);

$deleteResult = $subscriber->delete('[email protected]');
$this->assertEquals(true, $deleteResult['status']);

$currentStatus = $subscriber->status('[email protected]');
$this->assertEquals('Email does not exist in list', $currentStatus);

}
}

0 comments on commit 0e1b53e

Please sign in to comment.