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)
}
pub fn list_benchmarks(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/benchmarks/")
}
pub fn get_benchmark(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/benchmarks/{}/", slug))
}
pub fn list_cables(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/cables/")
}
pub fn get_cable(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/cables/{}/", slug))
}
pub fn list_compatibility(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/compatibility/")
}
pub fn get_compatibility(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/compatibility/{}/", slug))
}
pub fn list_connectors(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/connectors/")
}
pub fn get_connector(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/connectors/{}/", slug))
}
pub fn list_devices(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/devices/")
}
pub fn get_device(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/devices/{}/", slug))
}
pub fn list_faqs(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/faqs/")
}
pub fn get_faq(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/faqs/{}/", slug))
}
pub fn list_guide_series(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/guide-series/")
}
pub fn get_guide_sery(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/guide-series/{}/", slug))
}
pub fn list_guides(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/guides/")
}
pub fn get_guide(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/guides/{}/", slug))
}
pub fn list_setup_guides(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/setup-guides/")
}
pub fn get_setup_guide(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/setup-guides/{}/", slug))
}
pub fn list_standards(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/standards/")
}
pub fn get_standard(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/standards/{}/", slug))
}
pub fn list_terms(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/terms/")
}
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() }
}