Skip to main content

roblox_api/api/games/
v2.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{AssetTypeId, DateTime, Paging, endpoint};
4
5pub const URL: &str = "https://games.roblox.com/v2";
6
7#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
8#[serde(rename_all = "camelCase")]
9pub struct UniverseMedia {
10    pub asset_type: AssetTypeId,
11    pub asset_type_id: u8,
12
13    pub approved: bool,
14    pub alt_text: Option<String>,
15
16    pub image_id: Option<u64>,
17
18    pub video_id: Option<String>,
19    pub video_hash: Option<String>,
20    pub video_title: Option<String>,
21}
22
23// TODO: use CreatorType instead
24#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
25pub struct GameCreator {
26    pub id: u64,
27    #[serde(rename = "type")]
28    pub kind: String,
29    pub name: Option<String>,
30}
31
32#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
33pub struct GameRootPlace {
34    pub id: u64,
35    #[serde(rename = "type")]
36    pub kind: String,
37}
38
39#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
40#[serde(rename_all = "camelCase")]
41pub struct Game {
42    pub id: u64,
43    pub name: String,
44    pub description: Option<String>,
45
46    pub creator: GameCreator,
47    pub root_place: GameRootPlace,
48
49    pub created: DateTime,
50    pub updated: DateTime,
51
52    pub price: Option<u64>,
53    pub place_visits: u64,
54}
55
56#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
57pub struct GamesResponse {
58    #[serde(rename = "data")]
59    pub games: Vec<Game>,
60    #[serde(rename = "nextPageCursor")]
61    pub next_cursor: Option<String>,
62    #[serde(rename = "previousPageCursor")]
63    pub previous_cursor: Option<String>,
64}
65
66endpoint! {
67    universe_media(id: u64, all_experiences: bool) -> Vec<UniverseMedia> {
68        GET "{URL}/games/{id}/media";
69        types {
70            Response {
71                media("data"): Vec<UniverseMedia>,
72            }
73        }
74        prelude {
75            let all_experiences = all_experiences.to_string();
76        }
77        query {
78            "fetchAllExperienceRelatedMedia" => &all_experiences,
79        }
80        map |r: Response| r.media
81    }
82
83    /// Apparently this API only works on owned groups, use v2 instead
84    /// Set `access_filter` to 1, if you want a valid response
85    group_games(id: u64, access_filter: u8, paging: Paging<'_>) -> GamesResponse {
86        GET "{URL}/groups/{id}/games";
87        paging_query { paging, limit = 10 }
88        prelude {
89            let access_filter = access_filter.to_string();
90        }
91        query {
92            "accessFilter" => &access_filter,
93        }
94    }
95
96    /// Set `access_filter` to 1, if you want a valid response
97    group_games_v2(id: u64, access_filter: u8, paging: Paging<'_>) -> GamesResponse {
98        GET "{URL}/groups/{id}/gamesV2";
99        paging_query { paging, limit = 10 }
100        prelude {
101            let access_filter = access_filter.to_string();
102        }
103        query {
104            "accessFilter" => &access_filter,
105        }
106    }
107
108    /// Set `access_filter` to 2, if you want a valid response
109    user_games(id: u64, access_filter: u8, paging: Paging<'_>) -> GamesResponse {
110        GET "{URL}/users/{id}/games";
111        paging_query { paging, limit = 10 }
112        prelude {
113            let access_filter = access_filter.to_string();
114        }
115        query {
116            "accessFilter" => &access_filter,
117        }
118    }
119
120    /// Set `access_filter` to 2, if you want a valid response
121    user_favorited_games(id: u64, access_filter: u8, paging: Paging<'_>) -> GamesResponse {
122        GET "{URL}/users/{id}/favorite/games";
123        paging_query { paging, limit = 10 }
124        prelude {
125            let access_filter = access_filter.to_string();
126        }
127        query {
128            "accessFilter" => &access_filter,
129        }
130    }
131}