Skip to main content

asimov_serpapi_module/api/
google.rs

1// This is free and unencumbered software released into the public domain.
2
3#![allow(unused)]
4
5use asimov_module::prelude::{FromStr, String};
6use serde::Serialize;
7
8/// See: https://serpapi.com/search-api#api-parameters
9#[derive(Clone, Debug, Default, Serialize)]
10pub struct GoogleSearchRequest {
11    /// See: https://serpapi.com/search-api#api-parameters-search-query-q
12    pub q: String,
13}
14
15impl FromStr for GoogleSearchRequest {
16    type Err = url::ParseError;
17
18    fn from_str(input: &str) -> Result<Self, Self::Err> {
19        url::Url::parse(input).map(|url| {
20            let mut output = Self::default();
21            for (k, v) in url.query_pairs() {
22                match k.as_ref() {
23                    "q" => output.q = v.trim().into(),
24                    _ => {}
25                }
26            }
27            output
28        })
29    }
30}