Skip to content

Commit

Permalink
Merge pull request #15 from jereksel/feature/get_playlist
Browse files Browse the repository at this point in the history
Implement /v1/playlists/{playlist_id} endpoint
  • Loading branch information
ramsayleung committed Sep 11, 2018
2 parents a232e03 + 3ddb1a0 commit 3c0bb22
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/spotify/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,23 @@ impl Spotify {
self.convert_result::<PublicUser>(&result.unwrap_or_default())
}

//TODO: fields
///[get playlist](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/)
///Get full details about Spotify playlist
///Parameters:
///- playlist_id - the id of the playlist
///- market - an ISO 3166-1 alpha-2 country code.
pub fn playlist(&self, playlist_id: &str, market: Option<Country>) -> Result<FullPlaylist, failure::Error> {
let mut params = HashMap::new();
if let Some(_market) = market {
params.insert("market".to_owned(), _market.as_str().to_owned());
}

let url = format!("playlists/{}", playlist_id);
let result = self.get(&url, &mut params);
self.convert_result::<FullPlaylist>(&result.unwrap_or_default())
}

///[get users playlists](https://developer.spotify.com/web-api/get-a-list-of-current-users-playlists/)
///Get current user playlists without required getting his profile
///Parameters:
Expand Down
23 changes: 23 additions & 0 deletions tests/tests_with_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,26 @@ fn test_tracks() {
let tracks = spotify.tracks(track_uris, None);
assert!(tracks.is_ok());
}
#[test]
fn test_existing_playlist() {
let client_credential = SpotifyClientCredentials::default().build();

let spotify = Spotify::default()
.client_credentials_manager(client_credential)
.build();

let playlist = spotify.playlist("37i9dQZF1DZ06evO45P0Eo", None);
assert!(playlist.is_ok());
}

#[test]
fn test_fake_playlist() {
let client_credential = SpotifyClientCredentials::default().build();

let spotify = Spotify::default()
.client_credentials_manager(client_credential)
.build();

let playlist = spotify.playlist("fake_id", None);
assert!(!playlist.is_ok());
}

0 comments on commit 3c0bb22

Please sign in to comment.