drugfyi 0.1.0

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

    /// Get drug classe by slug.
    pub fn get_drug_classe(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/drug-classes/{}/", slug))
    }
    /// List all drug targets.
    pub fn list_drug_targets(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/drug-targets/")
    }

    /// Get drug target by slug.
    pub fn get_drug_target(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/drug-targets/{}/", slug))
    }
    /// List all drugs.
    pub fn list_drugs(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/drugs/")
    }

    /// Get drug by slug.
    pub fn get_drug(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/drugs/{}/", slug))
    }
    /// List all families.
    pub fn list_families(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/families/")
    }

    /// Get family by slug.
    pub fn get_family(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/families/{}/", 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 interactions.
    pub fn list_interactions(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/interactions/")
    }

    /// Get interaction by slug.
    pub fn get_interaction(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/interactions/{}/", slug))
    }
    /// List all journeys.
    pub fn list_journeys(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/journeys/")
    }

    /// Get journey by slug.
    pub fn get_journey(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/journeys/{}/", slug))
    }
    /// List all milestones.
    pub fn list_milestones(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/milestones/")
    }

    /// Get milestone by slug.
    pub fn get_milestone(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/milestones/{}/", slug))
    }
    /// List all side effects.
    pub fn list_side_effects(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/side-effects/")
    }

    /// Get side effect by slug.
    pub fn get_side_effect(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/side-effects/{}/", slug))
    }
    /// List all target interactions.
    pub fn list_target_interactions(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/target-interactions/")
    }

    /// Get target interaction by slug.
    pub fn get_target_interaction(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/target-interactions/{}/", slug))
    }
    /// List all therapeutic areas.
    pub fn list_therapeutic_areas(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/therapeutic-areas/")
    }

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

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