#![doc = include_str!("../README.md")]
#[doc(inline)]
pub use nutrition_information::NutritionInformation;
#[doc(inline)]
pub use recipe_information_provider::RecipeInformationProvider;
#[doc(inline)]
pub use restricted_diet::RestrictedDiet;
use schema_scraper::SchemaScraper;
use std::error::Error;
pub mod nutrition_information;
pub mod recipe_information_provider;
pub mod restricted_diet;
mod schema_scraper;
pub trait RecipeScraper {
fn scrape_recipe(
self,
html: &str,
) -> Result<Box<dyn RecipeInformationProvider>, serde_json::Error>;
}
pub fn scrape_recipe(html: &str) -> Result<Box<dyn RecipeInformationProvider>, Box<dyn Error>> {
let scraper = SchemaScraper {};
custom_scrape_recipe(html, scraper)
}
pub fn custom_scrape_recipe(
html: &str,
scraper: impl RecipeScraper,
) -> Result<Box<dyn RecipeInformationProvider>, Box<dyn Error>> {
Ok(scraper.scrape_recipe(html)?)
}
#[cfg(feature = "blocking")]
pub fn scrape_recipe_from_url_blocking(
url: &str,
) -> Result<Box<dyn RecipeInformationProvider>, Box<dyn Error>> {
let res = ureq::get(url).call()?.into_string()?;
scrape_recipe(&res)
}
#[cfg(feature = "async")]
pub async fn scrape_recipe_from_url(
url: &str,
) -> Result<Box<dyn RecipeInformationProvider>, Box<dyn Error>> {
let res = reqwest::get(url).await?.text().await?;
scrape_recipe(&res)
}