Skip to main content

dogehouse_api/
endpoints.rs

1use std::collections::BTreeMap as Map;
2use serde::Deserialize;
3use serde_json::Value;
4
5pub(crate) const BASE_URL: &'static str = "https://api.dogegarden.net/v1";
6
7#[async_trait::async_trait]
8/// Defines a 
9pub trait Endpoint {
10    /// Defines which scheme the endpoint is using.
11    type Scheme;
12    /// Sends a request to the endpoint, and deserializes it.
13    async fn send() -> Result<Self::Scheme, crate::ErrorType>;
14}
15
16crate::endpoint!(
17    #[doc = "This defines the binding for the /statistics endpoint in the API."]
18    Statistics,
19    StatisticsScheme,
20    "/statistics"
21);
22
23#[derive(Deserialize, PartialEq, Clone, Debug)]
24#[serde(rename_all = "camelCase")]
25/// The scheme defining what the API will return upon utilizing the /statistics endpoint.
26pub struct StatisticsScheme {
27    total_rooms: u64,
28    total_scheduled_rooms: u64,
29    total_registered: u64,
30    total_online: u64,
31    total_bots_online: u64,
32    total_bots_sending_telemetry: u64,
33}
34
35crate::endpoint!(
36    #[doc = "This defines the binding for the /popularRooms endpoint in the API."]
37    PopularRooms,
38    PopularRoomsScheme,
39    "/popularRooms"
40);
41
42#[derive(Deserialize, PartialEq, Clone, Debug)]
43#[serde(rename_all = "camelCase")]
44/// The scheme defining what the API will return upon utilizing the /popularRooms endpoint.
45pub struct PopularRoomsScheme {
46    rooms: Vec<PopularRoom>,
47    #[serde(flatten)]
48    // Some undocumented items are inside of /popularRooms
49    undocumented: Map<String, Value>,
50}
51
52#[derive(Deserialize, PartialEq, Clone, Debug)]
53#[serde(rename_all = "camelCase")]
54/// A room in a [PopularRoomsScheme].
55pub struct PopularRoom {
56    id: String,
57    name: String,
58    description: String,
59    num_people_inside: u64,
60    is_private: bool,
61    // Undocumented
62    chat_mode: String,
63    // Undocumented
64    chat_throttle: u64,
65    // Undocumented
66    auto_speaker: bool,
67    creator_id: String,
68    people_preview_list: Vec<PopularRoomUser>,
69    voice_server_id: String,
70    // Really Dogegarden?
71    #[serde(rename = "inserted_at")]
72    inserted_at: String,
73}
74
75#[derive(Deserialize, PartialEq, Clone, Debug)]
76#[serde(rename_all = "camelCase")]
77/// Defines a user inside of a [PopularRoom].
78pub struct PopularRoomUser {
79    id: String,
80    display_name: String,
81    num_followers: u64,
82    avatar_url: String,
83}
84
85crate::endpoint!(
86    #[doc = "This defines the binding for the /bots endpoint in the API."]
87    Bots,
88    Vec<Bot>,
89    "/bots"
90);
91
92#[derive(Deserialize, PartialEq, Clone, Debug)]
93#[serde(rename_all = "camelCase")]
94/// Defines a bot in the /bots API endpoint.
95pub struct Bot {
96    #[serde(rename = "_id")]
97    id: String,
98    #[serde(rename = "socket_id")]
99    socket_id: String,
100    bot: BotInner,
101    // This isn't even the same as other rooms
102    // Or in the docs
103    room: Map<String, Value>,
104}
105
106#[derive(Deserialize, PartialEq, Clone, Debug)]
107#[serde(rename_all = "camelCase")]
108/// For some reason, a bot contains a bot field, which contains these fields.
109pub struct BotInner {
110    uuid: String,
111    username: String,
112    avatar: String,
113}
114
115#[derive(Deserialize, PartialEq, Clone, Debug)]
116#[serde(rename_all = "camelCase")]
117/// Defines a room, which a [Bot] is in.
118pub struct BotRoom {
119    // Not in docs, AFAIK always null.
120    uuid: Value,
121    name: String,
122    listening: u64,
123    // Not in the docs, AFAIK always an empty vec.
124    users: Vec<Value>,
125}
126
127crate::endpoint!(
128    #[doc = "This defines the binding for the /scheduledRooms endpoint in the API."]
129    ScheduledRooms,
130    ScheduledRoomsScheme,
131    "/scheduledRooms"
132);
133
134#[derive(Deserialize, PartialEq, Clone, Debug)]
135#[serde(rename_all = "camelCase")]
136/// The scheme defining what the API will return upon utilizing the /scheduledRooms endpoint.
137pub struct ScheduledRoomsScheme {
138    scheduled_rooms: Vec<ScheduledRoom>,
139}
140
141#[derive(Deserialize, PartialEq, Clone, Debug)]
142#[serde(rename_all = "camelCase")]
143/// A room in the [ScheduledRoomsScheme].
144pub struct ScheduledRoom {
145    id: String,
146    name: String,
147    num_attending: u64,
148    scheduled_for: String,
149    description: String,
150    // ?? This will always be null, since the room hasn't started yet; It's an upcoming room.
151    room_id: Value,
152    creator: User,
153    creator_id: String,
154}
155
156
157#[derive(Deserialize, PartialEq, Clone, Debug)]
158#[serde(rename_all = "camelCase")]
159/// The owner of a [ScheduledRoom], or a user queried after calling
160/// [crate::queries::UserByUserName].
161pub struct User {
162    avatar_url: Option<String>,
163    banner_url: Option<String>,
164    bio: String,
165    // Not documented, and I cannot make sense out of this.
166    bot_owner_id: Value,
167    display_name: String,
168    // In the current state of the API always null.
169    follows_you: Value,
170    // In the current state of the API always null.
171    i_blocked_them: Value,
172    id: String,
173    last_online: String,
174    num_followers: u64,
175    num_following: u64,
176    online: bool,
177    // In the current state of the API always null.
178    room_permissions: Value,
179    username: String,
180    // "on" or "off" ??
181    whisper_privacy_setting: String,
182    // In the current state of the API always null.
183    you_are_following: Value,
184}