some_random_api/endpoints/
premium.rs

1use crate::{RankCard, Requester, WelcomeImage};
2use anyhow::Result;
3use serde_json::to_string;
4
5/// An endpoint for premium users
6///
7/// # Examples
8///
9/// ```
10/// use some_random_api::Client;
11/// use std::fs::write;
12///
13/// write(
14///     "petpet.gif",
15///     Client::new(None::<String>)
16///         .premium
17///         .petpet("avatar url").await?,
18/// )?;
19/// ```
20pub struct PremiumEndpoint(pub(crate) Requester);
21
22impl PremiumEndpoint {
23    /// Sussy
24    pub async fn among_us<T: ToString, U: ToString, V: ToString>(
25        &self,
26        username: T,
27        avatar_url: U,
28        text: Option<V>,
29    ) -> Result<Vec<u8>> {
30        self.0
31            .request_image(
32                "premium/amongus",
33                &[
34                    ("username", username.to_string()),
35                    ("avatar", avatar_url.to_string()),
36                    ("custom", text.map_or("".into(), |text| text.to_string())),
37                ],
38            )
39            .await
40    }
41
42    // Petpet
43    pub async fn petpet<T: ToString>(&self, avatar_url: T) -> Result<Vec<u8>> {
44        self.0
45            .request_image("premium/petpet", &[("avatar", avatar_url.to_string())])
46            .await
47    }
48
49    // Generate a rank card
50    pub async fn rank_card(&self, rank_card: RankCard) -> Result<Vec<u8>> {
51        self.0
52            .request_image(
53                format!("premium/rankcard/{}", to_string(&rank_card.template)?),
54                &rank_card,
55            )
56            .await
57    }
58
59    // Generate a premium welcome image
60    pub async fn welcome(&self, welcome_image: WelcomeImage) -> Result<Vec<u8>> {
61        self.0
62            .request_image(
63                format!("premium/welcome/{}", to_string(&welcome_image.template)?),
64                &welcome_image,
65            )
66            .await
67    }
68}