vinofyi 0.1.0

Rust client for the VinoFYI API — https://vinofyi.com
Documentation
//! Rust client for [VinoFYI](https://vinofyi.com) REST API.
//!
//! ```rust
//! let client = vinofyi::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://vinofyi.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 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 faults.
    pub fn list_faults(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/faults/")
    }

    /// Get fault by slug.
    pub fn get_fault(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/faults/{}/", slug))
    }
    /// List all flavors.
    pub fn list_flavors(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/flavors/")
    }

    /// Get flavor by slug.
    pub fn get_flavor(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/flavors/{}/", slug))
    }
    /// List all foods.
    pub fn list_foods(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/foods/")
    }

    /// Get food by slug.
    pub fn get_food(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/foods/{}/", 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 grapes.
    pub fn list_grapes(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/grapes/")
    }

    /// Get grape by slug.
    pub fn get_grape(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/grapes/{}/", 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 methods.
    pub fn list_methods(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/methods/")
    }

    /// Get method by slug.
    pub fn get_method(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/methods/{}/", 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 styles.
    pub fn list_styles(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/styles/")
    }

    /// Get style by slug.
    pub fn get_style(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/styles/{}/", slug))
    }
    /// List all wineries.
    pub fn list_wineries(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/wineries/")
    }

    /// Get winery by slug.
    pub fn get_winery(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/wineries/{}/", slug))
    }
    /// List all wines.
    pub fn list_wines(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/wines/")
    }

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

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