Skip to main content

asimov_brightdata_module/api/
scrape.rs

1// This is free and unencumbered software released into the public domain.
2
3#![allow(unused)]
4
5use asimov_module::prelude::{Result, String, Vec};
6use core::str::FromStr;
7use serde::Serialize;
8
9#[derive(Clone, Debug, Default, Serialize)]
10pub struct ScrapeRequest {
11    pub input: Vec<ScrapeInput>,
12
13    #[serde(
14        serialize_with = "serialize_custom_output_fields",
15        skip_serializing_if = "Vec::is_empty"
16    )]
17    pub custom_output_fields: Vec<String>,
18}
19
20impl From<Vec<ScrapeInput>> for ScrapeRequest {
21    fn from(input: Vec<ScrapeInput>) -> Self {
22        Self {
23            input,
24            ..Default::default()
25        }
26    }
27}
28
29#[derive(Clone, Debug, Serialize)]
30pub struct ScrapeInput {
31    pub url: String,
32}
33
34impl FromStr for ScrapeInput {
35    type Err = ();
36
37    fn from_str(input: &str) -> Result<Self, Self::Err> {
38        Ok(ScrapeInput {
39            url: String::from(input),
40        })
41    }
42}
43
44pub(crate) fn serialize_custom_output_fields<S>(t: &Vec<String>, s: S) -> Result<S::Ok, S::Error>
45where
46    S: serde::Serializer,
47{
48    s.serialize_str(&t.join("|"))
49}