misskey_api/endpoint/charts/
instance.rs

1use crate::model::chart::{
2    ChartSpan, DriveChart, FollowersChart, FollowingChart, NotesChart, RequestsChart, UsersChart,
3};
4
5use serde::{Deserialize, Serialize};
6use typed_builder::TypedBuilder;
7
8#[derive(Serialize, Debug, Clone, TypedBuilder)]
9#[serde(rename_all = "camelCase")]
10#[builder(doc)]
11pub struct Request {
12    pub span: ChartSpan,
13    #[builder(setter(into))]
14    pub host: String,
15    /// 1 .. 500
16    #[serde(skip_serializing_if = "Option::is_none")]
17    #[builder(default, setter(strip_option))]
18    pub limit: Option<u64>,
19    #[builder(default, setter(strip_option))]
20    pub offset: Option<u64>,
21}
22
23#[derive(Deserialize, Debug, Clone)]
24#[serde(rename_all = "camelCase")]
25pub struct Response {
26    pub requests: RequestsChart,
27    pub notes: NotesChart,
28    pub users: UsersChart,
29    pub following: FollowingChart,
30    pub followers: FollowersChart,
31    pub drive: DriveChart,
32}
33
34impl misskey_core::Request for Request {
35    type Response = Response;
36    const ENDPOINT: &'static str = "charts/instance";
37}
38
39#[cfg(test)]
40mod tests {
41    use super::Request;
42    use crate::test::{ClientExt, TestClient};
43
44    #[tokio::test]
45    async fn request() {
46        use crate::model::chart::ChartSpan;
47
48        let client = TestClient::new();
49        client
50            .test(Request {
51                span: ChartSpan::Day,
52                // TODO: use proper host string
53                host: "localhost:3000".to_string(),
54                limit: None,
55                offset: None,
56            })
57            .await;
58        client
59            .test(Request {
60                span: ChartSpan::Hour,
61                host: "localhost:3000".to_string(),
62                limit: None,
63                offset: None,
64            })
65            .await;
66    }
67
68    #[tokio::test]
69    async fn request_with_limit() {
70        use crate::model::chart::ChartSpan;
71
72        let client = TestClient::new();
73        client
74            .test(Request {
75                span: ChartSpan::Day,
76                host: "localhost:3000".to_string(),
77                limit: Some(500),
78                offset: None,
79            })
80            .await;
81    }
82
83    #[tokio::test]
84    async fn request_with_offset() {
85        use crate::model::chart::ChartSpan;
86
87        let client = TestClient::new();
88        client
89            .test(Request {
90                span: ChartSpan::Day,
91                host: "localhost:3000".to_string(),
92                limit: None,
93                offset: Some(5),
94            })
95            .await;
96    }
97}