spotify_web_api/api/tracks/
get_user_saved_tracks.rs

1use crate::api::prelude::*;
2
3/// Get a list of the tracks saved in the current Spotify user's library.
4///
5/// This API endpoint is in beta and could change without warning. Please share any feedback that you have, or issues that you discover, in the [Spotify developer community forum](https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer).
6#[derive(Default, Debug, Clone)]
7pub struct GetUserSavedTracks {
8    /// An [ISO 3166-1 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
9    /// If a country code is specified, only content that is available in that market will be returned.
10    /// If a valid user access token is specified in the request header, the country associated with the user account will take priority over this parameter.
11    ///
12    /// # Notes
13    /// If neither market or user country are provided, the content is considered unavailable for the client.
14    /// Users can view the country that is associated with their account in the [account settings](https://www.spotify.com/account/overview/).
15    pub market: Option<Market>,
16}
17
18impl Pageable for GetUserSavedTracks {}
19
20impl From<Market> for GetUserSavedTracks {
21    fn from(market: Market) -> Self {
22        Self {
23            market: Some(market),
24        }
25    }
26}
27
28impl Endpoint for GetUserSavedTracks {
29    fn method(&self) -> Method {
30        Method::GET
31    }
32
33    fn endpoint(&self) -> Cow<'static, str> {
34        "me/tracks".into()
35    }
36
37    fn parameters(&self) -> QueryParams<'_> {
38        let mut params = QueryParams::default();
39        params.push_opt("market", self.market.as_ref());
40        params
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47    use crate::{
48        api::{self, Query as _},
49        test::client::{ExpectedUrl, SingleTestClient},
50    };
51
52    #[test]
53    fn test_get_user_saved_track_endpoint() {
54        let endpoint = ExpectedUrl::builder().endpoint("me/tracks").build();
55        let client = SingleTestClient::new_raw(endpoint, "");
56        let endpoint = GetUserSavedTracks::default();
57        api::ignore(endpoint).query(&client).unwrap();
58    }
59}