spotify_web_api/api/albums/
remove_user_saved_albums.rs

1use crate::api::prelude::*;
2
3/// Remove one or more albums from the current user's 'Your Music' library.
4#[derive(Debug, Clone)]
5pub struct RemoveUserSavedAlbums {
6    /// A list of [Spotify IDs](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the albums.
7    pub ids: Vec<String>,
8}
9
10impl<T, I> From<I> for RemoveUserSavedAlbums
11where
12    I: IntoIterator<Item = T>,
13    T: Into<String>,
14{
15    fn from(ids: I) -> Self {
16        Self {
17            ids: ids.into_iter().map(Into::into).collect(),
18        }
19    }
20}
21
22impl Endpoint for RemoveUserSavedAlbums {
23    fn method(&self) -> Method {
24        Method::DELETE
25    }
26
27    fn endpoint(&self) -> Cow<'static, str> {
28        "me/albums".into()
29    }
30
31    fn parameters(&self) -> QueryParams<'_> {
32        let mut params = QueryParams::default();
33        params.push("ids", &self.ids.join(","));
34        params
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41    use crate::{
42        api::{self, Query as _},
43        test::client::{ExpectedUrl, SingleTestClient},
44    };
45    use http::Method;
46
47    #[test]
48    fn test_remove_user_saved_albums_endpoint() {
49        let endpoint = ExpectedUrl::builder()
50            .method(Method::DELETE)
51            .endpoint("me/albums")
52            .add_query_params(&[("ids", "7F50uh7oGitmAEScRKV6pD,27XW2QTeqZGOKlm2Dt0PvN")])
53            .build();
54
55        let client = SingleTestClient::new_raw(endpoint, "");
56
57        let endpoint =
58            RemoveUserSavedAlbums::from(["7F50uh7oGitmAEScRKV6pD", "27XW2QTeqZGOKlm2Dt0PvN"]);
59
60        api::ignore(endpoint).query(&client).unwrap();
61    }
62}