nle-cloud-sdk 0.1.1

Unofficial asynchronous Rust SDK for the NLECloud (新大陆物联网云平台) IoT platform
Documentation
use serde::{Deserialize, Serialize};

/// Credentials used to log in to NLECloud (`AccountLoginDTO`).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct AccountLoginDto {
    /// Account username or registered phone number.
    pub account: String,

    /// Account password.
    pub password: String,

    /// Whether to remember credentials.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub is_remember_me: Option<bool>,
}

impl AccountLoginDto {
    /// Creates a new login request with account and password.
    pub fn new(account: impl Into<String>, password: impl Into<String>) -> Self {
        Self {
            account: account.into(),
            password: password.into(),
            is_remember_me: None,
        }
    }

    /// Sets the `is_remember_me` flag.
    pub fn remember_me(mut self, remember: bool) -> Self {
        self.is_remember_me = Some(remember);
        self
    }
}

/// Authentication result returned upon successful login (`AccountLoginResultDTO`).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct AccountLoginResultDto {
    /// User identifier.
    #[serde(rename = "UserID", alias = "UserId")]
    pub user_id: i32,

    /// Username.
    pub user_name: Option<String>,

    /// Email address.
    pub email: Option<String>,

    /// Telephone number.
    #[serde(rename = "Telphone", alias = "Telephone")]
    pub telphone: Option<String>,

    /// Gender (true = male, false = female).
    pub gender: Option<bool>,

    /// Organization / School ID.
    #[serde(rename = "CollegeID", alias = "CollegeId")]
    pub college_id: Option<i32>,

    /// Organization / School name.
    pub college_name: Option<String>,

    /// User role name.
    pub role_name: Option<String>,

    /// User role ID.
    #[serde(rename = "RoleID", alias = "RoleId")]
    pub role_id: Option<i32>,

    /// API authentication access token.
    pub access_token: String,
}