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

OAuth tests cleanup, they don't modify the user's profile anymore #226

Merged
merged 22 commits into from
Aug 7, 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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
test:
name: Test and Lint for each Client
runs-on: ubuntu-latest
env:
RUST_BACKTRACE: 1
strategy:
matrix:
features:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ More in the [`examples` directory](https://github.com/ramsayleung/rspotify/tree/
- Rspotify now uses macros internally to make the endpoints as concise as possible and nice to read.
- Add `add_item_to_queue` endpoint.
- Add `category_playlists` endpoint ([#153](https://github.com/ramsayleung/rspotify/pull/153)).
- Add `resume_playback` endpoint.
- Fix race condition when using a single client from multiple threads ([#114](https://github.com/ramsayleung/rspotify/pull/114)).
- Rspotify should now be considerably lighter and less bloated ([discussion in #108](https://github.com/ramsayleung/rspotify/issues/108)):
+ Remove unused dependencies: `base64`, `env_logger`, `random`, `url`.
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/enums/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub enum DeviceType {
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-recommendationseedobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, AsRefStr)]
#[serde(rename_all = "snake_case")]
#[serde(rename_all = "UPPERCASE")]
pub enum RecommendationsSeedType {
Artist,
Track,
Expand Down
6 changes: 3 additions & 3 deletions rspotify-model/src/idtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait PlayContextIdType: IdType {}
macro_rules! sealed_types {
($($name:ident),+) => {
$(
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
marioortizmanero marked this conversation as resolved.
Show resolved Hide resolved
pub enum $name {}
impl private::Sealed for $name {}
impl IdType for $name {
Expand Down Expand Up @@ -65,7 +65,7 @@ pub type EpisodeIdBuf = IdBuf<Episode>;
///
/// This is a not-owning type, it stores a `&str` only. See
/// [IdBuf](crate::idtypes::IdBuf) for owned version of the type.
#[derive(Debug, PartialEq, Eq, Serialize)]
#[derive(Debug, PartialEq, Eq, Serialize, Hash)]
pub struct Id<T> {
#[serde(default)]
_type: PhantomData<T>,
Expand All @@ -80,7 +80,7 @@ pub struct Id<T> {
///
/// Use `Id::from_id(val).to_owned()`, `Id::from_uri(val).to_owned()` or
/// `Id::from_id_or_uri(val).to_owned()` to construct an instance of this type.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)]
pub struct IdBuf<T> {
#[serde(default)]
_type: PhantomData<T>,
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct SimplifiedPlaylist {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct FullPlaylist {
pub collaborative: bool,
pub description: String,
pub description: Option<String>,
pub external_urls: HashMap<String, String>,
pub followers: Followers,
pub href: String,
Expand Down
8 changes: 4 additions & 4 deletions src/clients/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,11 +913,11 @@ where
let seed_tracks = seed_tracks.map(join_ids);
let limit = limit.map(|x| x.to_string());
let mut params = build_map! {
optional "seed_artists": seed_artists.as_ref(),
optional "seed_genres": seed_genres.as_ref(),
optional "seed_tracks": seed_tracks.as_ref(),
optional "seed_artists": seed_artists.as_deref(),
optional "seed_genres": seed_genres.as_deref(),
optional "seed_tracks": seed_tracks.as_deref(),
optional "market": market.map(|x| x.as_ref()),
optional "limit": limit.as_ref(),
optional "limit": limit.as_deref(),
};

let attributes = [
Expand Down
56 changes: 43 additions & 13 deletions src/clients/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub trait OAuthClient: BaseClient {
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-change-playlist-details)
async fn playlist_change_detail(
&self,
playlist_id: &str,
playlist_id: &PlaylistId,
name: Option<&str>,
public: Option<bool>,
description: Option<&str>,
Expand All @@ -202,7 +202,7 @@ pub trait OAuthClient: BaseClient {
optional "description": description,
};

let url = format!("playlists/{}", playlist_id);
let url = format!("playlists/{}", playlist_id.id());
self.endpoint_put(&url, &params).await
}

Expand All @@ -212,9 +212,11 @@ pub trait OAuthClient: BaseClient {
/// - playlist_id - the id of the playlist
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-unfollow-playlist)
async fn playlist_unfollow(&self, playlist_id: &str) -> ClientResult<String> {
let url = format!("playlists/{}/followers", playlist_id);
self.endpoint_delete(&url, &json!({})).await
async fn playlist_unfollow(&self, playlist_id: &PlaylistId) -> ClientResult<()> {
let url = format!("playlists/{}/followers", playlist_id.id());
self.endpoint_delete(&url, &json!({})).await?;

Ok(())
}

/// Adds tracks to a playlist.
Expand Down Expand Up @@ -278,18 +280,15 @@ pub trait OAuthClient: BaseClient {
/// - snapshot_id - optional playlist's snapshot ID
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-reorder-or-replace-playlists-tracks)
async fn playlist_reorder_tracks<'a, T: PlayableIdType + 'a>(
async fn playlist_reorder_tracks(
&self,
playlist_id: &PlaylistId,
uris: Option<impl IntoIterator<Item = &'a Id<T>> + 'a>,
range_start: Option<i32>,
insert_before: Option<i32>,
range_length: Option<u32>,
snapshot_id: Option<&str>,
) -> ClientResult<PlaylistResult> {
let uris = uris.map(|u| u.into_iter().map(|id| id.uri()).collect::<Vec<_>>());
let params = build_json! {
optional "uris": uris,
optional "range_start": range_start,
optional "insert_before": insert_before,
optional "range_length": range_length,
Expand Down Expand Up @@ -433,7 +432,7 @@ pub trait OAuthClient: BaseClient {
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-recently-played)
async fn current_user_playing_track(&self) -> ClientResult<Option<CurrentlyPlayingContext>> {
let result = self
.get("me/player/currently-playing", None, &Query::new())
.endpoint_get("me/player/currently-playing", &Query::new())
.await?;
if result.is_empty() {
Ok(None)
Expand Down Expand Up @@ -835,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 @@ -957,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 @@ -992,6 +1000,28 @@ pub trait OAuthClient: BaseClient {
Ok(())
}

/// Resume a User’s Playback.
///
/// Parameters:
/// - device_id - device target for playback
marioortizmanero marked this conversation as resolved.
Show resolved Hide resolved
/// - position_ms
///
/// [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
2 changes: 1 addition & 1 deletion tests/test_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn test_recommendations_seed() {
"afterRelinkingSize": 365,
"href": "https://api.spotify.com/v1/artists/4NHQUGzhtTLFvgF5SZesLK",
"id": "4NHQUGzhtTLFvgF5SZesLK",
"type": "artist"
"type": "ARTIST"
}
"#;
let seed: RecommendationsSeed = serde_json::from_str(&json_str).unwrap();
Expand Down
Loading