airlinefyi 0.1.0

Rust client for the AirlineFYI API — https://airlinefyi.com
Documentation
//! Rust client for [AirlineFYI](https://airlinefyi.com) REST API.
//!
//! ```rust
//! let client = airlinefyi::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://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)
    }

    /// List all airlines.
    pub fn list_airlines(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/airlines/")
    }

    /// Get airline by slug.
    pub fn get_airline(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/airlines/{}/", slug))
    }
    /// List all airports.
    pub fn list_airports(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/airports/")
    }

    /// Get airport by slug.
    pub fn get_airport(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/airports/{}/", slug))
    }
    /// List all brief series.
    pub fn list_brief_series(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/brief-series/")
    }

    /// Get brief sery by slug.
    pub fn get_brief_sery(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/brief-series/{}/", slug))
    }
    /// List all cabin products.
    pub fn list_cabin_products(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/cabin-products/")
    }

    /// Get cabin product by slug.
    pub fn get_cabin_product(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/cabin-products/{}/", slug))
    }
    /// List all countries.
    pub fn list_countries(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/countries/")
    }

    /// Get country by slug.
    pub fn get_country(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/countries/{}/", 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 flight corridors.
    pub fn list_flight_corridors(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/flight-corridors/")
    }

    /// Get flight corridor by slug.
    pub fn get_flight_corridor(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/flight-corridors/{}/", slug))
    }
    /// List all flights.
    pub fn list_flights(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/flights/")
    }

    /// Get flight by slug.
    pub fn get_flight(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/flights/{}/", 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 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 hub profiles.
    pub fn list_hub_profiles(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/hub-profiles/")
    }

    /// Get hub profile by slug.
    pub fn get_hub_profile(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/hub-profiles/{}/", slug))
    }
    /// List all industry briefs.
    pub fn list_industry_briefs(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/industry-briefs/")
    }

    /// Get industry brief by slug.
    pub fn get_industry_brief(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.get(&format!("/api/v1/industry-briefs/{}/", slug))
    }
    /// List all loyalty programs.
    pub fn list_loyalty_programs(&self) -> Result<Value, Box<dyn std::error::Error>> {
        self.get("/api/v1/loyalty-programs/")
    }

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