some_random_api/endpoints/
others.rs

1use crate::{Base64, Binary, BotToken, Dictionary, Joke, Lyrics, Requester, Text};
2use anyhow::Result;
3
4/// An endpoint that sends other random stuff
5///
6/// # Examples
7///
8/// ```
9/// use some_random_api::Client;
10///
11/// Client::new(None::<String>).others.joke().await?;
12/// ```
13pub struct OthersEndpoint(pub(crate) Requester);
14
15impl OthersEndpoint {
16    /// Decode Base64
17    pub async fn decode_base64<T: ToString>(&self, text: T) -> Result<Text> {
18        self.0
19            .request("others/base64", Some(&[("decode", text.to_string())]))
20            .await
21    }
22
23    /// Encode Base64
24    pub async fn encode_base64<T: ToString>(&self, text: T) -> Result<Base64> {
25        self.0
26            .request("others/base64", Some(&[("encode", text.to_string())]))
27            .await
28    }
29
30    // Decode binary
31    pub async fn decode_binary<T: ToString>(&self, text: T) -> Result<Text> {
32        self.0
33            .request("others/binary", Some(&[("decode", text.to_string())]))
34            .await
35    }
36
37    // Encode binary
38    pub async fn encode_binary<T: ToString>(&self, text: T) -> Result<Binary> {
39        self.0
40            .request("others/binary", Some(&[("encode", text.to_string())]))
41            .await
42    }
43
44    // Generate a random Discord bot token
45    pub async fn bot_token<T: ToString>(&self, bot_id: Option<T>) -> Result<BotToken> {
46        match bot_id {
47            Some(bot_id) => {
48                self.0
49                    .request("others/bottoken", Some(&[("id", bot_id.to_string())]))
50                    .await
51            }
52            None => self.0.request("others/bottoken", None::<&()>).await,
53        }
54    }
55
56    /// Look up words
57    pub async fn dictionary<T: ToString>(&self, word: T) -> Result<Dictionary> {
58        self.0
59            .request("others/dictionary", Some(&[("word", word.to_string())]))
60            .await
61    }
62
63    /// Generate a random joke
64    pub async fn joke(&self) -> Result<Joke> {
65        self.0.request("others/joke", None::<&()>).await
66    }
67
68    /// Look up lyrics for a song
69    pub async fn lyrics<T: ToString>(&self, title: T) -> Result<Lyrics> {
70        self.0
71            .request("others/lyrics", Some(&[("title", title.to_string())]))
72            .await
73    }
74}