use serde_json::Value;
pub struct Client {
base_url: String,
http: reqwest::blocking::Client,
}
impl Client {
pub fn new() -> Self {
Self {
base_url: "https://plantfyi.com".to_string(),
http: reqwest::blocking::Client::new(),
}
}
fn get(&self, path: &str) -> Result<Value, Box<dyn std::error::Error>> {
let url = format!("{}{}", self.base_url, path);
let resp = self.http.get(&url).send()?.json()?;
Ok(resp)
}
pub fn search(&self, query: &str) -> Result<Value, Box<dyn std::error::Error>> {
let url = format!("{}/api/v1/search/?q={}", self.base_url, query);
let resp = self.http.get(&url).send()?.json()?;
Ok(resp)
}
pub fn list_climate_zones(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/climate-zones/")
}
pub fn get_climate_zone(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/climate-zones/{}/", slug))
}
pub fn list_comparisons(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/comparisons/")
}
pub fn get_comparison(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/comparisons/{}/", slug))
}
pub fn list_countries(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/countries/")
}
pub fn get_country(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/countries/{}/", slug))
}
pub fn list_distributions(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/distributions/")
}
pub fn get_distribution(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/distributions/{}/", slug))
}
pub fn list_families(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/families/")
}
pub fn get_family(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/families/{}/", slug))
}
pub fn list_faqs(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/faqs/")
}
pub fn get_faq(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/faqs/{}/", slug))
}
pub fn list_glossary(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/glossary/")
}
pub fn get_term(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/glossary/{}/", slug))
}
pub fn list_glossary_categories(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/glossary-categories/")
}
pub fn get_glossary_category(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/glossary-categories/{}/", slug))
}
pub fn list_guide_series(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/guide-series/")
}
pub fn get_guide_sery(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/guide-series/{}/", slug))
}
pub fn list_guides(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/guides/")
}
pub fn get_guide(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/guides/{}/", slug))
}
pub fn list_orders(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/orders/")
}
pub fn get_order(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/orders/{}/", slug))
}
pub fn list_plants(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/plants/")
}
pub fn get_plant(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/plants/{}/", slug))
}
}
impl Default for Client {
fn default() -> Self { Self::new() }
}