Skip to main content

floopy/resources/
sessions.rs

1use std::sync::Arc;
2
3use reqwest::Method;
4
5use crate::constants::session_by_id;
6use crate::error::Result;
7use crate::http::HttpTransport;
8use crate::options::RequestOptions;
9use crate::types::Session;
10
11use super::require;
12
13/// Restores stored conversations.
14pub struct Sessions {
15    t: Arc<HttpTransport>,
16}
17
18impl Sessions {
19    pub(crate) fn new(t: Arc<HttpTransport>) -> Self {
20        Self { t }
21    }
22
23    /// Restore a stored conversation by its session id (the value sent on
24    /// the `floopy-session-id` header at request time). Scoped to the API
25    /// key's organization.
26    ///
27    /// # Errors
28    /// Returns an [`Error`](crate::Error) on a non-2xx response or transport
29    /// failure.
30    pub async fn get(
31        &self,
32        session_id: &str,
33        req: impl Into<Option<RequestOptions>>,
34    ) -> Result<Session> {
35        let (data, _) = self
36            .t
37            .request(
38                Method::GET,
39                &session_by_id(session_id),
40                None,
41                &[],
42                req.into().as_ref(),
43            )
44            .await?;
45        require(data)
46    }
47}