use crate::client::NleCloudClient;
use crate::error::{Result, SdkError};
use crate::models::{AccountLoginDto, AccountLoginResultDto};
use reqwest::Method;
impl NleCloudClient {
pub async fn login(&self, req: &AccountLoginDto) -> Result<AccountLoginResultDto> {
if req.account.trim().is_empty() || req.password.trim().is_empty() {
return Err(SdkError::InvalidParameter(
"Account username and password must not be empty".to_string(),
));
}
let body = serde_json::to_value(req)?;
self.request_with_envelope(
Method::POST,
"users/login",
&[],
Some(body),
None,
false, )
.await
}
pub async fn login_with_credentials(
&self,
account: &str,
password: &str,
is_remember_me: bool,
) -> Result<AccountLoginResultDto> {
let req = AccountLoginDto {
account: account.to_string(),
password: password.to_string(),
is_remember_me: Some(is_remember_me),
};
self.login(&req).await
}
pub async fn get_current_token(
&self,
token_override: Option<&str>,
) -> Result<serde_json::Value> {
self.request_with_envelope(
Method::POST,
"users/getcurrenttoken",
&[],
None,
token_override,
true,
)
.await
}
}