gewe_http/moments/
timeline.rs

1use crate::client::GeweHttpClient;
2use gewe_core::{
3    GetContactsSnsListRequest, GetContactsSnsListResponse, GetSelfSnsListRequest,
4    GetSelfSnsListResponse, GetSnsDetailsRequest, GetSnsDetailsResponse, GeweError,
5};
6use tracing::instrument;
7
8impl GeweHttpClient {
9    #[instrument(skip(self))]
10    pub async fn get_self_sns_list(
11        &self,
12        req: GetSelfSnsListRequest<'_>,
13    ) -> Result<GetSelfSnsListResponse, GeweError> {
14        let env = self
15            .post_api::<_, GetSelfSnsListResponse>("gewe/v2/api/sns/snsList", &req)
16            .await?;
17        env.data.ok_or(GeweError::MissingData)
18    }
19
20    #[instrument(skip(self))]
21    pub async fn get_contacts_sns_list(
22        &self,
23        req: GetContactsSnsListRequest<'_>,
24    ) -> Result<GetContactsSnsListResponse, GeweError> {
25        let env = self
26            .post_api::<_, GetContactsSnsListResponse>("gewe/v2/api/sns/contactsSnsList", &req)
27            .await?;
28        env.data.ok_or(GeweError::MissingData)
29    }
30
31    #[instrument(skip(self))]
32    pub async fn get_sns_details(
33        &self,
34        req: GetSnsDetailsRequest<'_>,
35    ) -> Result<GetSnsDetailsResponse, GeweError> {
36        let env = self
37            .post_api::<_, GetSnsDetailsResponse>("gewe/v2/api/sns/snsDetails", &req)
38            .await?;
39        env.data.ok_or(GeweError::MissingData)
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_get_self_sns_list_request() {
49        let req = GetSelfSnsListRequest {
50            app_id: "test_app",
51            max_id: Some(123456),
52            decrypt: None,
53            first_page_md5: None,
54        };
55        let json = serde_json::to_string(&req).expect("Failed to serialize");
56        assert!(json.contains("appId"));
57        assert!(json.contains("maxId"));
58    }
59
60    #[test]
61    fn test_get_contacts_sns_list_request() {
62        let req = GetContactsSnsListRequest {
63            app_id: "test_app",
64            wxid: "contact_wxid",
65            max_id: None,
66            decrypt: None,
67            first_page_md5: None,
68        };
69        let json = serde_json::to_string(&req).expect("Failed to serialize");
70        assert!(json.contains("appId"));
71        assert!(json.contains("wxid"));
72    }
73
74    #[test]
75    fn test_get_sns_details_request() {
76        let req = GetSnsDetailsRequest {
77            app_id: "test_app",
78            sns_id: 123456,
79        };
80        let json = serde_json::to_string(&req).expect("Failed to serialize");
81        assert!(json.contains("appId"));
82        assert!(json.contains("snsId"));
83    }
84}