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

Implement Default when it is possible to #261

Merged
merged 4 commits into from
Oct 9, 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ More in the [`examples` directory](https://github.com/ramsayleung/rspotify/tree/
+ `get_an_episode`
+ `get_several_episodes`
+ `remove_users_saved_shows`
- ([#261](https://github.com/ramsayleung/rspotify/pull/261/files)) `PageSimpliedAlbums` has been renamed to `PageSimplifiedAlbums`
- ([#261](https://github.com/ramsayleung/rspotify/pull/261/files)) `Default` has been implemented for all the possible models
- ([#257](https://github.com/ramsayleung/rspotify/pull/257)) Fix naming for most playlist-related endpoints. They used to work only for tracks, but they've been extended to episodes as well, so we call the contents of a playlist "items" instead of "tracks".
+ `playlist_add_tracks` is now `playlist_add_items`
+ `playlist_tracks` is now `playlist_items`
Expand Down
8 changes: 4 additions & 4 deletions rspotify-model/src/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
/// Simplified Album Object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-simplifiedalbumobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct SimplifiedAlbum {
#[serde(skip_serializing_if = "Option::is_none")]
pub album_group: Option<String>,
Expand Down Expand Up @@ -56,19 +56,19 @@ pub struct FullAlbum {
pub tracks: Page<SimplifiedTrack>,
}

/// Full Albums wrapped by Vec object
/// Intermediate full Albums wrapped by Vec object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-multiple-albums)
#[derive(Deserialize)]
pub struct FullAlbums {
pub albums: Vec<FullAlbum>,
}

/// Simplified Albums wrapped by Page object
/// Intermediate simplified Albums wrapped by Page object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-new-releases)
#[derive(Deserialize)]
pub struct PageSimpliedAlbums {
pub struct PageSimplifiedAlbums {
pub albums: Page<SimplifiedAlbum>,
}

Expand Down
6 changes: 3 additions & 3 deletions rspotify-model/src/artist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{ArtistId, CursorBasedPage, Followers, Image};
/// Simplified Artist Object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-simplifiedartistobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct SimplifiedArtist {
pub external_urls: HashMap<String, String>,
pub href: Option<String>,
Expand All @@ -32,15 +32,15 @@ pub struct FullArtist {
pub popularity: u32,
}

/// Full artist object wrapped by `Vec`
/// Intermediate full artist object wrapped by `Vec`
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-multiple-artists)
#[derive(Deserialize)]
pub struct FullArtists {
pub artists: Vec<FullArtist>,
}

/// Full Artists vector wrapped by cursor-based-page object
/// Intermediate full Artists vector wrapped by cursor-based-page object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-followed)
#[derive(Deserialize)]
Expand Down
8 changes: 4 additions & 4 deletions rspotify-model/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct AudioFeatures {
pub valence: f32,
}

/// Audio feature object wrapped by `Vec`
/// Intermediate audio feature object wrapped by `Vec`
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-several-audio-features)
#[derive(Deserialize)]
Expand All @@ -58,7 +58,7 @@ pub struct AudioAnalysis {

/// Time interval object
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-audio-analysis)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct TimeInterval {
pub start: f32,
pub duration: f32,
Expand Down Expand Up @@ -87,7 +87,7 @@ pub struct AudioAnalysisSection {
/// Audio analysis meta object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-audio-analysis)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct AudioAnalysisMeta {
pub analyzer_version: String,
pub platform: String,
Expand All @@ -101,7 +101,7 @@ pub struct AudioAnalysisMeta {
/// Audio analysis segment object
///
///[Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-audio-analysis)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct AudioAnalysisSegment {
#[serde(flatten)]
pub time_interval: TimeInterval,
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
/// Spotify access token information
///
/// [Reference](https://developer.spotify.com/documentation/general/guides/authorization-guide/)
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Token {
/// An access token that can be provided in subsequent calls
pub access_token: String,
Expand Down
4 changes: 2 additions & 2 deletions rspotify-model/src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use crate::{Image, Page};
/// Category object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-categories)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Category {
pub href: String,
pub icons: Vec<Image>,
pub id: String,
pub name: String,
}

/// Categories wrapped by page object
/// Intermediate categories wrapped by page object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-categories)
#[derive(Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct CurrentPlaybackContext {
/// Actions object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-recently-played)
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, PartialEq, Eq, Default)]
pub struct Actions {
pub disallows: Vec<DisallowKey>,
}
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Device {
pub volume_percent: Option<u32>,
}

/// Device payload object
/// Intermediate device payload object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-a-users-available-devices)
#[derive(Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
/// Image object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-imageobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Image {
pub height: Option<u32>,
pub url: String,
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use serde::{Deserialize, Serialize};
/// Followers object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-followersobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Followers {
// This field will always set to null, as the Web API does not support it at the moment.
// pub href: Option<String>,
Expand Down
6 changes: 3 additions & 3 deletions rspotify-model/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
/// Paging object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-pagingobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Page<T> {
pub href: String,
pub items: Vec<T>,
Expand All @@ -19,7 +19,7 @@ pub struct Page<T> {
/// Cursor-based paging object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-cursorpagingobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct CursorBasedPage<T> {
pub href: String,
pub items: Vec<T>,
Expand All @@ -34,7 +34,7 @@ pub struct CursorBasedPage<T> {
/// Cursor object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-cursorobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Cursor {
pub after: Option<String>,
}
8 changes: 4 additions & 4 deletions rspotify-model/src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use crate::{Followers, Image, Page, PlayableItem, PlaylistId, PublicUser};
/// Playlist result object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-add-tracks-to-playlist)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct PlaylistResult {
pub snapshot_id: String,
}

/// Playlist Track Reference Object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-playlisttracksrefobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct PlaylistTracksRef {
pub href: String,
pub total: u32,
Expand Down Expand Up @@ -63,7 +63,7 @@ pub struct FullPlaylist {
/// Playlist track object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-playlisttrackobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct PlaylistItem {
pub added_at: Option<DateTime<Utc>>,
pub added_by: Option<PublicUser>,
Expand All @@ -78,7 +78,7 @@ pub struct FeaturedPlaylists {
pub playlists: Page<SimplifiedPlaylist>,
}

/// Category playlists object wrapped by `Page`
/// Intermediate category playlists object wrapped by `Page`
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-a-categories-playlists)
#[derive(Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/recommend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{RecommendationsSeedType, SimplifiedTrack};
/// Recommendations object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-recommendationsobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Recommendations {
pub seeds: Vec<RecommendationsSeed>,
pub tracks: Vec<SimplifiedTrack>,
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct SearchPlaylists {
/// Search for albums
///
///[Reference](https://developer.spotify.com/documentation/web-api/reference/#category-search)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct SearchAlbums {
pub albums: Page<SimplifiedAlbum>,
}
Expand Down
6 changes: 3 additions & 3 deletions rspotify-model/src/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ pub struct FullEpisode {
pub show: SimplifiedShow,
}

/// Episodes feature object wrapped by `Vec`
/// Intermediate episodes feature object wrapped by `Vec`
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-multiple-episodes)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Deserialize)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to remove Clone, Debug, Serialize, PartialEq, Eq, because we have changed the declaration of this struct.

Copy link
Collaborator Author

@marioortizmanero marioortizmanero Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is just an intermediate model, so I've added the same derives as the rest of the intermediate models. We don't really expose it to the user, so Deserialize is enough.

pub struct EpisodesPayload {
pub episodes: Vec<FullEpisode>,
}

/// Resume point object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-resumepointobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct ResumePoint {
pub fully_played: bool,
#[serde(with = "duration_ms", rename = "resume_position_ms")]
Expand Down
4 changes: 2 additions & 2 deletions rspotify-model/src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct TrackLink {
pub id: TrackId,
}

/// Full track wrapped by `Vec`
/// Intermediate full track wrapped by `Vec`
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-several-tracks)
#[derive(Deserialize)]
Expand All @@ -63,7 +63,7 @@ pub struct FullTracks {
/// relinking is applied.
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-simplifiedtrackobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct SimplifiedTrack {
pub artists: Vec<SimplifiedArtist>,
pub available_markets: Option<Vec<String>>,
Expand Down
2 changes: 1 addition & 1 deletion rspotify-model/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct PrivateUser {
/// Explicit content setting object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-explicitcontentsettingsobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct ExplicitContent {
pub filter_enabled: bool,
pub filter_locked: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/clients/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ where
};

let result = self.endpoint_get("browse/new-releases", &params).await?;
convert_result::<PageSimpliedAlbums>(&result).map(|x| x.albums)
convert_result::<PageSimplifiedAlbums>(&result).map(|x| x.albums)
}

/// Get Recommendations Based on Seeds
Expand Down