spotify_web_api/api/users/
get_followed_artists.rs

1use crate::{api::prelude::*, model::FollowedArtistsType};
2
3/// Get the current user's followed artists.
4#[derive(Debug, Clone)]
5pub struct GetFollowedArtists {
6    /// The ID type: currently only artist is supported.
7    pub type_: FollowedArtistsType,
8
9    /// The last artist ID retrieved from the previous request.
10    pub after: Option<String>,
11}
12
13impl GetFollowedArtists {
14    pub fn with_after(after: Option<impl Into<String>>) -> Self {
15        Self {
16            type_: FollowedArtistsType::Artist,
17            after: after.map(Into::into),
18        }
19    }
20}
21
22impl Default for GetFollowedArtists {
23    fn default() -> Self {
24        Self {
25            type_: FollowedArtistsType::Artist,
26            after: None,
27        }
28    }
29}
30
31impl From<FollowedArtistsType> for GetFollowedArtists {
32    fn from(type_: FollowedArtistsType) -> Self {
33        Self { type_, after: None }
34    }
35}
36
37impl Endpoint for GetFollowedArtists {
38    fn method(&self) -> Method {
39        Method::GET
40    }
41
42    fn endpoint(&self) -> Cow<'static, str> {
43        "me/following".into()
44    }
45
46    fn parameters(&self) -> QueryParams<'_> {
47        let mut params = QueryParams::default();
48        params.push("type", &self.type_);
49        params.push_opt("after", self.after.as_ref());
50        params
51    }
52}
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57    use crate::{
58        api::{self, Query as _},
59        test::client::{ExpectedUrl, SingleTestClient},
60    };
61
62    #[test]
63    fn test_get_followed_artists_endpoint() {
64        let endpoint = ExpectedUrl::builder()
65            .endpoint("me/following")
66            .add_query_params(&[("type", "artist")])
67            .build();
68
69        let client = SingleTestClient::new_raw(endpoint, "");
70
71        api::ignore(GetFollowedArtists::default())
72            .query(&client)
73            .unwrap();
74    }
75
76    #[test]
77    fn test_get_followed_artists_endpoint_with_after() {
78        let endpoint = ExpectedUrl::builder()
79            .endpoint("me/following")
80            .add_query_params(&[("type", "artist")])
81            .add_query_params(&[("after", "2CIMQHirSU0MQqyYHq0eOx")])
82            .build();
83
84        let client = SingleTestClient::new_raw(endpoint, "");
85
86        api::ignore(GetFollowedArtists::with_after(Some(
87            "2CIMQHirSU0MQqyYHq0eOx",
88        )))
89        .query(&client)
90        .unwrap();
91    }
92}