Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix is_playable always being None #260

Merged
merged 3 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ More in the [`examples` directory](https://github.com/ramsayleung/rspotify/tree/
+ `get_an_episode`
+ `get_several_episodes`
+ `remove_users_saved_shows`
- ([#260](https://github.com/ramsayleung/rspotify/pull/260)) The `current_user_saved_albums` and `current_user_saved_tracks` now have a `market` parameter

## 0.10 (2020/07/01)

Expand Down
4 changes: 2 additions & 2 deletions examples/pagination_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ async fn main() {
spotify.prompt_for_token(&url).await.unwrap();

// Executing the futures sequentially
let stream = spotify.current_user_saved_tracks();
let stream = spotify.current_user_saved_tracks(None);
pin_mut!(stream);
println!("Items (blocking):");
while let Some(item) = stream.try_next().await.unwrap() {
println!("* {}", item.track.name);
}

// Executing the futures concurrently
let stream = spotify.current_user_saved_tracks();
let stream = spotify.current_user_saved_tracks(None);
println!("\nItems (concurrent):");
stream
.try_for_each_concurrent(10, |item| async move {
Expand Down
2 changes: 1 addition & 1 deletion examples/pagination_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() {
println!("Items:");
loop {
let page = spotify
.current_user_saved_tracks_manual(Some(limit), Some(offset))
.current_user_saved_tracks_manual(None, Some(limit), Some(offset))
.await
.unwrap();
for item in page.items {
Expand Down
2 changes: 1 addition & 1 deletion examples/pagination_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
spotify.prompt_for_token(&url).unwrap();

// Typical iteration, no extra boilerplate needed.
let stream = spotify.current_user_saved_tracks();
let stream = spotify.current_user_saved_tracks(None);
println!("Items:");
for item in stream {
println!("* {}", item.unwrap().track.name);
Expand Down
22 changes: 18 additions & 4 deletions src/clients/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,22 +482,29 @@ pub trait OAuthClient: BaseClient {
/// of this.
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-users-saved-albums)
fn current_user_saved_albums(&self) -> Paginator<'_, ClientResult<SavedAlbum>> {
fn current_user_saved_albums<'a>(
&'a self,
market: Option<&'a Market>,
) -> Paginator<'a, ClientResult<SavedAlbum>> {
paginate(
move |limit, offset| self.current_user_saved_albums_manual(Some(limit), Some(offset)),
move |limit, offset| {
self.current_user_saved_albums_manual(market, Some(limit), Some(offset))
},
self.get_config().pagination_chunks,
)
}

/// The manually paginated version of [`Self::current_user_saved_albums`].
async fn current_user_saved_albums_manual(
&self,
market: Option<&Market>,
limit: Option<u32>,
offset: Option<u32>,
) -> ClientResult<Page<SavedAlbum>> {
let limit = limit.map(|s| s.to_string());
let offset = offset.map(|s| s.to_string());
let params = build_map! {
optional "market": market.map(|x| x.as_ref()),
optional "limit": limit.as_deref(),
optional "offset": offset.as_deref(),
};
Expand All @@ -518,22 +525,29 @@ pub trait OAuthClient: BaseClient {
/// version of this.
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-users-saved-tracks)
fn current_user_saved_tracks(&self) -> Paginator<'_, ClientResult<SavedTrack>> {
fn current_user_saved_tracks<'a>(
&'a self,
market: Option<&'a Market>,
) -> Paginator<'a, ClientResult<SavedTrack>> {
paginate(
move |limit, offset| self.current_user_saved_tracks_manual(Some(limit), Some(offset)),
move |limit, offset| {
self.current_user_saved_tracks_manual(market, Some(limit), Some(offset))
},
self.get_config().pagination_chunks,
)
}

/// The manually paginated version of [`Self::current_user_saved_tracks`].
async fn current_user_saved_tracks_manual(
&self,
market: Option<&Market>,
limit: Option<u32>,
offset: Option<u32>,
) -> ClientResult<Page<SavedTrack>> {
let limit = limit.map(|s| s.to_string());
let offset = offset.map(|s| s.to_string());
let params = build_map! {
optional "market": market.map(|x| x.as_ref()),
optional "limit": limit.as_deref(),
optional "offset": offset.as_deref(),
};
Expand Down
24 changes: 12 additions & 12 deletions tests/test_with_oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async fn test_current_user_saved_albums() {
.unwrap();

// Making sure the new albums appear
let all_albums = fetch_all(client.current_user_saved_albums()).await;
let all_albums = fetch_all(client.current_user_saved_albums(None)).await;
let all_uris = all_albums
.into_iter()
.map(|a| a.album.id)
Expand All @@ -221,32 +221,32 @@ async fn test_current_user_saved_albums() {
#[maybe_async::test(feature = "__sync", async(feature = "__async", tokio::test))]
#[ignore]
async fn test_current_user_saved_tracks_add() {
let client = oauth_client().await;
let tracks_ids = [
&TrackId::from_uri("spotify:track:4iV5W9uYEdYUVa79Axb7Rh").unwrap(),
&TrackId::from_uri("spotify:track:1301WleyT98MSxVHPZCA6M").unwrap(),
];
oauth_client()
.await
client
.current_user_saved_tracks_add(tracks_ids)
.await
.unwrap();

let contains = oauth_client()
.await
let contains = client
.current_user_saved_tracks_contains(tracks_ids)
.await
.unwrap();
// Every track should be saved
assert!(contains.into_iter().all(|x| x));

oauth_client()
.await
.current_user_saved_tracks_manual(Some(10), Some(0))
.await
.unwrap();
let all = fetch_all(client.current_user_saved_tracks(None)).await;
let all = all
.into_iter()
.filter_map(|saved| Some(saved.track.id))
.collect::<Vec<_>>();
// All the initial tracks should appear
assert!(tracks_ids.iter().all(|track| all.contains(track)));

oauth_client()
.await
client
.current_user_saved_tracks_delete(tracks_ids)
.await
.unwrap();
Expand Down