use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct SearchRequest {
api_key: String,
query: String,
#[serde(skip_serializing_if = "Option::is_none")]
search_depth: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
include_answer: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
include_images: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
include_raw_content: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
max_results: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
include_domains: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
exclude_domains: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
topic: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
days: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
include_image_descriptions: Option<bool>,
}
#[derive(Debug, Serialize)]
pub struct ExtractRequest {
api_key: String,
urls: Vec<String>,
}
impl Default for ExtractRequest {
fn default() -> Self {
Self {
api_key: "".into(),
urls: vec![],
}
}
}
impl ExtractRequest {
pub fn new<I, S>(api_key: &str, urls: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Self {
api_key: api_key.into(),
urls: urls.into_iter().map(Into::into).collect(),
}
}
}
impl Default for SearchRequest {
fn default() -> Self {
Self {
api_key: "".into(),
query: "".into(),
search_depth: None,
include_answer: None,
include_images: None,
include_raw_content: None,
max_results: None,
include_domains: None,
exclude_domains: None,
topic: None,
days: None,
include_image_descriptions: None,
}
}
}
impl SearchRequest {
pub fn new<S1, S2>(api_key: S1, query: S2) -> Self
where
S1: AsRef<str> + Into<String>,
S2: AsRef<str> + Into<String>,
{
Self {
api_key: api_key.into(),
query: query.into(),
..Default::default()
}
}
pub fn search_depth<S>(mut self, search_depth: S) -> Self
where
S: AsRef<str> + Into<String>,
{
self.search_depth = Some(search_depth.into());
self
}
pub fn include_answer(mut self, include_answer: bool) -> Self {
self.include_answer = Some(include_answer);
self
}
pub fn include_images(mut self, include_images: bool) -> Self {
self.include_images = Some(include_images);
self
}
pub fn include_raw_content(mut self, include_raw_content: bool) -> Self {
self.include_raw_content = Some(include_raw_content);
self
}
pub fn max_results(mut self, max_results: i32) -> Self {
self.max_results = Some(max_results);
self
}
pub fn include_domains<I, S>(mut self, include_domains: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<str> + Into<String>,
{
self.include_domains = Some(include_domains.into_iter().map(Into::into).collect());
self
}
pub fn exclude_domains<I, S>(mut self, exclude_domains: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<str> + Into<String>,
{
self.exclude_domains = Some(exclude_domains.into_iter().map(Into::into).collect());
self
}
pub fn topic<S>(mut self, topic: S) -> Self
where
S: AsRef<str> + Into<String>,
{
self.topic = Some(topic.into());
self
}
pub fn days(mut self, days: i32) -> Self {
self.days = Some(days);
self
}
pub fn include_image_descriptions(mut self, include_descriptions: bool) -> Self {
self.include_image_descriptions = Some(include_descriptions);
self
}
}