anatomyfyi 0.1.0

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

    /// Get comparison by slug.
    pub fn get_comparison(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/comparisons/{}/", slug))
    }
    /// List all entities.
    pub fn list_entities(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/entities/")
    }

    /// Get entity by slug.
    pub fn get_entity(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/entities/{}/", 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 glossary categories.
    pub fn list_glossary_categories(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/glossary-categories/")
    }

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

    /// Get guide sery by slug.
    pub fn get_guide_sery(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/guide-series/{}/", 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 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 relations.
    pub fn list_relations(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/relations/")
    }

    /// Get relation by slug.
    pub fn get_relation(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/relations/{}/", slug))
    }
    /// List all systems.
    pub fn list_systems(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/systems/")
    }

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

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