nhentairs/src/api.rs

27 lines
757 B
Rust
Raw Normal View History

2023-10-28 00:08:10 +00:00
use crate::structs;
extern crate serde_json;
2023-10-28 00:11:16 +00:00
pub async fn get_sauce_info(
client: reqwest::Client,
sauce: i32,
) -> Result<structs::GalleryInfo, reqwest::Error> {
2023-10-28 00:08:10 +00:00
let mut uri = String::from("https://nhentai.net/api/gallery/");
uri.push_str(&sauce.to_string());
2023-10-28 00:11:16 +00:00
let resp = client.get(&uri).send().await?;
2023-10-28 00:08:10 +00:00
Ok(serde_json::from_str(&resp.text().await?).unwrap())
}
2023-10-28 00:11:16 +00:00
pub async fn get_search_info(
client: reqwest::Client,
search_query: &str,
) -> Result<structs::SearchInfo, reqwest::Error> {
2023-10-28 00:08:10 +00:00
let uri = "https://nhentai.net/api/galleries/search";
2023-10-28 00:11:16 +00:00
let resp = client
.get(uri)
2023-10-28 00:08:10 +00:00
.query(&[("query", search_query)])
.send()
.await?;
Ok(serde_json::from_str(&resp.text().await?).unwrap())
}