+ Login route added to net module

! No wrapper goes around this module to avoid fragmentation
Note that basically every network hit is built around try's so they'll all return
HttpResult<T>'s
This commit is contained in:
shockrah 2021-04-05 17:41:28 -07:00
parent adea888b21
commit 10e8b7331f

19
tui/src/net.rs Normal file
View File

@ -0,0 +1,19 @@
use crate::api_types::Channel;
use crate::api_types::Jwt;
use reqwest::{Client, Url};
use reqwest::Result as HttpResult;
pub async fn login(url: &str, id: u64, secret: &str) -> HttpResult<String> {
let client = Client::new();
let mut url = Url::parse(&format!("{}/login", url)).unwrap();
url.query_pairs_mut().append_pair("id", &format!("{}", id));
url.query_pairs_mut().append_pair("secret", secret);
let response: Jwt = client.get(url).send().await?.json().await?;
Ok(response.jwt)
}
fn list_channels(url: &str, id: u64, secret: &str) -> Vec<Channel> {
todo!()
}