Files
crawlshot/src/ShotJobBuilder.php
2025-08-11 02:35:35 +08:00

77 lines
1.8 KiB
PHP

<?php
namespace Crawlshot\Laravel;
class ShotJobBuilder
{
protected CrawlshotClient $client;
protected string $url;
protected array $options = [];
public function __construct(CrawlshotClient $client, string $url)
{
$this->client = $client;
$this->url = $url;
}
public function webhookUrl(string $webhookUrl): self
{
$this->options['webhook_url'] = $webhookUrl;
return $this;
}
public function webhookEventsFilter(array $events): self
{
$this->options['webhook_events_filter'] = $events;
return $this;
}
public function viewportSize(int $width, int $height): self
{
$this->options['viewport_width'] = $width;
$this->options['viewport_height'] = $height;
return $this;
}
public function quality(int $quality): self
{
$this->options['quality'] = $quality;
return $this;
}
public function timeout(int $seconds): self
{
$this->options['timeout'] = $seconds;
return $this;
}
public function delay(int $milliseconds): self
{
$this->options['delay'] = $milliseconds;
return $this;
}
public function blockAds(bool $block = true): self
{
$this->options['block_ads'] = $block;
return $this;
}
public function blockCookieBanners(bool $block = true): self
{
$this->options['block_cookie_banners'] = $block;
return $this;
}
public function blockTrackers(bool $block = true): self
{
$this->options['block_trackers'] = $block;
return $this;
}
public function create(): ShotResponse
{
$data = $this->client->createShot($this->url, $this->options);
return new ShotResponse($data, $this->client);
}
}