use super::BaseApi;
use crate::{Client, Query, Language, Realtime};
pub struct RealtimeApi<'a> {
client: &'a Client,
query: Option<Query>,
aqi: bool,
lang: Option<Language>
}
impl<'a> RealtimeApi<'a> {
pub fn new(client: &'a Client) -> Self {
Self {
client,
query: None,
aqi: false,
lang: None
}
}
pub fn query(mut self, query: Query) -> Self {
self.query = Some(query);
self
}
pub fn aqi(mut self) -> Self {
self.aqi = true;
self
}
pub fn lang(mut self, lang: Language) -> Self {
self.lang = Some(lang);
self
}
}
impl<'a> BaseApi<'a> for RealtimeApi<'a> {
type Model = Realtime;
fn path(&self) -> &str {
"current"
}
fn client(&self) -> &'a Client {
self.client
}
fn params(&self) -> Vec<(&str, String)> {
let query = self.query.as_ref().unwrap();
let mut params = vec![
("key", self.client.api_key.clone()), ("q", query.to_string()),
("aqi", if self.aqi { "yes".to_string() } else { "no".to_string() })
];
if let Some(lang) = &self.lang {
params.push(("lang", lang.to_string()))
}
params
}
}