[PR #157] [MERGED] Keep polishing the models #275

Closed
opened 2026-02-27 20:24:04 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/157
Author: @ramsayleung
Created: 11/21/2020
Status: Merged
Merged: 12/15/2020
Merged by: @ramsayleung

Base: masterHead: ramsay_refactor_model


📝 Commits (10+)

  • 3f4e294 Remove FullArtists struct, define it inside the endpoint function.
  • 9321596 Merge branch 'master' into ramsay_refactor_model
  • b83a7b8 Update CHANGELOG about removing FullArtists.
  • edf7d2c Replace FullTracks with Vec.
  • 748d996 Update document.
  • 645bbab Replace AudioFeaturesPayload with Vec<AudioFeatures>.
  • 2463b6b Update CHANGELOG.
  • 7373529 Recover wrapper objects and make them public in crate
  • de43450 Update CHANGELOG and remove unnecessary derived traits.
  • bc7c931 Reduce FullAlbums wrapper object

📊 Changes

16 files changed (+744 additions, -113 deletions)

View changed files

📝 CHANGELOG.md (+22 -2)
📝 examples/with_refresh_token.rs (+1 -1)
📝 src/client.rs (+31 -22)
📝 src/model/album.rs (+4 -6)
📝 src/model/artist.rs (+4 -6)
📝 src/model/audio.rs (+10 -4)
📝 src/model/category.rs (+2 -3)
📝 src/model/context.rs (+32 -21)
📝 src/model/device.rs (+21 -3)
📝 src/model/mod.rs (+121 -1)
📝 src/model/offset.rs (+10 -3)
📝 src/model/show.rs (+22 -7)
📝 src/model/track.rs (+16 -7)
📝 src/util.rs (+1 -1)
📝 tests/test_models.rs (+433 -26)
📝 tests/test_with_oauth.rs (+14 -0)

📄 Description

Description

Keep polish the models by following the issues:

Motivation and Context

To make rspotify's API easier to use.

  • Types like FullAlbums, PageSimplifiedAlbums, etc exist as wrappers. This makes the API more complex. Instead, have that type exist solely in the API function that needs it, and then return a Vec. This drastically reduces the number of public API types. The wrapper objects need to be reduced:
    • FullTracks
    • CursorPageFullArtists
    • SeversalSimplifiedShows
    • DevicePayload
    • AudioFeaturesPayload
    • PageCategory
    • PageSimpliedAlbums
    • FullAlbums
    • FullArtists
  • AudioAnalysisSection::mode and AudioFeatures::mode are f32s but should be Option<Mode>s where enum Mode { Major, Minor } as it is more useful.
  • CursorBasedPage should also not include the URLs.
  • Rename AudioFeatures.duration_ms to duration, and change its type from u32 to std::time::Duration.
  • Rename FullEpisode.duration_ms to duration, and change its type from u32 to std::time::Duration.
  • Rename SimplifiedEpisode.duration_ms to duration, and change its type from u32 to std::time::Duration.
  • Rename FullTrack.duration_ms to duration, and change its type from u32 to std::time::Duration.
  • Rename SimplifiedTrack.duration_ms to duration, and change its type from u32 to std::time::Duration.
  • SimplifiedEpisode::duration_ms should be a Duration.
  • Offset::position should be a Duration
  • CurrentlyPlayingContext::progress_ms should be progress: Option<Duration>.
  • CurrentPlaybackContext::progress_ms should be progress: Option<Duration>.
  • ResumePoint::resume_position_ms should be a Duration.
  • CurrentlyPlayingContext::timestamp should be a DateTime<Utc>
  • CurrentPlaybackContext::timestamp should be a DateTime<Utc>
  • SimplifiedPlayingContext::timestamp should be a DateTime<Utc>(SimplifiedPlayingContext is useless, just remove it.)

Dependencies

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Please also list any relevant details for your test configuration

  • Reduce wrapper object:
    • FullArtists: test_artist_related_artists, test_artists
    • FullTracks: test_artist_top_tracks, test_tracks
    • CursorPageFullArtists: test_current_user_followed_artists
    • SeversalSimplifiedShows: test_get_seversal_shows
    • DevicePayload: test_device
    • AudioFeaturesPayload: test_audios_features
    • PageCategory: test_categories
    • PageSimpliedAlbums: test_new_releases
    • FullAlbums: test_albums
  • Rename duration_ms to duration, and change its type from f32 to std::time::Duration
    • AudioFeatures: test_audio_features
    • FullEpisode: test_full_episode
    • SimplifiedEpisode: simplified_episode
    • FullTrack: test_full_track
    • SimplifiedTrack: test_simplified_track
  • ResumePoint::resume_position_ms should be a Duration: test_resume_point
  • CurrentlyPlayingContext/CurrentlyPlaybackContext/SimplifiedPlayingContext::timestamp should be a DateTime<Utc>
    • CurrentlyPlayingContext: test_currently_playing_context
    • CurrentPlaybackContext: test_current_playback_context
  • Offset::position should be a Duration: test_offset

PS: it seems the pull request template doesn't works, I just add the content manually, and I would like to open a new PR to test the pull request template individually


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ramsayleung/rspotify/pull/157 **Author:** [@ramsayleung](https://github.com/ramsayleung) **Created:** 11/21/2020 **Status:** ✅ Merged **Merged:** 12/15/2020 **Merged by:** [@ramsayleung](https://github.com/ramsayleung) **Base:** `master` ← **Head:** `ramsay_refactor_model` --- ### 📝 Commits (10+) - [`3f4e294`](https://github.com/ramsayleung/rspotify/commit/3f4e2944250526b8765ab891fb10018f8185aa85) Remove `FullArtists` struct, define it inside the endpoint function. - [`9321596`](https://github.com/ramsayleung/rspotify/commit/93215961f01dfa560786ec01ae8f3f00ea133c39) Merge branch 'master' into ramsay_refactor_model - [`b83a7b8`](https://github.com/ramsayleung/rspotify/commit/b83a7b899e3e0e3b24f02be539374facbd2c3dc2) Update CHANGELOG about removing `FullArtists`. - [`edf7d2c`](https://github.com/ramsayleung/rspotify/commit/edf7d2c8193c93d28ad0da616197f7ee4553ec27) Replace FullTracks with Vec<FullTrack>. - [`748d996`](https://github.com/ramsayleung/rspotify/commit/748d9961990a1c1f07cfcf6a61cbcfb74d26cc9b) Update document. - [`645bbab`](https://github.com/ramsayleung/rspotify/commit/645bbab80d5115453d887ce82e5f9a0d3d6d1881) Replace `AudioFeaturesPayload` with `Vec<AudioFeatures>`. - [`2463b6b`](https://github.com/ramsayleung/rspotify/commit/2463b6b3ea92426841f49ce7f5bcc972363f967d) Update CHANGELOG. - [`7373529`](https://github.com/ramsayleung/rspotify/commit/7373529dc85846d6a9826ebaa8c794c16cb5715b) Recover wrapper objects and make them public in crate - [`de43450`](https://github.com/ramsayleung/rspotify/commit/de43450e7c7e75747c60c37aadda48e6877eff19) Update CHANGELOG and remove unnecessary derived traits. - [`bc7c931`](https://github.com/ramsayleung/rspotify/commit/bc7c9315bb7ba78937a5fe64048026c123902f8c) Reduce `FullAlbums` wrapper object ### 📊 Changes **16 files changed** (+744 additions, -113 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+22 -2) 📝 `examples/with_refresh_token.rs` (+1 -1) 📝 `src/client.rs` (+31 -22) 📝 `src/model/album.rs` (+4 -6) 📝 `src/model/artist.rs` (+4 -6) 📝 `src/model/audio.rs` (+10 -4) 📝 `src/model/category.rs` (+2 -3) 📝 `src/model/context.rs` (+32 -21) 📝 `src/model/device.rs` (+21 -3) 📝 `src/model/mod.rs` (+121 -1) 📝 `src/model/offset.rs` (+10 -3) 📝 `src/model/show.rs` (+22 -7) 📝 `src/model/track.rs` (+16 -7) 📝 `src/util.rs` (+1 -1) 📝 `tests/test_models.rs` (+433 -26) 📝 `tests/test_with_oauth.rs` (+14 -0) </details> ### 📄 Description ## Description Keep polish the models by following the issues: + #127 + #149 ## Motivation and Context To make `rspotify`'s API easier to use. + [x] Types like FullAlbums, PageSimplifiedAlbums, etc exist as wrappers. This makes the API more complex. Instead, have that type exist solely in the API function that needs it, and then return a Vec<FullAlbum>. This drastically reduces the number of public API types. The wrapper objects need to be reduced: - [x] `FullTracks` - [x] `CursorPageFullArtists` - [x] `SeversalSimplifiedShows` - [x] `DevicePayload` - [x] `AudioFeaturesPayload` - [x] `PageCategory` - [x] `PageSimpliedAlbums` - [x] `FullAlbums` - [x] `FullArtists` + [ ] `AudioAnalysisSection::mode` and `AudioFeatures::mode` are `f32s` but should be `Option<Mode>s` where `enum Mode { Major, Minor } `as it is more useful. + [ ] ~~`CursorBasedPage` should also not include the URLs.~~ + [x] Rename `AudioFeatures.duration_ms` to duration, and change its type from `u32` to `std::time::Duration`. + [x] Rename `FullEpisode.duration_ms` to duration, and change its type from `u32` to `std::time::Duration`. + [x] Rename `SimplifiedEpisode.duration_ms` to duration, and change its type from `u32` to `std::time::Duration`. + [x] Rename `FullTrack.duration_ms` to duration, and change its type from `u32` to `std::time::Duration`. + [x] Rename `SimplifiedTrack.duration_ms` to duration, and change its type from `u32` to `std::time::Duration`. + [x] `SimplifiedEpisode::duration_ms` should be a `Duration`. + [x] `Offset::position` should be a `Duration` + [x] `CurrentlyPlayingContext::progress_ms` should be `progress`: `Option<Duration>`. + [x] `CurrentPlaybackContext::progress_ms` should be `progress`: `Option<Duration>`. + [x] `ResumePoint::resume_position_ms` should be a `Duration`. + [x] `CurrentlyPlayingContext::timestamp` should be a `DateTime<Utc>` + [x] `CurrentPlaybackContext::timestamp` should be a `DateTime<Utc>` + [x] ~~`SimplifiedPlayingContext::timestamp` should be a `DateTime<Utc>`~~(`SimplifiedPlayingContext` is useless, just remove it.) ## Dependencies ## Type of change Please delete options that are not relevant. - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [x] Reduce wrapper object: - [x] `FullArtists`: `test_artist_related_artists`, `test_artists` - [x] `FullTracks`: `test_artist_top_tracks`, `test_tracks` - [x] `CursorPageFullArtists`: `test_current_user_followed_artists` - [x] `SeversalSimplifiedShows`: `test_get_seversal_shows` - [x] `DevicePayload`: `test_device` - [x] `AudioFeaturesPayload`: `test_audios_features` - [x] `PageCategory`: `test_categories` - [x] `PageSimpliedAlbums`: `test_new_releases` - [x] `FullAlbums`: `test_albums` - [x] Rename `duration_ms` to `duration`, and change its type from `f32` to `std::time::Duration` - [x] `AudioFeatures`: `test_audio_features` - [x] `FullEpisode`: `test_full_episode` - [x] `SimplifiedEpisode`: `simplified_episode` - [x] `FullTrack`: `test_full_track` - [x] `SimplifiedTrack`: `test_simplified_track` + [x] `ResumePoint::resume_position_ms` should be a `Duration`: `test_resume_point` - [x] `CurrentlyPlayingContext/CurrentlyPlaybackContext/SimplifiedPlayingContext::timestamp` should be a `DateTime<Utc>` + [x] `CurrentlyPlayingContext`: `test_currently_playing_context` + [x] `CurrentPlaybackContext`: `test_current_playback_context` + [x] `Offset::position` should be a `Duration`: `test_offset` PS: it seems the pull request template doesn't works, I just add the content manually, and I would like to open a new PR to test the pull request template individually --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:24:04 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#275
No description provided.