rsteam/steam_apps/
get_app_list.rs

1use crate::utils::{Result, AUTHORITY};
2use crate::SteamClient;
3
4use hyper::body::to_bytes;
5use hyper::Uri;
6
7use serde::Deserialize;
8use serde_json::from_slice;
9
10const PATH: &str = "/ISteamApps/GetAppList/v0002";
11
12#[derive(Deserialize)]
13pub struct App {
14    #[serde(rename = "appid")]
15    pub id: u32,
16    pub name: String,
17}
18
19#[derive(Deserialize)]
20struct Apps {
21    apps: Vec<App>,
22}
23
24#[derive(Deserialize)]
25struct Response {
26    applist: Apps,
27}
28
29impl SteamClient {
30    /// Gets full list of all applications available in the steam store
31    ///
32    /// App list is very long so it's not recommended to query often
33    pub async fn get_app_list(&self) -> Result<Vec<App>> {
34        let uri = Uri::builder()
35            .scheme("https")
36            .authority(AUTHORITY)
37            .path_and_query(PATH)
38            .build()?;
39
40        let raw_response = self.client.get(uri).await?;
41        let raw_body = raw_response.into_body();
42        let response: Response = from_slice(&to_bytes(raw_body).await?)?;
43
44        Ok(response.applist.apps)
45    }
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51    use tokio_test::block_on;
52
53    #[test]
54    fn csgo_is_in_the_list() {
55        let client = SteamClient::new();
56        let apps = block_on(client.get_app_list()).unwrap();
57        assert!(apps
58            .iter()
59            .any(|app| app.id == 730 && app.name == "Counter-Strike 2"));
60    }
61}