#![cfg_attr(docsrs, feature(doc_cfg))]
use std::time::Duration;
pub mod core;
pub mod account;
pub mod amazon;
pub mod google;
pub mod reddit;
pub mod twitter;
pub mod vinted;
pub mod web;
#[doc = include_str!("../docs/CLI.md")]
pub mod cli_reference {}
#[cfg(feature = "cli")]
#[doc(hidden)]
pub mod cli;
pub use crate::core::{Config, Error, Result, DEFAULT_BASE_URL};
use crate::core::{resolve_api_key, Client, Config as CoreConfig};
pub use account::Account;
pub use amazon::Amazon;
pub use google::Google;
pub use reddit::Reddit;
pub use twitter::Twitter;
pub use vinted::Vinted;
pub use web::Web;
#[derive(Clone)]
pub struct ScrapeBadger {
client: Client,
}
impl ScrapeBadger {
pub fn new(api_key: impl Into<String>) -> Result<Self> {
Self::builder().api_key(api_key).build()
}
pub fn from_env() -> Result<Self> {
Self::builder().build()
}
pub fn builder() -> ScrapeBadgerBuilder {
ScrapeBadgerBuilder::default()
}
pub fn client(&self) -> &Client {
&self.client
}
pub fn account(&self) -> Account {
Account::new(self.client.clone())
}
pub fn amazon(&self) -> Amazon {
Amazon::new(self.client.clone())
}
pub fn google(&self) -> Google {
Google::new(self.client.clone())
}
pub fn reddit(&self) -> Reddit {
Reddit::new(self.client.clone())
}
pub fn twitter(&self) -> Twitter {
Twitter::new(self.client.clone())
}
pub fn vinted(&self) -> Vinted {
Vinted::new(self.client.clone())
}
pub fn web(&self) -> Web {
Web::new(self.client.clone())
}
}
#[derive(Default)]
pub struct ScrapeBadgerBuilder {
api_key: Option<String>,
base_url: Option<String>,
timeout: Option<Duration>,
max_retries: Option<u32>,
user_agent: Option<String>,
}
impl ScrapeBadgerBuilder {
pub fn api_key(mut self, api_key: impl Into<String>) -> Self {
self.api_key = Some(api_key.into());
self
}
pub fn base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = Some(base_url.into());
self
}
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout);
self
}
pub fn max_retries(mut self, max_retries: u32) -> Self {
self.max_retries = Some(max_retries);
self
}
pub fn user_agent(mut self, user_agent: impl Into<String>) -> Self {
self.user_agent = Some(user_agent.into());
self
}
pub fn build(self) -> Result<ScrapeBadger> {
let api_key = resolve_api_key(self.api_key)?;
let mut config = CoreConfig::new(api_key);
if let Some(v) = self.base_url {
config.base_url = v;
}
if let Some(v) = self.timeout {
config.timeout = v;
}
if let Some(v) = self.max_retries {
config.max_retries = v;
}
if let Some(v) = self.user_agent {
config.user_agent = v;
}
Ok(ScrapeBadger {
client: Client::from_config(config)?,
})
}
}