Skip to content

Commit

Permalink
fix #231
Browse files Browse the repository at this point in the history
  • Loading branch information
marioortizmanero committed Jul 14, 2021
1 parent 27e7e41 commit 6c2eb9b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
36 changes: 33 additions & 3 deletions src/clients/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,9 @@ pub trait OAuthClient: BaseClient {
///
/// Parameters:
/// - market: Optional. an ISO 3166-1 alpha-2 country code or the string from_token.
/// - additional_types: Optional. A comma-separated list of item types that
/// your client supports besides the default track type. Valid types are:
/// `track` and `episode`.
/// - additional_types: Optional. A list of item types that your client
/// supports besides the default track type. Valid types are: `track` and
/// `episode`.
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-information-about-the-users-current-playback)
async fn current_playback<'a>(
Expand Down Expand Up @@ -956,6 +956,15 @@ pub trait OAuthClient: BaseClient {
Ok(())
}

/// Start a user's playback
///
/// Parameters:
/// - uris
/// - device_id
/// - offset
/// - position_ms
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-start-a-users-playback)
async fn start_uris_playback<'a, T: PlayableIdType + 'a>(
&self,
uris: impl IntoIterator<Item = &'a Id<T>> + 'a,
Expand Down Expand Up @@ -991,6 +1000,27 @@ pub trait OAuthClient: BaseClient {
Ok(())
}

/// Resume a User’s Playback.
///
/// Parameters:
/// - device_id - device target for playback
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-start-a-users-playback)
async fn resume_playback(
&self,
device_id: Option<&str>,
position_ms: Option<u32>,
) -> ClientResult<()> {
let params = build_json! {
optional "position_ms": position_ms,
};

let url = append_device_id("me/player/play", device_id);
self.endpoint_put(&url, &params).await?;

Ok(())
}

/// Skip User’s Playback To Next Track.
///
/// Parameters:
Expand Down
24 changes: 18 additions & 6 deletions tests/test_with_oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,26 @@ async fn test_playback() {
.await
.unwrap();

for _ in &uris {
for i in 0..uris.len() - 1 {
client.next_track(Some(&device_id)).await.unwrap();

client.pause_playback(Some(&device_id)).await.unwrap();
}

for _ in &uris {
client.previous_track(Some(&device_id)).await.unwrap();
// Also trying to go to the previous track
if i != 0 {
client.previous_track(Some(&device_id)).await.unwrap();
client.next_track(Some(&device_id)).await.unwrap();
}

// Making sure pause/resume also works
let playback = client.current_playback(None, None::<&[_]>).await.unwrap();
if let Some(playback) = playback {
if playback.is_playing {
client.pause_playback(Some(&device_id)).await.unwrap();
client.resume_playback(None, None).await.unwrap();
} else {
client.resume_playback(None, None).await.unwrap();
client.pause_playback(Some(&device_id)).await.unwrap();
}
}
}

client
Expand Down

0 comments on commit 6c2eb9b

Please sign in to comment.