openlegends_api/user/login/
request.rs

1pub mod data;
2pub mod error;
3pub mod header;
4
5pub use data::Data;
6pub use error::Error;
7pub use header::HEADER;
8
9pub struct Request {
10    data: Data,
11    header: String,
12}
13
14impl Request {
15    pub fn build(username: String, password: String) -> Result<Self, Error> {
16        Ok(Self {
17            data: Data::build(username, password),
18            header: HEADER.to_string(),
19        })
20    }
21
22    pub fn to_string(&self) -> Result<String, Error> {
23        Ok(format!(
24            "{}\r\n{}",
25            self.header,
26            match self.data.to_json() {
27                Ok(json) => json,
28                Err(e) => return Err(Error::Data(e)),
29            }
30        ))
31    }
32}