x_pixiv_lib/
user.rs

1use crate::data::{Api, Illusts};
2
3use std::collections::HashMap;
4
5pub struct User {
6    id: usize,
7}
8
9impl User {
10    pub fn new(id: usize) -> Self {
11        Self { id }
12    }
13
14    pub async fn get_artworks(&self) -> reqwest::Result<Vec<usize>> {
15        let data = reqwest::get(format!(
16            "https://www.pixiv.net/ajax/user/{}/profile/all",
17            self.id
18        ))
19        .await?
20        .error_for_status()?
21        .json::<Api<Illusts<HashMap<usize, Option<bool>>>>>()
22        .await?;
23        let images = data
24            .body
25            .illusts
26            .keys()
27            .map(|k| k.clone())
28            .collect::<Vec<usize>>();
29
30        Ok(images)
31    }
32}
33
34#[cfg(test)]
35mod test {
36    use super::User;
37
38    #[tokio::test]
39    async fn test() {
40        let images = User::new(3115085).get_artworks().await.unwrap();
41        println!("{:?}", images);
42    }
43}