spotify_web_api/api/artists/
get_artist_top_tracks.rs

1use crate::api::prelude::*;
2
3/// Get Spotify catalog information about an artist's top tracks by country.
4#[derive(Debug, Clone)]
5pub struct GetArtistTopTracks {
6    /// The [Spotify ID](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the artist.
7    pub id: String,
8
9    /// An [ISO 3166-1 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
10    /// If a country code is specified, only content that is available in that market will be returned.
11    /// 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.
12    ///
13    /// # Notes
14    /// If neither market or user country are provided, the content is considered unavailable for the client.
15    /// Users can view the country that is associated with their account in the [account settings](https://www.spotify.com/account/overview/).
16    pub market: Option<Market>,
17}
18
19impl<T: Into<String>> From<T> for GetArtistTopTracks {
20    fn from(id: T) -> Self {
21        Self {
22            id: id.into(),
23            market: None,
24        }
25    }
26}
27
28impl Endpoint for GetArtistTopTracks {
29    fn method(&self) -> Method {
30        Method::GET
31    }
32
33    fn endpoint(&self) -> Cow<'static, str> {
34        format!("artists/{}/top-tracks", self.id).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_artist_top_tracks_endpoint() {
54        let endpoint = ExpectedUrl::builder()
55            .endpoint("artists/0TnOYISbd1XYRBk9myaseg/top-tracks")
56            .build();
57
58        let client = SingleTestClient::new_raw(endpoint, "");
59
60        let endpoint = GetArtistTopTracks::from("0TnOYISbd1XYRBk9myaseg");
61
62        api::ignore(endpoint).query(&client).unwrap();
63    }
64}