xo_api_client/api/
session.rs

1use std::sync::Arc;
2
3use jsonrpsee_types::{traits::Client, v2::params::ParamsSer};
4use jsonrpsee_ws_client::WsClient;
5
6use crate::{credentials::Credentials, RpcError};
7
8pub struct SessionProcedures {
9    pub(crate) inner: Arc<WsClient>,
10}
11
12impl SessionProcedures {
13    /// Sign in to xo-server, this is required for access to most of the other methods
14    ///
15    /// xo-cli: session.signIn
16    pub async fn sign_in(&self, credentials: impl Into<Credentials>) -> Result<(), RpcError> {
17        log::debug!("Signing in...");
18
19        #[derive(serde::Serialize)]
20        pub struct Credentials {
21            email: String,
22            password: String,
23        }
24
25        let _: SigninResponse = self
26            .inner
27            .request(
28                "session.signIn",
29                Some(ParamsSer::Map(credentials.into().into())),
30            )
31            .await?;
32
33        log::debug!("Signed in");
34
35        Ok(())
36    }
37}
38
39#[derive(serde::Deserialize)]
40struct SigninResponse {}