use serde_json::Value;
pub struct Client {
base_url: String,
http: reqwest::blocking::Client,
}
impl Client {
pub fn new() -> Self {
Self {
base_url: "https://airlinefyi.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_airlines(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/airlines/")
}
pub fn get_airline(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/airlines/{}/", slug))
}
pub fn list_airports(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/airports/")
}
pub fn get_airport(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/airports/{}/", slug))
}
pub fn list_brief_series(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/brief-series/")
}
pub fn get_brief_sery(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/brief-series/{}/", slug))
}
pub fn list_cabin_products(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/cabin-products/")
}
pub fn get_cabin_product(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/cabin-products/{}/", 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_flight_corridors(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/flight-corridors/")
}
pub fn get_flight_corridor(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/flight-corridors/{}/", slug))
}
pub fn list_flights(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/flights/")
}
pub fn get_flight(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/flights/{}/", 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_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_hub_profiles(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/hub-profiles/")
}
pub fn get_hub_profile(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/hub-profiles/{}/", slug))
}
pub fn list_industry_briefs(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/industry-briefs/")
}
pub fn get_industry_brief(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/industry-briefs/{}/", slug))
}
pub fn list_loyalty_programs(&self) -> Result<Value, Box<dyn std::error::Error>> {
self.get("/api/v1/loyalty-programs/")
}
pub fn get_loyalty_program(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
self.get(&format!("/api/v1/loyalty-programs/{}/", 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))
}
}
impl Default for Client {
fn default() -> Self { Self::new() }
}