nle-cloud-sdk 0.1.1

Unofficial asynchronous Rust SDK for the NLECloud (新大陆物联网云平台) IoT platform
Documentation
//! # NLECloud SDK for Rust
//!
//! An idiomatic, asynchronous, thread-safe Rust SDK for the NLECloud (新大陆物联网云平台) IoT platform.
//!
//! ## Overview
//!
//! - **Async & Non-blocking**: Built on `tokio` and `reqwest` (with `rustls-tls`).
//! - **Immutable Client**: [`NleCloudClient`] configured via [`NleCloudClientBuilder`].
//! - **Generic Envelope Unwrapping**: Responses wrapped in upstream `ResultMsg` envelopes
//!   are automatically intercepted, mapping non-zero API statuses into [`SdkError::Api`].
//! - **Complete Model Coverage**: Strongly typed structs matching all NLECloud DTOs,
//!   including legacy PascalCase aliases (e.g. [`DeviceInfoDTO`]) for easy migration.
//!
//! ## Modules & Core APIs
//!
//! The client exposes operations across several domains:
//!
//! | Module | Core Methods | Description |
//! |---|---|---|
//! | [`api::auth`] | [`login`](NleCloudClient::login), [`get_current_token`](NleCloudClient::get_current_token) | User authentication & token management |
//! | [`api::projects`] | [`get_projects`](NleCloudClient::get_projects), [`add_project`](NleCloudClient::add_project), [`get_project_sensors`](NleCloudClient::get_project_sensors) | Project lifecycle & hierarchy queries |
//! | [`api::devices`] | [`get_devices`](NleCloudClient::get_devices), [`get_device_info`](NleCloudClient::get_device_info), [`get_devices_status`](NleCloudClient::get_devices_status) | Device CRUD & online status checks |
//! | [`api::sensors`] | [`get_sensors`](NleCloudClient::get_sensors), [`add_sensor_datas`](NleCloudClient::add_sensor_datas), [`get_sensor_datas`](NleCloudClient::get_sensor_datas) | Sensor management & telemetry time-series |
//! | [`api::commands`] | [`send_cmd`](NleCloudClient::send_cmd) | Actuator control & command dispatching |
//!
//! ## Quick Start
//!
//! ```no_run
//! use nle_cloud_sdk::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//!     // 1. Build an unauthenticated client
//!     let client = NleCloudClient::builder()
//!         .base_url("http://api.nlecloud.com")
//!         .build()?;
//!
//!     // 2. Authenticate
//!     let login_res = client.login_with_credentials("your_account", "your_password", false).await?;
//!     println!("Logged in! Token: {}", login_res.access_token);
//!
//!     // 3. Create an authenticated client clone
//!     let auth_client = client.with_token(login_res.access_token);
//!
//!     // 4. Query sensors for a device
//!     let sensors = auth_client.get_sensors(10367, None, None).await?;
//!     println!("Sensors found: {}", sensors.len());
//!
//!     // 5. Dispatch an actuator command (e.g. Turn On = 1)
//!     auth_client.send_cmd(10367, "nl_fan", &1, None).await?;
//!
//!     Ok(())
//! }
//! ```

#![warn(missing_docs)]

pub mod api;
pub mod client;
pub(crate) mod envelope;
pub mod error;
pub mod models;
pub mod utils;

pub use client::{DEFAULT_BASE_URL, DEFAULT_TIMEOUT, NleCloudClient, NleCloudClientBuilder};
pub use error::{Result, SdkError};
pub use models::*;

/// Convenient prelude module for re-exporting common types.
pub mod prelude {
    pub use crate::client::{
        DEFAULT_BASE_URL, DEFAULT_TIMEOUT, NleCloudClient, NleCloudClientBuilder,
    };
    pub use crate::error::{Result, SdkError};
    pub use crate::models::*;
}