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    /// Tor network egress for .onion hidden services and OSINT.
124    PublicTorPool,
125}
126
127impl ProxyPool {
128    /// Wire-format string.
129    pub fn as_str(&self) -> &'static str {
130        match self {
131            Self::PublicDatacenterPool => "public_datacenter_pool",
132            Self::PublicResidentialPool => "public_residential_pool",
133            Self::PublicTorPool => "public_tor_pool",
134        }
135    }
136}
137
138/// Screenshot capture flags.
139#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
140#[serde(rename_all = "snake_case")]
141pub enum ScreenshotFlag {
142    /// Load images (otherwise blocked for performance).
143    LoadImages,
144    /// Render in dark mode.
145    DarkMode,
146    /// Block cookie/consent banners.
147    BlockBanners,
148    /// Use print-media CSS.
149    PrintMediaFormat,
150    /// Request higher-quality output.
151    HighQuality,
152}
153
154impl ScreenshotFlag {
155    /// Wire-format string.
156    pub fn as_str(&self) -> &'static str {
157        match self {
158            Self::LoadImages => "load_images",
159            Self::DarkMode => "dark_mode",
160            Self::BlockBanners => "block_banners",
161            Self::PrintMediaFormat => "print_media_format",
162            Self::HighQuality => "high_quality",
163        }
164    }
165}
166
167/// Screenshot image format.
168#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
169#[serde(rename_all = "lowercase")]
170pub enum ScreenshotFormat {
171    /// JPEG output.
172    Jpg,
173    /// PNG output.
174    Png,
175    /// WebP output.
176    Webp,
177    /// GIF output.
178    Gif,
179}
180
181impl ScreenshotFormat {
182    /// Wire-format string.
183    pub fn as_str(&self) -> &'static str {
184        match self {
185            Self::Jpg => "jpg",
186            Self::Png => "png",
187            Self::Webp => "webp",
188            Self::Gif => "gif",
189        }
190    }
191}
192
193/// Screenshot legacy option flags (distinct from `ScreenshotFlag` which
194/// applies to the inline screenshots on a scrape).
195#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
196#[serde(rename_all = "snake_case")]
197pub enum ScreenshotOption {
198    /// Load images.
199    LoadImages,
200    /// Render in dark mode.
201    DarkMode,
202    /// Block cookie banners.
203    BlockBanners,
204    /// Print-media CSS.
205    PrintMediaFormat,
206}
207
208impl ScreenshotOption {
209    /// Wire-format string.
210    pub fn as_str(&self) -> &'static str {
211        match self {
212            Self::LoadImages => "load_images",
213            Self::DarkMode => "dark_mode",
214            Self::BlockBanners => "block_banners",
215            Self::PrintMediaFormat => "print_media_format",
216        }
217    }
218}
219
220/// Scrape output format.
221#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
222#[serde(rename_all = "snake_case")]
223pub enum Format {
224    /// Structured JSON.
225    Json,
226    /// Plain text (HTML stripped).
227    Text,
228    /// Markdown.
229    Markdown,
230    /// Cleaned/normalized HTML.
231    CleanHtml,
232    /// Raw HTML.
233    Raw,
234}
235
236impl Format {
237    /// Wire-format string.
238    pub fn as_str(&self) -> &'static str {
239        match self {
240            Self::Json => "json",
241            Self::Text => "text",
242            Self::Markdown => "markdown",
243            Self::CleanHtml => "clean_html",
244            Self::Raw => "raw",
245        }
246    }
247}
248
249/// Additional options combinable with [`Format`].
250#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
251#[serde(rename_all = "snake_case")]
252pub enum FormatOption {
253    /// Strip links.
254    NoLinks,
255    /// Strip images.
256    NoImages,
257    /// Keep only the main content.
258    OnlyContent,
259}
260
261impl FormatOption {
262    /// Wire-format string.
263    pub fn as_str(&self) -> &'static str {
264        match self {
265            Self::NoLinks => "no_links",
266            Self::NoImages => "no_images",
267            Self::OnlyContent => "only_content",
268        }
269    }
270}
271
272/// HTTP methods the scrape endpoint accepts.
273#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
274#[serde(rename_all = "UPPERCASE")]
275pub enum HttpMethod {
276    /// `GET`.
277    Get,
278    /// `POST`.
279    Post,
280    /// `PUT`.
281    Put,
282    /// `PATCH`.
283    Patch,
284    /// `OPTIONS`.
285    Options,
286    /// `HEAD`.
287    Head,
288}
289
290impl HttpMethod {
291    /// Wire-format string.
292    pub fn as_str(&self) -> &'static str {
293        match self {
294            Self::Get => "GET",
295            Self::Post => "POST",
296            Self::Put => "PUT",
297            Self::Patch => "PATCH",
298            Self::Options => "OPTIONS",
299            Self::Head => "HEAD",
300        }
301    }
302}
303
304/// Document-body compression format for the extraction endpoint.
305#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
306#[serde(rename_all = "lowercase")]
307pub enum CompressionFormat {
308    /// gzip.
309    Gzip,
310    /// zstd.
311    Zstd,
312    /// deflate.
313    Deflate,
314}
315
316impl CompressionFormat {
317    /// Wire-format string.
318    pub fn as_str(&self) -> &'static str {
319        match self {
320            Self::Gzip => "gzip",
321            Self::Zstd => "zstd",
322            Self::Deflate => "deflate",
323        }
324    }
325}
326
327/// Content formats the crawler API supports.
328#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
329#[serde(rename_all = "snake_case")]
330pub enum CrawlerContentFormat {
331    /// Raw HTML.
332    Html,
333    /// Cleaned HTML.
334    CleanHtml,
335    /// Markdown.
336    Markdown,
337    /// Plain text.
338    Text,
339    /// Structured JSON.
340    Json,
341    /// Extracted data (AI template).
342    ExtractedData,
343    /// Page metadata.
344    PageMetadata,
345}
346
347impl CrawlerContentFormat {
348    /// Wire-format string.
349    pub fn as_str(&self) -> &'static str {
350        match self {
351            Self::Html => "html",
352            Self::CleanHtml => "clean_html",
353            Self::Markdown => "markdown",
354            Self::Text => "text",
355            Self::Json => "json",
356            Self::ExtractedData => "extracted_data",
357            Self::PageMetadata => "page_metadata",
358        }
359    }
360}
361
362/// Crawler webhook events.
363#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
364#[serde(rename_all = "snake_case")]
365pub enum CrawlerWebhookEvent {
366    /// `crawler_started`.
367    CrawlerStarted,
368    /// `crawler_url_visited`.
369    CrawlerUrlVisited,
370    /// `crawler_url_skipped`.
371    CrawlerUrlSkipped,
372    /// `crawler_url_discovered`.
373    CrawlerUrlDiscovered,
374    /// `crawler_url_failed`.
375    CrawlerUrlFailed,
376    /// `crawler_stopped`.
377    CrawlerStopped,
378    /// `crawler_cancelled`.
379    CrawlerCancelled,
380    /// `crawler_finished`.
381    CrawlerFinished,
382}
383
384impl CrawlerWebhookEvent {
385    /// Wire-format string.
386    pub fn as_str(&self) -> &'static str {
387        match self {
388            Self::CrawlerStarted => "crawler_started",
389            Self::CrawlerUrlVisited => "crawler_url_visited",
390            Self::CrawlerUrlSkipped => "crawler_url_skipped",
391            Self::CrawlerUrlDiscovered => "crawler_url_discovered",
392            Self::CrawlerUrlFailed => "crawler_url_failed",
393            Self::CrawlerStopped => "crawler_stopped",
394            Self::CrawlerCancelled => "crawler_cancelled",
395            Self::CrawlerFinished => "crawler_finished",
396        }
397    }
398}