The blacklist client package for connecting to the Blacklist Server.
To get the latest version of Laravel Blacklist Client, simply require the project using Composer:
composer require andrey-helldar/blacklist-client
Instead, you may of course manually update your require block and run composer update
if you so choose:
{
"require": {
"andrey-helldar/blacklist-client": "^2.0"
}
}
Now, you can also publish the config file to change implementations (ie. interface to specific class):
php artisan vendor:publish --provider="Helldar\BlacklistClient\ServiceProvider"
First look at the config.
To check the existence of a spammer in the database, you need to transfer the data type and value:
/*
* DATABASE
* foo@example.com - exists
* bar@example.com - not exists
*/
use Helldar\BlacklistClient\Facades\Client;
return Client::check('http://example.com'); // false
return Client::check('192.168.1.1'); // false
return Client::check('+0 (000) 000-00-00'); // false
return Client::check('foo@example.com');
/* GuzzleHttp\Exception\ClientException with 423 code and content:
*
* {"error":{"code":400,"msg":["Checked foo@example.com was found in our database.]}}
*/
For example:
use GuzzleHttp\Exception\ClientException;
use Helldar\BlacklistClient\Facades\Client;
class Foo
{
public function store(array $data)
{
if (! $this->isSpammer($data['email'])) {
// storing data
}
}
private function isSpammer(string $value): bool
{
try {
return Client::check($value);
}
catch (ClientException $exception) {
return true;
}
}
}
To storing a spammer to the database, use the method store
of the facade Client
:
use Helldar\BlacklistClient\Facades\Client;
return Client::store('foo@example.com', 'email');
return Client::store('http://example.com', 'url');
return Client::store('192.168.1.1', 'ip');
return Client::store('+0 (000) 000-00-00', 'phone');
For example:
use Helldar\BlacklistClient\Facades\Client;
$item = Client::store('foo@example.com', 'email');
return $item->expired_at; // 2019-09-27 23:25:27
This package is released under the MIT License.