1pub mod function;
2pub mod schema;
3
4use crate::{ChmlApi, res::ApiResult};
5
6impl ChmlApi {
8 pub async fn login(
10 &mut self,
11 login_params: &function::LoginParams,
12 ) -> ApiResult<schema::UserInfo> {
13 function::login(self, login_params).await
14 }
15
16 pub async fn send_email_code(
18 &self,
19 sec_params: &function::SendEmailCodeParams,
20 ) -> ApiResult<()> {
21 function::send_email_code(self, sec_params).await
22 }
23
24 pub async fn register(&self, register_params: &function::RegisterParams) -> ApiResult<()> {
26 function::register(self, register_params).await
27 }
28
29 pub async fn user_info(&self) -> ApiResult<schema::UserInfo> {
31 function::get_user_info(&self).await
32 }
33
34 pub async fn retoken(&self, reset_token_params: &function::ResetTokenParams) -> ApiResult<()> {
36 function::reset_token(self, reset_token_params).await
37 }
38
39 pub async fn qiandao(&self, checkin_params: &function::CheckinParams) -> ApiResult<()> {
41 function::checkin(self, checkin_params).await
42 }
43
44 pub async fn reset_password(
46 &self,
47 reset_password_params: &function::ResetPasswordParams,
48 ) -> ApiResult<()> {
49 function::reset_password(self, reset_password_params).await
50 }
51
52 pub async fn update_username(&self, new_username: &str) -> ApiResult<()> {
54 function::update_username(self, new_username).await
55 }
56
57 pub async fn update_qq(&self, new_qq: &str) -> ApiResult<()> {
59 function::update_qq(self, new_qq).await
60 }
61
62 pub async fn update_userimg(&self, new_user_img_url: &str) -> ApiResult<()> {
64 function::update_user_img_url(self, new_user_img_url).await
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71 use crate::prelude::*;
72
73 #[tokio::test]
74 async fn test_login_success() {
75 init_logger();
76
77 let mut chml_api = ChmlApi::from_env().unwrap();
78 let login_params = function::LoginParams {
79 username: "username".to_string(),
80 password: "password".to_string(),
81 };
82 let res = chml_api.login(&login_params).await;
83 println!("{:?}", res);
84 }
85
86 #[tokio::test]
87 async fn test_user_info() {
88 init_logger();
89
90 let mut chml_api = ChmlApi::from_env().unwrap();
91 let login_params = function::LoginParams {
92 username: "username".to_string(),
93 password: "password".to_string(),
94 };
95 let _ = chml_api.login(&login_params).await;
96 let res = chml_api.user_info().await;
97 println!("{:?}", res);
98 }
99}