use crate::client::{encode_path_segment, Client};
use crate::idempotency::IdempotencyKey;
use crate::models::common::ListParams;
use crate::models::session::{CreateSessionRequest, Session};
#[derive(Debug, Clone, Copy)]
pub struct Sessions<'c> {
client: &'c Client,
}
impl<'c> Sessions<'c> {
pub(crate) fn new(client: &'c Client) -> Self {
Self { client }
}
pub async fn create(
&self,
request: &CreateSessionRequest,
idempotency_key: Option<&IdempotencyKey>,
) -> crate::Result<Session> {
let mut req = self.client.post("/api/v1/sessions").json(request);
if let Some(k) = idempotency_key {
req = req.idempotency_key(k);
}
req.send().await
}
pub async fn get(&self, reference: &str) -> crate::Result<Session> {
self.client
.get(&format!(
"/api/v1/sessions/{}",
encode_path_segment(reference)
))
.send()
.await
}
pub async fn list(&self, params: &ListParams) -> crate::Result<Vec<Session>> {
self.client
.get("/api/v1/sessions")
.query(params)
.send()
.await
}
pub async fn cancel(&self, reference: &str) -> crate::Result<Session> {
self.client
.post(&format!(
"/api/v1/sessions/{}/cancel",
encode_path_segment(reference)
))
.send()
.await
}
}