use crate::error::EchoError;
use crate::types::session::Session;
const SESSION_URL: &str = "http://127.0.0.1:6721/session";
pub struct Client {
agent: ureq::Agent,
}
impl Client {
pub fn new() -> Self {
Client {
agent: ureq::Agent::new_with_defaults(),
}
}
pub fn fetch_session(&self) -> Result<Session, EchoError> {
let body = self.agent.get(SESSION_URL).call()?.body_mut().read_to_string()?;
let session = serde_json::from_str(&body)?;
Ok(session)
}
}
impl Default for Client {
fn default() -> Self {
Self::new()
}
}