use super::Event;
#[derive(Clone)]
pub struct GammaClient {
base_url: String,
client: reqwest::Client,
}
#[derive(Debug, serde::Serialize)]
pub struct GetEventsRequest {
pub tag_id: String,
pub exclude_tag_ids: Vec<String>,
pub active: bool,
pub closed: bool,
}
impl Default for GetEventsRequest {
fn default() -> Self {
Self {
tag_id: "".to_string(),
exclude_tag_ids: vec![],
active: true,
closed: false,
}
}
}
impl GammaClient {
pub fn new(base_url: String) -> Self {
Self {
base_url,
client: reqwest::Client::new(),
}
}
pub async fn get_events(&self, request: GetEventsRequest) -> Result<Vec<Event>, reqwest::Error> {
let url = format!("{}/events", self.base_url);
let mut query_params = vec![
("active", request.active.to_string()),
("closed", request.closed.to_string()),
];
if !request.tag_id.is_empty() {
query_params.push(("tag_id", request.tag_id));
}
for exclude_tag_id in request.exclude_tag_ids {
query_params.push(("exclude_tag_id", exclude_tag_id));
}
let response = self.client.get(url).query(&query_params).send().await?;
let events: Vec<Event> = response.json().await?;
Ok(events)
}
}