misskey_api/endpoint/charts/
hashtag.rs

1use crate::model::{
2    chart::{ChartSpan, HashtagChart},
3    note::Tag,
4};
5
6use serde::{Deserialize, Serialize};
7use typed_builder::TypedBuilder;
8
9#[derive(Serialize, Debug, Clone, TypedBuilder)]
10#[serde(rename_all = "camelCase")]
11#[builder(doc)]
12pub struct Request {
13    pub span: ChartSpan,
14    pub tag: Tag,
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 local: HashtagChart,
27    pub remote: HashtagChart,
28}
29
30impl misskey_core::Request for Request {
31    type Response = Response;
32    const ENDPOINT: &'static str = "charts/hashtag";
33}
34
35#[cfg(test)]
36mod tests {
37    use super::Request;
38    use crate::test::{ClientExt, TestClient};
39
40    #[tokio::test]
41    async fn request() {
42        use crate::model::{chart::ChartSpan, note::Tag};
43
44        let client = TestClient::new();
45        client
46            .test(Request {
47                span: ChartSpan::Day,
48                tag: Tag("tag".to_string()),
49                limit: None,
50                offset: None,
51            })
52            .await;
53        client
54            .test(Request {
55                span: ChartSpan::Hour,
56                tag: Tag("tag".to_string()),
57                limit: None,
58                offset: None,
59            })
60            .await;
61    }
62
63    #[tokio::test]
64    async fn request_with_limit() {
65        use crate::model::{chart::ChartSpan, note::Tag};
66
67        let client = TestClient::new();
68        client
69            .test(Request {
70                span: ChartSpan::Day,
71                tag: Tag("tag".to_string()),
72                limit: Some(500),
73                offset: None,
74            })
75            .await;
76    }
77
78    #[tokio::test]
79    async fn request_with_offset() {
80        use crate::model::{chart::ChartSpan, note::Tag};
81
82        let client = TestClient::new();
83        client
84            .test(Request {
85                span: ChartSpan::Day,
86                tag: Tag("tag".to_string()),
87                limit: None,
88                offset: Some(5),
89            })
90            .await;
91    }
92}