cablefyi 0.1.0

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

    /// Get benchmark by slug.
    pub fn get_benchmark(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/benchmarks/{}/", slug))
    }
    /// List all cables.
    pub fn list_cables(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/cables/")
    }

    /// Get cable by slug.
    pub fn get_cable(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/cables/{}/", slug))
    }
    /// List all compatibility.
    pub fn list_compatibility(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/compatibility/")
    }

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

    /// Get connector by slug.
    pub fn get_connector(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/connectors/{}/", slug))
    }
    /// List all devices.
    pub fn list_devices(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/devices/")
    }

    /// Get device by slug.
    pub fn get_device(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/devices/{}/", 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 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 setup guides.
    pub fn list_setup_guides(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/setup-guides/")
    }

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

    /// Get standard by slug.
    pub fn get_standard(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/standards/{}/", slug))
    }
    /// List all terms.
    pub fn list_terms(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/terms/")
    }

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

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