soundcloud_rs/client/
users.rs1use crate::models::client::Client;
2use crate::models::client::Identifier;
3use crate::models::error::Error;
4use crate::models::query::{Paging, UsersQuery};
5use crate::models::response::{Playlists, Reposts, Tracks, User, Users};
6
7impl Client {
8 pub async fn search_users(&self, query: Option<&UsersQuery>) -> Result<Users, Error> {
9 let resp: Users = self.get("search/users", query).await?;
10 Ok(resp)
11 }
12
13 pub async fn get_user(
14 &self,
15 identifier: &Identifier,
16 ) -> Result<User, Error> {
17 let url = format!("users/{identifier}");
18 let resp: User = self.get(&url, None::<&()>).await?;
19 Ok(resp)
20 }
21
22 pub async fn get_user_followers(
23 &self,
24 identifier: &Identifier,
25 pagination: Option<&Paging>,
26 ) -> Result<Users, Error> {
27 let url = format!("users/{identifier}/followers");
28 let resp: Users = self.get(&url, pagination).await?;
29 Ok(resp)
30 }
31
32 pub async fn get_user_followings(
33 &self,
34 identifier: &Identifier,
35 pagination: Option<&Paging>,
36 ) -> Result<Users, Error> {
37 let url = format!("users/{identifier}/followings");
38 let resp: Users = self.get(&url, pagination).await?;
39 Ok(resp)
40 }
41
42 pub async fn get_user_playlists(
43 &self,
44 identifier: &Identifier,
45 pagination: Option<&Paging>,
46 ) -> Result<Playlists, Error> {
47 let url = format!("users/{identifier}/playlists");
48 let resp: Playlists = self.get(&url, pagination).await?;
49 Ok(resp)
50 }
51
52 pub async fn get_user_tracks(
53 &self,
54 identifier: &Identifier,
55 pagination: Option<&Paging>,
56 ) -> Result<Tracks, Error> {
57 let url = format!("users/{identifier}/tracks");
58 let resp: Tracks = self.get(&url, pagination).await?;
59 Ok(resp)
60 }
61
62 pub async fn get_user_reposts(
63 &self,
64 identifier: &Identifier,
65 pagination: Option<&Paging>,
66 ) -> Result<Reposts, Error> {
67 let id = match identifier {
68 Identifier::Id(id) => id.to_string(),
69 Identifier::Urn(urn) => urn
70 .split(':')
71 .last()
72 .expect("Could not extract ID from URN")
73 .to_owned(),
74 };
75 let url = format!("stream/users/{}/reposts", id);
76 let resp: Reposts = self.get(&url, pagination).await?;
77 Ok(resp)
78 }
79}