some_random_api/endpoints/
others.rs1use crate::{Base64, Binary, BotToken, Dictionary, Joke, Lyrics, Requester, Text};
2use anyhow::Result;
3
4pub struct OthersEndpoint(pub(crate) Requester);
14
15impl OthersEndpoint {
16 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 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 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 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 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 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 pub async fn joke(&self) -> Result<Joke> {
65 self.0.request("others/joke", None::<&()>).await
66 }
67
68 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}