Skip to main content

altstream_api/
api.rs

1
2use std::error::Error;
3
4use crate::{pub_transmission_types::*, request::*};
5
6const BASE: &str = "https://altstream.online/api/v1";
7
8/// Get information about a channel.
9///
10/// # Example
11/// ```
12/// # #[tokio::main]
13/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
14/// let channel_info = altstream_api::get_channel_info("letsgoashe").await?;
15/// # Ok(())
16/// # }
17/// ```
18///
19/// See [AltStream Online API documentation](https://altstream.online/documentation?tab=api).
20pub async fn get_channel_info(username: &str) -> Result<ChannelInfo, Box<dyn Error>> {
21    parse_unwrap_response(&request(&format!("{BASE}/channels/{username}")).await?)
22}
23
24/// Get information about a channel's panels.
25///
26/// # Example
27/// ```
28/// # #[tokio::main]
29/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
30/// let panels = altstream_api::get_channel_panels("letsgoashe").await?;
31/// # Ok(())
32/// # }
33/// ```
34///
35/// See [AltStream Online API documentation](https://altstream.online/documentation?tab=api).
36pub async fn get_channel_panels(username: &str) -> Result<Panels, Box<dyn Error>> {
37    parse_unwrap_response(&request(&format!("{BASE}/channels/{username}/panels")).await?)
38}
39
40/// Get information about a channel's rewards.
41///
42/// # Example
43/// ```
44/// # #[tokio::main]
45/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
46/// let rewards = altstream_api::get_channel_rewards("letsgoashe").await?;
47/// # Ok(())
48/// # }
49/// ```
50///
51/// See [AltStream Online API documentation](https://altstream.online/documentation?tab=api).
52pub async fn get_channel_rewards(username: &str) -> Result<ChannelRewards, Box<dyn Error>> {
53    parse_unwrap_response(&request(&format!("{BASE}/channels/{username}/rewards")).await?)
54}
55
56/// Get information about a channel's emotes.
57///
58/// # Example
59/// ```
60/// # #[tokio::main]
61/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
62/// let emotes = altstream_api::get_channel_emotes("letsgoashe").await?;
63/// # Ok(())
64/// # }
65/// ```
66///
67/// See [AltStream Online API documentation](https://altstream.online/documentation?tab=api).
68pub async fn get_channel_emotes(username: &str) -> Result<ChannelEmotes, Box<dyn Error>> {
69    parse_unwrap_response(&request(&format!("{BASE}/channels/{username}/emotes")).await?)
70}
71
72/// Get information about a stream's tags.
73///
74/// # Example
75/// ```
76/// # #[tokio::main]
77/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
78/// let tags = altstream_api::get_stream_tags("letsgoashe").await?;
79/// # Ok(())
80/// # }
81/// ```
82///
83/// See [AltStream Online API documentation](https://altstream.online/documentation?tab=api).
84pub async fn get_stream_tags(username: &str) -> Result<StreamTags, Box<dyn Error>> {
85    parse_unwrap_response(&request(&format!("{BASE}/channels/{username}/tags")).await?)
86}
87
88/// Get information about a user's settings.
89///
90/// # Example
91/// ```
92/// # #[tokio::main]
93/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
94/// let settings = altstream_api::get_user_settings("letsgoashe").await?;
95/// # Ok(())
96/// # }
97/// ```
98///
99/// See [AltStream Online API documentation](https://altstream.online/documentation?tab=api).
100pub async fn get_user_settings(username: &str) -> Result<UserSettings, Box<dyn Error>> {
101    // user settings is the only endpoint that doesn't return a wrapped response,
102    // so we use parse_response instead of parse_unwrap_response
103    parse_response(&request(&format!("{BASE}/user-settings/{username}")).await?)
104}
105
106/// Get information about a user's settings for a specific channel.
107///
108/// # Example
109/// ```
110/// # #[tokio::main]
111/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
112/// let settings = altstream_api::get_user_channel_settings("soweliluna", "letsgoashe").await?;
113/// # Ok(())
114/// # }
115/// ```
116///
117/// See [AltStream Online API documentation](https://altstream.online/documentation?tab=api).
118pub async fn get_user_channel_settings(
119    username: &str,
120    channel: &str,
121) -> Result<UserSettings, Box<dyn Error>> {
122    parse_response(
123        &request(&format!(
124            "{BASE}/user-settings/{username}?channel={channel}"
125        ))
126        .await?,
127    )
128}