but safer
This commit is contained in:
parent
b3b0160497
commit
2e4778f2f9
1 changed files with 18 additions and 12 deletions
|
@ -49,22 +49,28 @@ pub struct Client {
|
|||
|
||||
impl Client {
|
||||
pub fn new(url: &str, username: &str, token: &str, salt: &str) -> Result<Self, Error> {
|
||||
let base_url = reqwest::Url::parse_with_params(
|
||||
url,
|
||||
&[
|
||||
("u", username),
|
||||
("t", token),
|
||||
("s", salt),
|
||||
("v", "1.16.1"),
|
||||
("c", "eu.callcc.audrey"),
|
||||
("f", "json"),
|
||||
],
|
||||
)
|
||||
.map_err(|err| Error::UrlParseError(err.to_string()))?;
|
||||
|
||||
if base_url.scheme() != "http" && base_url.scheme() != "https" {
|
||||
return Err(Error::UrlParseError("Url scheme is not HTTP(s)".into()));
|
||||
}
|
||||
|
||||
Ok(Client {
|
||||
client: reqwest::Client::builder()
|
||||
.user_agent("audrey/linux") // Audrey.Const.user_agent
|
||||
.build()?,
|
||||
base_url: reqwest::Url::parse_with_params(
|
||||
url,
|
||||
&[
|
||||
("u", username),
|
||||
("t", token),
|
||||
("s", salt),
|
||||
("v", "1.16.1"),
|
||||
("c", "eu.callcc.audrey"),
|
||||
("f", "json"),
|
||||
],
|
||||
)
|
||||
.map_err(|err| Error::UrlParseError(err.to_string()))?,
|
||||
base_url,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue