wattpad/
raw_api.rs

1use anyhow::Result;
2use reqwest::{Client, Url};
3use serde_json::Value;
4
5pub async fn get(
6    path: String,
7    params: Vec<(&str, &str)>,
8    use_api: bool,
9    client: &Client,
10) -> Result<Value> {
11    //FIXME: these should be user configurable incase someone reimplements the wattpad backend and hosts it themselves for some ungodly reason (definitely not me :trollface:)
12    let url = if use_api {
13        Url::parse_with_params(&format!("https://api.wattpad.com{}", path), params.iter())?
14    } else {
15        Url::parse_with_params(&format!("https://www.wattpad.com{}", path), params.iter())?
16    };
17    let resp = client.get(url).send().await?;
18    Ok(resp.json::<Value>().await?)
19}
20
21pub async fn get_text(
22    path: String,
23    params: Vec<(&str, &str)>,
24    use_api: bool,
25    client: &Client,
26) -> Result<String> {
27    //FIXME: these should be user configurable incase someone reimplements the wattpad backend and hosts it themselves for some ungodly reason (definitely not me :trollface:)
28    let url = if use_api {
29        Url::parse_with_params(&format!("https://api.wattpad.com{}", path), params.iter())?
30    } else {
31        Url::parse_with_params(&format!("https://www.wattpad.com{}", path), params.iter())?
32    };
33    let resp = client.get(url).send().await?;
34
35    Ok(resp.text().await?)
36}