use serde_json::Value;
pub struct Client {
base_url: String,
http: reqwest::blocking::Client,
}
impl Client {
pub fn new() -> Self {
Self {
base_url: "https://teafyi.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_benefits(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/benefits/")
}
pub fn get_benefit(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/benefits/{}/", slug))
}
pub fn list_brewing(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/brewing/")
}
pub fn get_brewing(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/brewing/{}/", slug))
}
pub fn list_categories(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/categories/")
}
pub fn get_category(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/categories/{}/", slug))
}
pub fn list_compounds(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/compounds/")
}
pub fn get_compound(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/compounds/{}/", slug))
}
pub fn list_countries(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/countries/")
}
pub fn get_country(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/countries/{}/", 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_glossary(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/glossary/")
}
pub fn get_term(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/glossary/{}/", 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_processing(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/processing/")
}
pub fn get_processing(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/processing/{}/", slug))
}
pub fn list_regions(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/regions/")
}
pub fn get_region(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/regions/{}/", slug))
}
pub fn list_teaware(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/teaware/")
}
pub fn get_teaware(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/teaware/{}/", slug))
}
pub fn list_tools(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/tools/")
}
pub fn get_tool(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/tools/{}/", slug))
}
pub fn list_varieties(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/varieties/")
}
pub fn get_variety(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/varieties/{}/", slug))
}
}
impl Default for Client {
fn default() -> Self { Self::new() }
}