gitee_rs/notifications/
mod.rs1use crate::{error::GiteeError, GiteeClient};
2use reqwest::Method;
3use serde_json::Value;
4
5mod models;
6pub use models::*;
7
8impl GiteeClient {
9 pub async fn list_user_notifications(&self) -> Result<Vec<Notification>, GiteeError> {
11 let url = format!("{}/notifications/threads", self.base_url());
12 let response = self
13 .client()
14 .request(Method::GET, &url)
15 .header("Authorization", self.auth_header())
16 .send()
17 .await?;
18
19 if !response.status().is_success() {
20 return Err(GiteeError::ApiError(format!(
21 "Failed to list notifications: {}",
22 response.status()
23 )));
24 }
25
26 let body = response.text().await?;
27 let v: Value = serde_json::from_str(&body)?;
28
29 if let Some(items) = v.get("list") {
31 let list: Vec<Notification> = serde_json::from_value(items.clone())?;
32 Ok(list)
33 } else if let Some(items) = v.get("items") {
34 let list: Vec<Notification> = serde_json::from_value(items.clone())?;
35 Ok(list)
36 } else if v.is_array() {
37 let list: Vec<Notification> = serde_json::from_value(v)?;
38 Ok(list)
39 } else {
40 Ok(vec![])
41 }
42 }
43}