use std::future::{Future, IntoFuture};
use std::pin::Pin;
use reqwest::Method;
use crate::client::Client;
use crate::dispatch::{decode_json, room_path};
use crate::error::Result;
use crate::types::{Occupancy, RoomName};
#[derive(Clone, Debug)]
pub struct OccupancyHandle {
pub(crate) client: Client,
pub(crate) room: RoomName,
}
impl OccupancyHandle {
pub(crate) fn new(client: Client, room: RoomName) -> Self {
Self { client, room }
}
pub fn get(&self) -> GetOccupancy {
GetOccupancy {
client: self.client.clone(),
room: self.room.clone(),
}
}
}
#[derive(Clone, Debug)]
pub struct GetOccupancy {
client: Client,
room: RoomName,
}
impl IntoFuture for GetOccupancy {
type Output = Result<Occupancy>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
let resp = self
.client
.inner
.send(
Method::GET,
&room_path(self.room.as_str(), "/occupancy"),
&[],
None,
false,
)
.await?;
decode_json(&resp.body)
})
}
}