andrey-helldar/blacklist-client

This package is abandoned and no longer maintained. The author suggests using the johannebert/laravel-spam-protector package instead.

The blacklist client package for connecting to the Blacklist Server

v2.2.1 2020-12-30 19:48 UTC

README

The blacklist client package for connecting to the Blacklist Server.

blacklist client

StyleCI Total Downloads Latest Stable Version Latest Unstable Version License

Content

Installation

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"

Using

First look at the config.

check / exists

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;
        }
    }
}

store

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

License

This package is released under the MIT License.