scrapfly_sdk/
enums.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
//! Strongly-typed enums mirroring `sdk/go/enums.go`.
//!
//! Every enum serializes to its lowercase wire-format string via `serde(rename_all = ...)`.

use serde::{Deserialize, Serialize};

/// Simulated vision deficiency for the screenshot API.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum VisionDeficiencyType {
    /// No simulated deficiency.
    None,
    /// Red-green color blindness (missing green cones).
    Deuteranopia,
    /// Red-green color blindness (missing red cones).
    Protanopia,
    /// Blue-yellow color blindness.
    Tritanopia,
    /// Total color blindness.
    Achromatopsia,
    /// Blurred vision simulation.
    BlurredVision,
    /// Reduced contrast simulation.
    ReducedContrast,
}

impl VisionDeficiencyType {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::None => "none",
            Self::Deuteranopia => "deuteranopia",
            Self::Protanopia => "protanopia",
            Self::Tritanopia => "tritanopia",
            Self::Achromatopsia => "achromatopsia",
            Self::BlurredVision => "blurredVision",
            Self::ReducedContrast => "reducedContrast",
        }
    }
}

/// AI extraction model catalog.
///
/// See <https://scrapfly.io/docs/extraction-api/automatic-ai#models>.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ExtractionModel {
    /// Article content.
    Article,
    /// Event listing.
    Event,
    /// Food recipe.
    FoodRecipe,
    /// Hotel page.
    Hotel,
    /// Hotel listing page.
    HotelListing,
    /// Job listing.
    JobListing,
    /// Job posting.
    JobPosting,
    /// Organization.
    Organization,
    /// Product page.
    Product,
    /// Product listing.
    ProductListing,
    /// Real-estate property.
    RealEstateProperty,
    /// Real-estate property listing.
    RealEstatePropertyListing,
    /// Review list.
    ReviewList,
    /// Search engine results page.
    SearchEngineResults,
    /// Social media post.
    SocialMediaPost,
    /// Software listing.
    Software,
    /// Stock quote.
    Stock,
    /// Vehicle ad.
    VehicleAd,
    /// Vehicle ad listing.
    VehicleAdListing,
}

impl ExtractionModel {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Article => "article",
            Self::Event => "event",
            Self::FoodRecipe => "food_recipe",
            Self::Hotel => "hotel",
            Self::HotelListing => "hotel_listing",
            Self::JobListing => "job_listing",
            Self::JobPosting => "job_posting",
            Self::Organization => "organization",
            Self::Product => "product",
            Self::ProductListing => "product_listing",
            Self::RealEstateProperty => "real_estate_property",
            Self::RealEstatePropertyListing => "real_estate_property_listing",
            Self::ReviewList => "review_list",
            Self::SearchEngineResults => "search_engine_results",
            Self::SocialMediaPost => "social_media_post",
            Self::Software => "software",
            Self::Stock => "stock",
            Self::VehicleAd => "vehicle_ad",
            Self::VehicleAdListing => "vehicle_ad_listing",
        }
    }
}

/// Proxy pool catalog.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ProxyPool {
    /// Data-center proxies (cheaper, faster, easier to detect).
    PublicDatacenterPool,
    /// Residential proxies (more expensive, harder to detect).
    PublicResidentialPool,
}

impl ProxyPool {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::PublicDatacenterPool => "public_datacenter_pool",
            Self::PublicResidentialPool => "public_residential_pool",
        }
    }
}

/// Screenshot capture flags.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ScreenshotFlag {
    /// Load images (otherwise blocked for performance).
    LoadImages,
    /// Render in dark mode.
    DarkMode,
    /// Block cookie/consent banners.
    BlockBanners,
    /// Use print-media CSS.
    PrintMediaFormat,
    /// Request higher-quality output.
    HighQuality,
}

impl ScreenshotFlag {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::LoadImages => "load_images",
            Self::DarkMode => "dark_mode",
            Self::BlockBanners => "block_banners",
            Self::PrintMediaFormat => "print_media_format",
            Self::HighQuality => "high_quality",
        }
    }
}

/// Screenshot image format.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ScreenshotFormat {
    /// JPEG output.
    Jpg,
    /// PNG output.
    Png,
    /// WebP output.
    Webp,
    /// GIF output.
    Gif,
}

