spotify_web_api/api/artists/
get_artist_top_tracks.rs1use crate::api::prelude::*;
2
3#[derive(Debug, Clone)]
5pub struct GetArtistTopTracks {
6 pub id: String,
8
9 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}