andrey-helldar / blacklist-server
The blacklist server package
Requires
- php: ^7.1.3|^8.0
- ext-json: *
- andrey-helldar/api-response: ^4.3
- andrey-helldar/blacklist-core: ^2.0
- illuminate/contracts: ^5.6|^6.0|^7.0|^8.0
- illuminate/database: ^5.6|^6.0|^7.0|^8.0
- illuminate/support: ^5.6|^6.0|^7.0|^8.0
- illuminate/validation: ^5.6|^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^3.5|^4.0
- phpunit/phpunit: ^7.0|^8.0
Suggests
- andrey-helldar/blacklist-client: The blacklist client package for connecting to the Blacklist Server
- barryvdh/laravel-cors: Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
README
Content
Installation
To get the latest version of Laravel Blacklist Server, simply require the project using Composer:
composer require andrey-helldar/blacklist-server
Instead, you may of course manually update your require block and run composer update
if you so choose:
{ "require": { "andrey-helldar/blacklist-server": "^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.
After installation, your application will accept incoming requests for the creation and verification of spammers in stop lists. To do this, you can use packet andrey-helldar/blacklist-client or simply send a POST or GET request to address https://<your-site.com>/api/blacklist
, passing the necessary parameters:
field | required | comment |
---|---|---|
type | sometimes | available is: "email", "url", "ip", "phone" |
value | yes | string |
In order for the server part to be able to add or check spammers on its own, you can install package andrey-helldar/blacklist-client on it or go the more complicated way using facades:
use Helldar\BlacklistServer\Facades\Blacklist; return Blacklist::store('foo@example.com', 'email') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('foo@example.com') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('foo@example.com') : bool return Blacklist::store('http://example.com', 'url') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('http://example.com') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('http://example.com') : bool return Blacklist::store('192.168.1.1', 'ip') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('192.168.1.1') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('192.168.1.1') : bool return Blacklist::store('+0 (000) 000-00-00', 'phone') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('+0 (000) 000-00-00') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('+0 (000) 000-00-00') : bool
However, we recommend using the client.
store
When sending a POST request to the address of server https://<your-site>/api/blacklist
with the correct data.
Foe example:
POST https://<your-site>/api/blacklist
Content-Type: application/json
{
"type": "email",
"value": "foo@example.com"
}
It will return a JSON object:
{ "type": "email", "value": "foo@example.com", "expired_at": "2024-05-11 16:41:04", "created_at": "2019-09-14 11:45:04", "updated_at": "2019-09-14 16:41:04" }
If the data being sent is filled incorrectly, the server will return an error with code 400 and the following JSON object:
{ "error": { "code": 400, "msg": ["<message of the error>"] }, "request": { // incoming data } }
For example:
{ "error": { "code": 400, "msg": ["The type must be one of email, url, phone or ip, null given."] }, "request": { "type": "foo", "value": "foo@example.com" } }
exists
If the requested data is not found in the database, the site will return a 200 code:
"ok"
If the requested data is found in the database, the site will return the code 423 (Locked):
{ "error": { "code": 423, "msg": ["Checked email foo@example.com was found in our database."] }, "request": { "value": "foo@example.com" } }
If the data being sent is filled incorrectly, the server will return an error with code 400 and the following JSON object. For example:
{ "error": { "code": 400, "msg": ["The value field is required."] }, "request": {} } { "error": { "code": 400, "msg": ["The type must be one of email, url, phone or ip, null given."] }, "request": { "type": "foo", "value": "foo@example.com" } }
License
This package is released under the MIT License.