PHP code example of 68publishers / crawler-client-php
1. Go to this page and download the library: Download 68publishers/crawler-client-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
68publishers / crawler-client-php example snippets
use SixtyEightPublishers\CrawlerClient\CrawlerClient;
$client = CrawlerClient::create('<full url to your crawler instance>');
use SixtyEightPublishers\CrawlerClient\CrawlerClient;
$client = CrawlerClient::create('<full url to your crawler instance>', [
'timeout' => 0,
]);
use SixtyEightPublishers\CrawlerClient\CrawlerClient;
use SixtyEightPublishers\CrawlerClient\Authentication\Credentials;
$client = CrawlerClient::create('<full url to your crawler instance>');
$client = $client->withAuthentication(new Credentials('<username>', '<password>'));
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenariosController;
$controller = $client->getController(ScenariosController::class);
/**
* @param int $page
* @param int $limit
* @param array<string, string|array<string>> $filter
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenarioListingResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
*/
$response = $controller->listScenarios(1, 10);
$filteredResponse = $controller->listScenarios(1, 10, [
'name' => 'Test',
'status' => 'failed',
])
/**
* @param string $scenarioId
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenarioResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
* @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException
*/
$response = $controller->getScenario('<id>');
/**
* @param \SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody $requestBody
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenarioResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
*/
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody;
$requestBody = new ScenarioRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
config: [
'scenes' => [ /* ... */ ],
'options' => [ /* ... */ ],
'entrypoint' => [ /* ... */ ],
],
)
$response = $controller->runScenario($requestBody);
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action;
$requestBody = new ScenarioRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
config: (new ScenarioConfig(new Entrypoint('<url>', 'default')))
->withOptions(/* ... */)
->withScene('default', [
new Action('...', [ /* ... */ ])
new Action('...', [ /* ... */ ])
]),
)
$response = $controller->runScenario($requestBody);
/**
* @param \SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody $requestBody
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValidateScenarioResponse
*/
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody;
$requestBody = new ScenarioRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
config: [
'scenes' => [ /* ... */ ],
'options' => [ /* ... */ ],
'entrypoint' => [ /* ... */ ],
],
)
$response = $controller->validateScenario($requestBody);
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action;
$requestBody = new ScenarioRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
config: (new ScenarioConfig(new Entrypoint('<url>', 'default')))
->withOptions(/* ... */)
->withScene('default', [
new Action('...', [ /* ... */ ])
new Action('...', [ /* ... */ ])
]),
)
$response = $controller->validateScenario($requestBody);
/**
* @param string $scenarioId
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\Common\NoContentResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
* @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException
*/
$response = $controller->abortScenario('<id>');
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulersController;
$controller = $client->getController(ScenarioSchedulersController::class);
/**
* @param int $page
* @param int $limit
* @param array<string, string|array<string>> $filter
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerListingResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
*/
$response = $controller->listScenarioSchedulers(1, 10);
$filteredResponse = $controller->listScenarioSchedulers(1, 10, [
'name' => 'Test',
'userId' => '<id>',
])
/**
* @param string $scenarioSchedulerId
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
* @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException
*/
$response = $controller->getScenarioScheduler('<id>');
$etag = $response->getEtag(); # you need Etag for update
/**
* @param \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody $requestBody
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
*/
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody;
$requestBody = new ScenarioSchedulerRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
active: true,
expression: '0 2 * * *',
config: [
'scenes' => [ /* ... */ ],
'options' => [ /* ... */ ],
'entrypoint' => [ /* ... */ ],
],
)
$response = $controller->createScenarioScheduler($requestBody);
$etag = $response->getEtag(); # you need Etag for update
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action;
$requestBody = new ScenarioSchedulerRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
active: true,
expression: '0 2 * * *',
config: (new ScenarioConfig(new Entrypoint('<url>', 'default')))
->withOptions(/* ... */)
->withScene('default', [
new Action('...', [ /* ... */ ])
new Action('...', [ /* ... */ ])
]),
)
$response = $controller->runScenario($requestBody);
$etag = $response->getEtag(); # you need Etag for update
/**
* @param string $scenarioSchedulerId
* @param string $etag
* @param \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody $requestBody
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
* @throws \SixtyEightPublishers\CrawlerClient\Exception\PreconditionFailedException
*/
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody;
$requestBody = new ScenarioSchedulerRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
active: true,
expression: '0 2 * * *',
config: [
'scenes' => [ /* ... */ ],
'options' => [ /* ... */ ],
'entrypoint' => [ /* ... */ ],
],
)
$response = $controller->updateScenarioScheduler('<id>', '<etag>', $requestBody);
$etag = $response->getEtag(); # you need Etag for next update
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action;
$requestBody = new ScenarioSchedulerRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
active: true,
expression: '0 2 * * *',
config: (new ScenarioConfig(new Entrypoint('<url>', 'default')))
->withOptions(/* ... */)
->withScene('default', [
new Action('...', [ /* ... */ ])
new Action('...', [ /* ... */ ])
]),
)
$response = $controller->updateScenarioScheduler('<id>', '<etag>', $requestBody);
$etag = $response->getEtag(); # you need Etag for next update
/**
* @param \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody $requestBody
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ValidateScenarioSchedulerResponse
*/
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody;
$requestBody = new ScenarioSchedulerRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
active: true,
expression: '0 2 * * *',
config: [
'scenes' => [ /* ... */ ],
'options' => [ /* ... */ ],
'entrypoint' => [ /* ... */ ],
],
)
$response = $controller->validateScenarioScheduler($requestBody);
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action;
$requestBody = new ScenarioSchedulerRequestBody(
name: 'My scenario',
flags: ['my_flag' => 'my_flag_value'],
active: true,
expression: '0 2 * * *',
config: (new ScenarioConfig(new Entrypoint('<url>', 'default')))
->withOptions(/* ... */)
->withScene('default', [
new Action('...', [ /* ... */ ])
new Action('...', [ /* ... */ ])
]),
)
$response = $controller->validateScenarioScheduler($requestBody);
/**
* @param string $scenarioSchedulerId
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
* @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException
*/
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody;
# to activate the scenario scheduler:
$response = $controller->activateScenarioScheduler('<id>');
# to deactivate the scenario scheduler:
$response = $controller->deactivateScenarioScheduler('<id>');
/**
* @param string $scenarioSchedulerId
*
* @returns \SixtyEightPublishers\CrawlerClient\Controller\Common\NoContentResponse
*
* @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException
* @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException
*/
$response = $controller->deleteScenarioScheduler('<id>');