teafyi 0.1.0

Rust client for the TeaFYI API — https://teafyi.com
Documentation
//! Rust client for [TeaFYI](https://teafyi.com) REST API.
//!
//! ```rust
//! let client = teafyi::Client::new();
//! let result = client.search("query").unwrap();
//! ```

use serde_json::Value;

pub struct Client {
    base_url: String,
    http: reqwest::blocking::Client,
}

impl Client {
    pub fn new() -> Self {
        Self {
            base_url: "https://teafyi.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)
    }

    /// List all benefits.
    pub fn list_benefits(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/benefits/")
    }

    /// Get benefit by slug.
    pub fn get_benefit(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/benefits/{}/", slug))
    }
    /// List all brewing.
    pub fn list_brewing(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/brewing/")
    }

    /// Get brewing by slug.
    pub fn get_brewing(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/brewing/{}/", slug))
    }
    /// List all categories.
    pub fn list_categories(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/categories/")
    }

    /// Get category by slug.
    pub fn get_category(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/categories/{}/", slug))
    }
    /// List all compounds.
    pub fn list_compounds(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/compounds/")
    }

    /// Get compound by slug.
    pub fn get_compound(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/compounds/{}/", slug))
    }
    /// List all countries.
    pub fn list_countries(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/countries/")
    }

    /// Get country by slug.
    pub fn get_country(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/countries/{}/", slug))
    }
    /// List all faqs.
    pub fn list_faqs(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/faqs/")
    }

    /// Get faq by slug.
    pub fn get_faq(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/faqs/{}/", slug))
    }
    /// List all glossary.
    pub fn list_glossary(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/glossary/")
    }

    /// Get term by slug.
    pub fn get_term(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/glossary/{}/", slug))
    }
    /// List all guides.
    pub fn list_guides(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/guides/")
    }

    /// Get guide by slug.
    pub fn get_guide(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/guides/{}/", slug))
    }
    /// List all processing.
    pub fn list_processing(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/processing/")
    }

    /// Get processing by slug.
    pub fn get_processing(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/processing/{}/", slug))
    }
    /// List all regions.
    pub fn list_regions(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/regions/")
    }

    /// Get region by slug.
    pub fn get_region(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/regions/{}/", slug))
    }
    /// List all teaware.
    pub fn list_teaware(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/teaware/")
    }

    /// Get teaware by slug.
    pub fn get_teaware(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/teaware/{}/", slug))
    }
    /// List all tools.
    pub fn list_tools(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/tools/")
    }

    /// Get tool by slug.
    pub fn get_tool(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/tools/{}/", slug))
    }
    /// List all varieties.
    pub fn list_varieties(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/varieties/")
    }

    /// Get variety by slug.
    pub fn get_variety(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/varieties/{}/", slug))
    }
}

impl Default for Client {
    fn default() -> Self { Self::new() }
}