Skip to main content

Crate librcekunit

Crate librcekunit 

Source
Expand description

§CekUnit Client Library

A comprehensive Rust client for interacting with the CekUnit web application. This library provides a type-safe, ergonomic API for authentication and all major features of the CekUnit platform, including dashboard management, input data (nasabah) operations, PIC (Person In Charge) management, user management, and export functionality.

§Overview

The library is structured around a main client CekUnitClient that manages a shared session cache and provides access to specialized sub‑clients for different parts of the application. All network operations are performed via a blocking reqwest client with configurable timeouts, retries, and connection pooling.

§Features

  • Authentication: Login with email/password, automatic CSRF token handling, session persistence via filesystem cache.
  • Dashboard: Fetch paginated CekUnit lists, export data (Excel, PDF, CSV), get unique column values, delete records (single, by category, or all).
  • Input Data (Nasabah): Submit new customer records.
  • Input User: List and export user‑input data with search, sort, and date filters.
  • PIC Management: Create, update, delete, and list Persons In Charge.
  • User Management: List and update application users.

§Caching

Upon successful login, session cookies and the current CSRF token are stored in a JSON file inside the system’s cache directory (e.g., ~/.cache/cekunit/ on Linux). All subsequent requests automatically attach these cookies, so you only need to log in once per session.

§Environment Configuration

The library reads configuration from environment variables (or a .env file). Required variables include:

  • USER_EMAIL – login email
  • USER_PASSWORD – login password
  • BASE_URL – base URL of the CekUnit installation (e.g., https://example.com)
  • Various endpoint variables (see EnvConfig documentation for the full list)

§Example

use cekunit_client::CekUnitClient;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create the main client – loads configuration from environment
    let mut client = CekUnitClient::new()?;

    // Log in (if no valid session exists, this will perform a new login)
    let session = client.login()?;
    println!("Logged in at: {}", session.timestamp);

    // Access the dashboard client
    let dashboard = client.dashboard()?;
    let html = dashboard.get_dashboard(Some(1), None, Some("created_at"), Some("desc"))?;

    // Export data as Excel
    let excel_data = dashboard.export_cekunit("excel", "created_at", "desc")?;
    std::fs::write("export.xlsx", excel_data)?;

    // Log out when done
    client.logout()?;

    Ok(())
}

Re-exports§

pub use crate::api::auth::loging::LoginClient;
pub use crate::api::auth::logout::LogoutClient;
pub use crate::api::auth::utils::cache::CacheData;
pub use crate::api::auth::utils::cache::CacheManager;
pub use crate::api::dashboard::DashboardClient;
pub use crate::api::dashboard::InputDataClient;
pub use crate::api::dashboard::InputUserClient;
pub use crate::api::dashboard::PicClient;
pub use crate::api::dashboard::UsersClient;
pub use crate::client::CekUnitClient;
pub use crate::handler::env::EnvConfig;
pub use crate::handler::error::ApiError;

Modules§

api
client
Main client for the CekUnit API.
handler
utils
Utility functions and types for internal use, but exposed for advanced scenarios.

Structs§

BuildInfo
Build metadata for the CekUnit client crate.

Functions§

build_info
Returns a BuildInfo struct containing metadata about the crate.
name
Returns the current crate name as defined in Cargo.toml.
version
Returns the current crate version as defined in Cargo.toml.