1use crate::error::{ApiError, Result};
4use reqwest::Client;
5use serde_json::Value;
6use url::Url;
7
8pub struct EventClient {
10 base_url: String,
11 client: Client,
12}
13
14impl EventClient {
15 pub fn new(base_url: String, client: Client) -> Self {
17 Self { base_url, client }
18 }
19
20 pub fn with_auth(self, token: &str) -> Self {
22 self
24 }
25
26 pub async fn get_events_repo_date(
28 &self,
29 repo: String,
30 date: String,
31 ) -> Result<Value> {
32 let path = format!("/events/{}/-/{}", repo, date);
33 let url = Url::parse(&format!("{}{}", self.base_url, path))?;
34
35
36 let request = self.client.request(
37 reqwest::Method::GET,
38 url
39 );
40
41
42
43
44 let response = request.send().await?;
45
46 if response.status().is_success() {
47 let json: Value = response.json().await?;
48 Ok(json)
49 } else {
50 Err(ApiError::HttpError(response.status().as_u16()))
51 }
52 }
53
54}