spotify_web_api/api/player/
get_playback_state.rs

1use crate::api::prelude::*;
2
3/// Get information about the user’s current playback state, including track or episode, progress, and active device.
4#[derive(Debug, Default, Clone)]
5pub struct GetPlaybackState {
6    /// An [ISO 3166-1 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
7    /// If a country code is specified, only content that is available in that market will be returned.
8    /// 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.
9    ///
10    /// # Notes
11    /// If neither market or user country are provided, the content is considered unavailable for the client.
12    /// Users can view the country that is associated with their account in the [account settings](https://www.spotify.com/account/overview/).
13    pub market: Option<Market>,
14}
15
16impl Endpoint for GetPlaybackState {
17    fn method(&self) -> Method {
18        Method::GET
19    }
20
21    fn endpoint(&self) -> Cow<'static, str> {
22        "me/player".into()
23    }
24
25    fn parameters(&self) -> QueryParams<'_> {
26        let mut params = QueryParams::default();
27        params.push_opt("market", self.market.as_ref());
28        params
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35    use crate::{
36        api::{self, Query as _},
37        test::client::{ExpectedUrl, SingleTestClient},
38    };
39
40    #[test]
41    fn test_get_playback_state_endpoint() {
42        let endpoint = ExpectedUrl::builder().endpoint("me/player").build();
43
44        let client = SingleTestClient::new_raw(endpoint, "");
45
46        let endpoint = GetPlaybackState::default();
47
48        api::ignore(endpoint).query(&client).unwrap();
49    }
50}