kafkiansky / textru
Library for text.ru api interaction.
Installs: 2 015
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2020-04-07 03:45:11 UTC
README
Requirements
- PHP 7.2 or higher
- GuzzleHttp 6.3 or higher
Installation
Use Composer for install:
composer require kafkiansky/textruapi
Usage
Simple create object of class TextruInteractor with two arguments:
- Send text for checking, put in
sendForVerification()
methodQueuedText
object with needed arguments, e.g. Text, CallbackUrl, etc. All arguments except text are not required.
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use Kafkiansky\Textru\Model\CallbackUrl; use Kafkiansky\Textru\Model\QueuedText; use Kafkiansky\Textru\Model\Text; use Kafkiansky\Textru\Model\UserKey; use Kafkiansky\Textru\ReadModel\QueuedTextResponse; use Kafkiansky\Textru\TextruInteractor; use Kafkiansky\Textru\Model\ResultFor; use GuzzleHttp\Client; use Kafkiansky\Textru\Model\JsonVisible; use Kafkiansky\Textru\ReadModel\CheckedResult; $userKey = 'userKeyFromTextRuApi'; $interactor = new TextruInteractor(new Client(), new UserKey($userKey)); /** @var QueuedTextResponse $queuedTextResponse */ $queuedTextResponse = $interactor->sendForVerification(new QueuedText(new Text('your_text'), new CallbackUrl('your_url'))); $textUid = $queuedTextResponse->getTextUid(); echo $textUid; // 48934969
- After that use
getResultFor
method withResultFor
object
<?php /** @var \Kafkiansky\Textru\ReadModel\CheckedResult $checkedResult */ $checkedResult = $interactor->getResultFor(new ResultFor($textUid, JsonVisible::detail())); var_dump($checkedResult->getDateCheck()); // DateTimeImmutable object echo $checkedResult->getUnique(); // 0.00 print_r($checkedResult->getUrls()); // plagiat urls echo $checkedResult->getCountCharsWithoutSpace(); // 327 echo $checkedResult->getCountCharsWithSpace(); // 383 echo $checkedResult->getCountWords(); // 122 echo $checkedResult->getSpamPercent(); // 15 echo $checkedResult->getWaterPercent(); // 41 # Text.ru return result after time (10-30 m), not immediately. # To check that result exist, simple use isChecked() method of $checkedResult object, e.g: if ($checkedResult->isChecked()) { // store in database }
- Get account size symbols info
<?php echo $interactor->getRemainingChars(); // 4444