Skip to main content

scrapfly_sdk/
enums.rs

1//! Strongly-typed enums mirroring `sdk/go/enums.go`.
2//!
3//! Every enum serializes to its lowercase wire-format string via `serde(rename_all = ...)`.
4
5use serde::{Deserialize, Serialize};
6
7/// Simulated vision deficiency for the screenshot API.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub enum VisionDeficiencyType {
11    /// No simulated deficiency.
12    None,
13    /// Red-green color blindness (missing green cones).
14    Deuteranopia,
15    /// Red-green color blindness (missing red cones).
16    Protanopia,
17    /// Blue-yellow color blindness.
18    Tritanopia,
19    /// Total color blindness.
20    Achromatopsia,
21    /// Blurred vision simulation.
22    BlurredVision,
23    /// Reduced contrast simulation.
24    ReducedContrast,
25}
26
27impl VisionDeficiencyType {
28    /// Wire-format string.
29    pub fn as_str(&self) -> &'static str {
30        match self {
31            Self::None => "none",
32            Self::Deuteranopia => "deuteranopia",
33            Self::Protanopia => "protanopia",
34            Self::Tritanopia => "tritanopia",
35            Self::Achromatopsia => "achromatopsia",
36            Self::BlurredVision => "blurredVision",
37            Self::ReducedContrast => "reducedContrast",
38        }
39    }
40}
41
42/// AI extraction model catalog.
43///
44/// See <https://scrapfly.io/docs/extraction-api/automatic-ai#models>.
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
46#[serde(rename_all = "snake_case")]
47pub enum ExtractionModel {
48    /// Article content.
49    Article,
50    /// Event listing.
51    Event,
52    /// Food recipe.
53    FoodRecipe,
54    /// Hotel page.
55    Hotel,
56    /// Hotel listing page.
57    HotelListing,
58    /// Job listing.
59    JobListing,
60    /// Job posting.
61    JobPosting,
62    /// Organization.
63    Organization,
64    /// Product page.
65    Product,
66    /// Product listing.
67    ProductListing,
68    /// Real-estate property.
69    RealEstateProperty,
70    /// Real-estate property listing.
71    RealEstatePropertyListing,
72    /// Review list.
73    ReviewList,
74    /// Search engine results page.
75    SearchEngineResults,
76    /// Social media post.
77    SocialMediaPost,
78    /// Software listing.
79    Software,
80    /// Stock quote.
81    Stock,
82    /// Vehicle ad.
83    VehicleAd,
84    /// Vehicle ad listing.
85    VehicleAdListing,
86}
87
88impl ExtractionModel {
89    /// Wire-format string.
90    pub fn as_str(&self) -> &'static str {
91        match self {
92            Self::Article => "article",
93            Self::Event => "event",
94            Self::FoodRecipe => "food_recipe",
95            Self::Hotel => "hotel",
96            Self::HotelListing => "hotel_listing",
97            Self::JobListing => "job_listing",
98            Self::JobPosting => "job_posting",
99            Self::Organization => "organization",
100            Self::Product => "product",
101            Self::ProductListing => "product_listing",
102            Self::RealEstateProperty => "real_estate_property",
103            Self::RealEstatePropertyListing => "real_estate_property_listing",
104            Self::ReviewList => "review_list",
105            Self::SearchEngineResults => "search_engine_results",
106            Self::SocialMediaPost => "social_media_post",
107            Self::Software => "software",
108            Self::Stock => "stock",
109            Self::VehicleAd => "vehicle_ad",
110            Self::VehicleAdListing => "vehicle_ad_listing",
111        }
112    }
113}
114
115/// Proxy pool catalog.
116#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
117#[serde(rename_all = "snake_case")]
118pub enum ProxyPool {
119    /// Data-center proxies (cheaper, faster, easier to detect).
120    PublicDatacenterPool,
121    /// Residential proxies (more expensive, harder to detect).
122    PublicResidentialPool,
123}
124
125impl ProxyPool {
126    /// Wire-format string.
127    pub fn as_str(&self) -> &'static str {
128        match self {
129            Self::PublicDatacenterPool => "public_datacenter_pool",
130            Self::PublicResidentialPool => "public_residential_pool",
131        }
132    }
133}
134
135/// Screenshot capture flags.
136#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
137#[serde(rename_all = "snake_case")]
138pub enum ScreenshotFlag {
139    /// Load images (otherwise blocked for performance).
140    LoadImages,
141    /// Render in dark mode.
142    DarkMode,
143    /// Block cookie/consent banners.
144    BlockBanners,
145    /// Use print-media CSS.
146    PrintMediaFormat,
147    /// Request higher-quality output.
148    HighQuality,
149}
150
151impl ScreenshotFlag {
152    /// Wire-format string.
153    pub fn as_str(&self) -> &'static str {
154        match self {
155            Self::LoadImages => "load_images",
156            Self::DarkMode => "dark_mode",
157            Self::BlockBanners => "block_banners",
158            Self::PrintMediaFormat => "print_media_format",
159            Self::HighQuality => "high_quality",
160        }
161    }
162}
163
164/// Screenshot image format.
165#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
166#[serde(rename_all = "lowercase")]
167pub enum ScreenshotFormat {
168    /// JPEG output.
169    Jpg,
170    /// PNG output.
171    Png,
172    /// WebP output.
173    Webp,
174    /// GIF output.
175    Gif,
176}
177
178impl ScreenshotFormat {
179    /// Wire-format string.
180    pub fn as_str(&self) -> &'static str {
181        match self {
182            Self::Jpg => "jpg",
183            Self::Png => "png",
184            Self::Webp => "webp",
185            Self::Gif => "gif",
186        }
187    }
188}
189
190/// Screenshot legacy option flags (distinct from `ScreenshotFlag` which
191/// applies to the inline screenshots on a scrape).
192#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
193#[serde(rename_all = "snake_case")]
194pub enum ScreenshotOption {
195    /// Load images.
196    LoadImages,
197    /// Render in dark mode.
198    DarkMode,
199    /// Block cookie banners.
200    BlockBanners,
201    /// Print-media CSS.
202    PrintMediaFormat,
203}
204
205impl ScreenshotOption {
206    /// Wire-format string.
207    pub fn as_str(&self) -> &'static str {
208        match self {
209            Self::LoadImages => "load_images",
210            Self::DarkMode => "dark_mode",
211            Self::BlockBanners => "block_banners",
212            Self::PrintMediaFormat => "print_media_format",
213        }
214    }
215}
216
217/// Scrape output format.
218#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
219#[serde(rename_all = "snake_case")]
220pub enum Format {
221    /// Structured JSON.
222    Json,
223    /// Plain text (HTML stripped).
224    Text,
225    /// Markdown.
226    Markdown,
227    /// Cleaned/normalized HTML.
228    CleanHtml,
229    /// Raw HTML.
230    Raw,
231}
232
233impl Format {
234    /// Wire-format string.
235    pub fn as_str(&self) -> &'static str {
236        match self {
237            Self::Json => "json",
238            Self::Text => "text",
239            Self::Markdown => "markdown",
240            Self::CleanHtml => "clean_html",
241            Self::Raw => "raw",
242        }
243    }
244}
245
246/// Additional options combinable with [`Format`].
247#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
248#[serde(rename_all = "snake_case")]
249pub enum FormatOption {
250    /// Strip links.
251    NoLinks,
252    /// Strip images.
253    NoImages,
254    /// Keep only the main content.
255    OnlyContent,
256}
257
258impl FormatOption {
259    /// Wire-format string.
260    pub fn as_str(&self) -> &'static str {
261        match self {
262            Self::NoLinks => "no_links",
263            Self::NoImages => "no_images",
264            Self::OnlyContent => "only_content",
265        }
266    }
267}
268
269/// HTTP methods the scrape endpoint accepts.
270#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
271#[serde(rename_all = "UPPERCASE")]
272pub enum HttpMethod {
273    /// `GET`.
274    Get,
275    /// `POST`.
276    Post,
277    /// `PUT`.
278    Put,
279    /// `PATCH`.
280    Patch,
281    /// `OPTIONS`.
282    Options,
283    /// `HEAD`.
284    Head,
285}
286
287impl HttpMethod {
288    /// Wire-format string.
289    pub fn as_str(&self) -> &'static str {
290        match self {
291            Self::Get => "GET",
292            Self::Post => "POST",
293            Self::Put => "PUT",
294            Self::Patch => "PATCH",
295            Self::Options => "OPTIONS",
296            Self::Head => "HEAD",
297        }
298    }
299}
300
301/// Document-body compression format for the extraction endpoint.
302#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
303#[serde(rename_all = "lowercase")]
304pub enum CompressionFormat {
305    /// gzip.
306    Gzip,
307    /// zstd.
308    Zstd,
309    /// deflate.
310    Deflate,
311}
312
313impl CompressionFormat {
314    /// Wire-format string.
315    pub fn as_str(&self) -> &'static str {
316        match self {
317            Self::Gzip => "gzip",
318            Self::Zstd => "zstd",
319            Self::Deflate => "deflate",
320        }
321    }
322}
323
324/// Content formats the crawler API supports.
325#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
326#[serde(rename_all = "snake_case")]
327pub enum CrawlerContentFormat {
328    /// Raw HTML.
329    Html,
330    /// Cleaned HTML.
331    CleanHtml,
332    /// Markdown.
333    Markdown,
334    /// Plain text.
335    Text,
336    /// Structured JSON.
337    Json,
338    /// Extracted data (AI template).
339    ExtractedData,
340    /// Page metadata.
341    PageMetadata,
342}
343
344impl CrawlerContentFormat {
345    /// Wire-format string.
346    pub fn as_str(&self) -> &'static str {
347        match self {
348            Self::Html => "html",
349            Self::CleanHtml => "clean_html",
350            Self::Markdown => "markdown",
351            Self::Text => "text",
352            Self::Json => "json",
353            Self::ExtractedData => "extracted_data",
354            Self::PageMetadata => "page_metadata",
355        }
356    }
357}
358
359/// Crawler webhook events.
360#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
361#[serde(rename_all = "snake_case")]
362pub enum CrawlerWebhookEvent {
363    /// `crawler_started`.
364    CrawlerStarted,
365    /// `crawler_url_visited`.
366    CrawlerUrlVisited,
367    /// `crawler_url_skipped`.
368    CrawlerUrlSkipped,
369    /// `crawler_url_discovered`.
370    CrawlerUrlDiscovered,
371    /// `crawler_url_failed`.
372    CrawlerUrlFailed,
373    /// `crawler_stopped`.
374    CrawlerStopped,
375    /// `crawler_cancelled`.
376    CrawlerCancelled,
377    /// `crawler_finished`.
378    CrawlerFinished,
379}
380
381impl CrawlerWebhookEvent {
382    /// Wire-format string.
383    pub fn as_str(&self) -> &'static str {
384        match self {
385            Self::CrawlerStarted => "crawler_started",
386            Self::CrawlerUrlVisited => "crawler_url_visited",
387            Self::CrawlerUrlSkipped => "crawler_url_skipped",
388            Self::CrawlerUrlDiscovered => "crawler_url_discovered",
389            Self::CrawlerUrlFailed => "crawler_url_failed",
390            Self::CrawlerStopped => "crawler_stopped",
391            Self::CrawlerCancelled => "crawler_cancelled",
392            Self::CrawlerFinished => "crawler_finished",
393        }
394    }
395}