pub struct UsersClient { /* private fields */ }Expand description
Client for user management operations.
This client provides methods to list and update application users.
It relies on a valid session stored in the cache, which must be obtained
by first logging in via LoginClient.
§Example
use cekunit_client::api::dashboard::UsersClient;
use std::collections::HashMap;
let client = UsersClient::new()?;
// Fetch the first page of users, sorted by name ascending
let html = client.get_users_list(Some(1), Some("name"), Some("asc"))?;
// Update an existing user (ID = 42)
let mut updates = HashMap::new();
updates.insert("name", "New Name");
updates.insert("email", "new@example.com");
client.update_user("42", updates)?;Implementations§
Source§impl UsersClient
impl UsersClient
Sourcepub fn new() -> Result<Self, ApiError>
pub fn new() -> Result<Self, ApiError>
Creates a new UsersClient with default configuration loaded from environment variables.
This is a convenience constructor that loads the configuration and creates a cache manager.
§Errors
Returns ApiError if:
- Environment variables are missing or invalid.
- The cache directory cannot be created.
- The HTTP client cannot be built.
Sourcepub fn with_config(config: EnvConfig) -> Result<Self, ApiError>
pub fn with_config(config: EnvConfig) -> Result<Self, ApiError>
Creates a new UsersClient with a given configuration.
This allows using a pre‑loaded configuration, for example when sharing configuration between multiple clients.
§Arguments
config- The environment configuration to use.
§Errors
Returns ApiError if:
- The cache directory cannot be created.
- The HTTP client cannot be built.
Sourcepub fn with_config_and_cache(
config: EnvConfig,
cache_manager: CacheManager,
) -> Result<Self, ApiError>
pub fn with_config_and_cache( config: EnvConfig, cache_manager: CacheManager, ) -> Result<Self, ApiError>
Creates a new UsersClient with a given configuration and an existing cache manager.
This is useful when sharing the same cache (and thus the same session) across multiple clients.
§Arguments
config- The environment configuration.cache_manager- An existing cache manager (typically from the main client).
§Errors
Returns ApiError if the HTTP client cannot be built.
Sourcepub fn get_users_list(
&self,
page: Option<u32>,
sort: Option<&str>,
direction: Option<&str>,
) -> Result<String, ApiError>
pub fn get_users_list( &self, page: Option<u32>, sort: Option<&str>, direction: Option<&str>, ) -> Result<String, ApiError>
Fetches the users list HTML with optional pagination and sorting.
This method sends a GET request to the users listing endpoint and returns the raw HTML of the page.
§Arguments
page- Optional page number (1‑based). IfNone, the first page is assumed.sort- Optional column name to sort by (e.g.,"name","email").direction- Optional sort direction ("asc"or"desc").
§Returns
The raw HTML of the users list as a String.
§Errors
Returns ApiError if:
- No valid session exists.
- The HTTP request fails (network, timeout).
- The server returns a non‑success status (4xx or 5xx).
- The response body cannot be read.
Sourcepub fn update_user(
&self,
id: &str,
data: HashMap<&str, &str>,
) -> Result<(), ApiError>
pub fn update_user( &self, id: &str, data: HashMap<&str, &str>, ) -> Result<(), ApiError>
Updates an existing user’s details.
This method sends a POST request with _method=PUT to the user item endpoint.
The CSRF token is automatically included, and the caller provides the fields to update.
§Arguments
id- The identifier of the user to update.data- A map of field names to new values. The map must not include_tokenor_method.
§Errors
Returns ApiError if:
- No valid session exists.
- The HTTP request fails.
- The server returns a non‑success status (2xx or 302 is considered success).
§Example
let mut updates = HashMap::new();
updates.insert("name", "Jane Doe");
updates.insert("email", "jane@example.com");
client.update_user("5", updates)?;Sourcepub fn get_csrf_token(&self) -> Result<String, ApiError>
pub fn get_csrf_token(&self) -> Result<String, ApiError>
Fetches a fresh CSRF token from the users list page.
This method retrieves the first page of the users list using
get_users_list and extracts the CSRF token from the HTML.
The token can be used for subsequent POST requests if needed.
§Returns
The CSRF token as a string.
§Errors
Returns ApiError if:
- No valid session exists.
- The users list page cannot be fetched.
- No CSRF token is found in the HTML.
Sourcepub fn cache_manager(&self) -> &CacheManager
pub fn cache_manager(&self) -> &CacheManager
Returns a reference to the cache manager.