blob: 97af63c77f56a0c94faceadb375629d3843b3159 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
use crate::{Error, RandomTeawie};
use std::future::Future;
use log::trace;
const TEAWIE_API: &str = "https://api.getchoo.com";
pub trait Ext {
/// Get a random teawie
///
/// # Errors
///
/// Will return [`Err`] if the request fails or the response cannot be deserialized
fn random_teawie(&self) -> impl Future<Output = Result<RandomTeawie, Error>> + Send;
}
impl Ext for super::Client {
async fn random_teawie(&self) -> Result<RandomTeawie, Error> {
let url = format!("{TEAWIE_API}/random_teawie");
let request = self.get(&url).build()?;
trace!("Making GET request to {}", request.url());
let response = self.execute(request).await?;
response.error_for_status_ref()?;
let random_teawie: RandomTeawie = response.json().await?;
Ok(random_teawie)
}
}
|