impl ScreenshotFormat {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Jpg => "jpg",
            Self::Png => "png",
            Self::Webp => "webp",
            Self::Gif => "gif",
        }
    }
}

/// Screenshot legacy option flags (distinct from `ScreenshotFlag` which
/// applies to the inline screenshots on a scrape).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ScreenshotOption {
    /// Load images.
    LoadImages,
    /// Render in dark mode.
    DarkMode,
    /// Block cookie banners.
    BlockBanners,
    /// Print-media CSS.
    PrintMediaFormat,
}

impl ScreenshotOption {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::LoadImages => "load_images",
            Self::DarkMode => "dark_mode",
            Self::BlockBanners => "block_banners",
            Self::PrintMediaFormat => "print_media_format",
        }
    }
}

/// Scrape output format.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Format {
    /// Structured JSON.
    Json,
    /// Plain text (HTML stripped).
    Text,
    /// Markdown.
    Markdown,
    /// Cleaned/normalized HTML.
    CleanHtml,
    /// Raw HTML.
    Raw,
}

impl Format {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Json => "json",
            Self::Text => "text",
            Self::Markdown => "markdown",
            Self::CleanHtml => "clean_html",
            Self::Raw => "raw",
        }
    }
}

/// Additional options combinable with [`Format`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FormatOption {
    /// Strip links.
    NoLinks,
    /// Strip images.
    NoImages,
    /// Keep only the main content.
    OnlyContent,
}

impl FormatOption {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::NoLinks => "no_links",
            Self::NoImages => "no_images",
            Self::OnlyContent => "only_content",
        }
    }
}

/// HTTP methods the scrape endpoint accepts.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum HttpMethod {
    /// `GET`.
    Get,
    /// `POST`.
    Post,
    /// `PUT`.
    Put,
    /// `PATCH`.
    Patch,
    /// `OPTIONS`.
    Options,
    /// `HEAD`.
    Head,
}

impl HttpMethod {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Get => "GET",
            Self::Post => "POST",
            Self::Put => "PUT",
            Self::Patch => "PATCH",
            Self::Options => "OPTIONS",
            Self::Head => "HEAD",
        }
    }
}

/// Document-body compression format for the extraction endpoint.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CompressionFormat {
    /// gzip.
    Gzip,
    /// zstd.
    Zstd,
    /// deflate.
    Deflate,
}

impl CompressionFormat {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Gzip => "gzip",
            Self::Zstd => "zstd",
            Self::Deflate => "deflate",
        }
    }
}

/// Content formats the crawler API supports.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CrawlerContentFormat {
    /// Raw HTML.
    Html,
    /// Cleaned HTML.
    CleanHtml,
    /// Markdown.
    Markdown,
    /// Plain text.
    Text,
    /// Structured JSON.
    Json,
    /// Extracted data (AI template).
    ExtractedData,
    /// Page metadata.
    PageMetadata,
}

impl CrawlerContentFormat {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Html => "html",
            Self::CleanHtml => "clean_html",
            Self::Markdown => "markdown",
            Self::Text => "text",
            Self::Json => "json",
            Self::ExtractedData => "extracted_data",
            Self::PageMetadata => "page_metadata",
        }
    }
}

/// Crawler webhook events.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CrawlerWebhookEvent {
    /// `crawler_started`.
    CrawlerStarted,
    /// `crawler_url_visited`.
    CrawlerUrlVisited,
    /// `crawler_url_skipped`.
    CrawlerUrlSkipped,
    /// `crawler_url_discovered`.
    CrawlerUrlDiscovered,
    /// `crawler_url_failed`.
    CrawlerUrlFailed,
    /// `crawler_stopped`.
    CrawlerStopped,
    /// `crawler_cancelled`.
    CrawlerCancelled,
    /// `crawler_finished`.
    CrawlerFinished,
}

impl CrawlerWebhookEvent {
    /// Wire-format string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::CrawlerStarted => "crawler_started",
            Self::CrawlerUrlVisited => "crawler_url_visited",
            Self::CrawlerUrlSkipped => "crawler_url_skipped",
            Self::CrawlerUrlDiscovered => "crawler_url_discovered",
            Self::CrawlerUrlFailed => "crawler_url_failed",
            Self::CrawlerStopped => "crawler_stopped",
            Self::CrawlerCancelled => "crawler_cancelled",
            Self::CrawlerFinished => "crawler_finished",
        }
    }
}