xo_api_client/api/
token.rs

1use std::{collections::BTreeMap, sync::Arc};
2
3use jsonrpsee_types::{traits::Client, v2::params::ParamsSer};
4use jsonrpsee_ws_client::WsClient;
5
6use crate::{credentials::Token, RpcError};
7
8pub struct TokenProcedures {
9    pub(crate) inner: Arc<WsClient>,
10}
11
12impl TokenProcedures {
13    /// Create authentication token
14    ///
15    /// xo-cli: token.create [expiresIn=<number|string>]
16    pub async fn create(&self) -> Result<Token, RpcError> {
17        // TODO: consider specifying the `expiresIn` parameter
18        let token: Token = self
19            .inner
20            .request("token.create", Some(ParamsSer::Map(BTreeMap::new())))
21            .await?;
22
23        Ok(token)
24    }
25}