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 refreshing token #255

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
f887e93
Use Github Action to automatically publish crate to crate.io
ramsayleung May 9, 2021
c2046c7
Add UnknownId and some tests
marioortizmanero Aug 20, 2021
d5d2812
Proper docs thanks to reworked macro
marioortizmanero Aug 20, 2021
5a52393
Module-level documentation
marioortizmanero Aug 20, 2021
1ab8ad1
Now with an example!
marioortizmanero Aug 20, 2021
3b66b9a
Stuck fighting compiler error about Deserialize
marioortizmanero Aug 20, 2021
5d459f4
First draft with newtype
marioortizmanero Aug 24, 2021
ea435db
The compiler hates me
marioortizmanero Aug 24, 2021
ce0a860
Mixing Attempt #1 and Attempt #2
marioortizmanero Aug 24, 2021
bbf0cc2
Almost working now
marioortizmanero Aug 25, 2021
5b1562f
Finally fix Offset impl
marioortizmanero Aug 25, 2021
aa34757
Even simpler Offset this way
marioortizmanero Aug 25, 2021
6d9a748
Got it working!
marioortizmanero Aug 25, 2021
67e4838
Format
marioortizmanero Aug 25, 2021
bb85b68
Simplify lifetimes
marioortizmanero Aug 25, 2021
678906e
Clippy
marioortizmanero Aug 25, 2021
5a38a4e
Last clippy fixes
marioortizmanero Aug 25, 2021
27bdc36
Fix compilation of tests
marioortizmanero Aug 25, 2021
b01415c
Finally fix all tests
marioortizmanero Aug 25, 2021
92eb74b
Fix more docs
marioortizmanero Aug 25, 2021
367620c
Object-safe trait with String
marioortizmanero Aug 26, 2021
58219b5
Note about type safety, cargo fmt
marioortizmanero Aug 28, 2021
a5f9093
attempt without generics
marioortizmanero Aug 29, 2021
641c4e1
Fix tests and docs finally
marioortizmanero Aug 30, 2021
1be8217
Clarify comment
marioortizmanero Aug 30, 2021
3b02d39
Remove outdated comment
marioortizmanero Aug 30, 2021
48187a3
Type inference simplification
marioortizmanero Aug 30, 2021
98fcb28
Revert test
marioortizmanero Aug 30, 2021
d803c7f
Simplify assert_eq into assert
marioortizmanero Aug 30, 2021
4c0d9d3
Clarify docs for Id
marioortizmanero Aug 30, 2021
91f036e
Polish docs
marioortizmanero Aug 30, 2021
4a51f81
Fix cached token scopes
Rigellute Aug 30, 2021
fe28024
Merge pull request #245 from Rigellute/master
marioortizmanero Aug 30, 2021
765911d
Fix CI
marioortizmanero Aug 31, 2021
a3d14dc
Simplify recommendations
marioortizmanero Aug 31, 2021
9333e27
Merge pull request #248 from ramsayleung/fix-ci
ramsayleung Sep 1, 2021
0c767e7
Fix CI, generics for HashMap, ready 4 review
marioortizmanero Sep 1, 2021
0b2c479
Serialize attributes
marioortizmanero Sep 1, 2021
5d228ab
update changelog
marioortizmanero Sep 2, 2021
3636c91
Update CHANGELOG
marioortizmanero Sep 2, 2021
3d6f50a
Merge pull request #249 from ramsayleung/simplify-recommendations
ramsayleung Sep 2, 2021
683aae3
Merge with master
marioortizmanero Sep 2, 2021
f85d5e8
Fix TrackId
marioortizmanero Sep 2, 2021
2b418f9
Remove unnecessary `_type` fields
marioortizmanero Sep 6, 2021
bc1c7be
Cleanup Cargo.toml
marioortizmanero Sep 6, 2021
4489430
logging -> debug_assert
marioortizmanero Sep 6, 2021
0e38d95
More cargo cleanup
marioortizmanero Sep 6, 2021
933f116
Formatting
marioortizmanero Sep 6, 2021
6ca5fff
No need for a fancy logger
marioortizmanero Sep 6, 2021
466a9a9
Clean up derives
marioortizmanero Sep 6, 2021
da95750
Lots of fixes & improvements
marioortizmanero Sep 6, 2021
c337ae8
Upgraded all dependencies with `cargo upgrade`
marioortizmanero Sep 6, 2021
bdfc9a7
Fix docs errors
marioortizmanero Sep 6, 2021
1fb3492
Fix clippy errors
marioortizmanero Sep 6, 2021
775a8fb
Fix test errors
marioortizmanero Sep 6, 2021
f3c4160
Merge branch 'master' into ramsay_use_ci_to_publish_crate
ramsayleung Sep 6, 2021
1b9aadf
Add bash script to publish crates
ramsayleung Sep 6, 2021
e5d3eb2
Add new lines
ramsayleung Sep 6, 2021
8fa008d
fix path error
ramsayleung Sep 6, 2021
c40781a
make publish.sh executable
ramsayleung Sep 6, 2021
84a0a8a
Remove unnecessary line
ramsayleung Sep 6, 2021
46f242b
remove git config
Sep 7, 2021
6aa9b92
remove git config
ramsayleung Sep 7, 2021
e4a9c77
Merge branch 'ramsay_use_ci_to_publish_crate' of github.com:ramsayleu…
Sep 7, 2021
1e2d62b
Merge pull request #211 from ramsayleung/ramsay_use_ci_to_publish_crate
marioortizmanero Sep 7, 2021
b3439c9
Merge pull request #250 from ramsayleung/cleanup
marioortizmanero Sep 7, 2021
022dcf4
Merge branch 'master' into fix-ids-4
marioortizmanero Sep 7, 2021
c74260b
fix changelog
marioortizmanero Sep 14, 2021
f9424a4
Custom deserialization and tests
marioortizmanero Sep 14, 2021
c26eed0
We can actually use &str for deserialization
marioortizmanero Sep 15, 2021
d654f82
Allow negative values in duration_ms
flip1995 Sep 15, 2021
e762c5a
Merge pull request #251 from flip1995/neg_resume_position_ms
ramsayleung Sep 15, 2021
07ce3db
Add note in changelog about uri and _type removed
marioortizmanero Sep 15, 2021
cc63f2e
Fix reference for FullShow and remove _type
marioortizmanero Sep 15, 2021
7543b2a
Fix reference for SimpleShow and remove _type
marioortizmanero Sep 15, 2021
40b5aa9
Fix episode models
marioortizmanero Sep 15, 2021
e5caadd
Formatting
marioortizmanero Sep 15, 2021
98c299c
Add TODOs about playlist endpoint inconsistencies
marioortizmanero Sep 15, 2021
89b3721
Merge pull request #244 from ramsayleung/fix-ids-4
marioortizmanero Sep 15, 2021
854369c
Fix token reading with prompt utility
marioortizmanero Sep 19, 2021
ae30eae
Fix docs
marioortizmanero Sep 20, 2021
ba98d32
Merge pull request #252 from ramsayleung/fix-token-read
ramsayleung Sep 20, 2021
9ff89c4
Fix auth token not being set properly
Rigellute Sep 17, 2021
09f5da4
Fix unauthorized playback control
Rigellute Sep 20, 2021
4bb3906
Revert "Fix auth token not being set properly"
Rigellute Sep 20, 2021
5527736
Change `get_token_mut` to return mutable reference to Option
Rigellute Sep 20, 2021
a096fda
Merge pull request #254 from Rigellute/master
marioortizmanero Sep 20, 2021
2b2411b
Fix self-refreshing token
marioortizmanero Sep 25, 2021
df5f9f1
Fix some deadlocks and examples
marioortizmanero Sep 25, 2021
dfd5e1a
Merge branch 'master' into fix-refresh-token
marioortizmanero Sep 25, 2021
a5eb0a5
Fix clippy
marioortizmanero Sep 25, 2021
0dbda18
Fix threading example
marioortizmanero Sep 25, 2021
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
29 changes: 29 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
create:
tags:
- v*

name: Publish Crate

jobs:
publish:
name: Deploy a new version of Rspotify to crate.io
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Release
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
shell: bash
run: |
# Publishing crates
"${GITHUB_WORKSPACE}/tools/publish.sh"
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,16 @@ More in the [`examples` directory](https://github.com/ramsayleung/rspotify/tree/
- The `Spotify` client has been split up by authorization flows (`ClientCredsSpotify`, `AuthCodeSpotify`, `AuthCodePkceSpotify`), which allows us to remove the builder pattern. The authentication process has been rewritten. ([#216](https://github.com/ramsayleung/rspotify/pull/216)).
- Fix typo in `user_playlist_remove_specific_occurrenes_of_tracks`, now it's `user_playlist_remove_specific_occurrences_of_tracks`.
- ([#123](https://github.com/ramsayleung/rspotify/pull/123)) All fallible calls in the client return a `ClientError` rather than using `failure`.
- ([#161](https://github.com/ramsayleung/rspotify/pull/161)) Endpoints taking `Vec<String>/&[String]` as parameter have changed to `impl IntoIterator<Item = &Id<Type>>`.
+ The endpoints which changes parameter from `Vec<String>` to `impl IntoIterator<Item = &Id<Type>>`:
- ([#244](https://github.com/ramsayleung/rspotify/pull/244)) Model objects like `FullTrack` or `AudioFeatures` have had their `_type` and `uri` fields removed. These can be accessed instead with the `id` field: `id._type()` or `id.uri()`.
- ([#244](https://github.com/ramsayleung/rspotify/pull/244)) Endpoints taking `Vec<String>/&[String]` as parameter have changed to `impl IntoIterator<Item = &Id>`.
+ The endpoints which changes parameter from `Vec<String>` to `impl IntoIterator<Item = &Id>`:
- `albums`
- `artists`
- `check_users_saved_shows`
- `get_several_episodes`
- `remove_users_saved_shows`
- `save_shows`
+ The endpoints which changes parameter from `&[String]` to `impl IntoIterator<Item = &Id<Type>>`:
+ The endpoints which changes parameter from `&[String]` to `impl IntoIterator<Item = &Id>`:
- `audios_features`
- `current_user_saved_albums_add`
- `current_user_saved_albums_contains`
Expand All @@ -211,7 +212,7 @@ More in the [`examples` directory](https://github.com/ramsayleung/rspotify/tree/
- `user_playlist_replace_tracks`
- `user_unfollow_artists`
- `user_unfollow_users`
+ The endpoints which changes parameter from `String` to `&Id<Type>`:
+ The endpoints which changes parameter from `String` to `&Id`:
- `get_a_show`
- `get_an_episode`
- `get_shows_episodes`
Expand All @@ -226,6 +227,7 @@ More in the [`examples` directory](https://github.com/ramsayleung/rspotify/tree/
- ([#128](https://github.com/ramsayleung/rspotify/pull/128)) Refactor all enum files with `strum`, reduced boilerplate code.
+ All enums don't have a method named `as_str()` anymore, by leveraging `strum`, it's easy to convert strings to enum variants based on their name, with method `as_ref()`.
- Fix typo in `transfer_playback`: `device_id` to `device_ids`.
- ([#249](https://github.com/ramsayleung/rspotify/pull/249)) The `recommendations` endpoint has been made simpler to use; the attributes are now serialized with `RecommendationsAttribute`.
- ([#145](https://github.com/ramsayleung/rspotify/pull/145)) Refactor models to make it easier to use:
+ Changed type of `track` in `PlayHistory` to `FullTrack` ([#139](https://github.com/ramsayleung/rspotify/pull/139)).
+ Rename model `CurrentlyPlaybackContext` to `CurrentPlaybackContext`
Expand All @@ -245,7 +247,7 @@ More in the [`examples` directory](https://github.com/ramsayleung/rspotify/tree/
+ Change `{FullArtist, FullPlaylist, PublicUser, PrivateUser}::followers` from `HashMap<String, Option<Value>>` to struct `Followers`
+ Replace `Actions::disallows` with a `Vec<DisallowKey>` by removing all entires whose value is false, which will result in a simpler API
+ Replace `{FullAlbum, SimplifiedEpisode, FullEpisode}::release_date_precision` from `String` to `DatePrecision` enum, makes it easier to use.
+ Id and URI parameters are type-safe now everywhere, `Id<Type>` and `IdBuf<Type>` types for ids/URIs added (non-owning and owning structs).
+ Id and URI parameters are type-safe now everywhere thanks to the `Id` trait and its implementations.
- ([#157](https://github.com/ramsayleung/rspotify/pull/157)) Keep polishing models to make it easier to use:
+ Constrain visibility of `FullArtists` struct with `pub (in crate)`, make `artists` and `artist_related_artists` endpoints return a `Vec<FullArtist>` instead.
+ Constrain visibility of `FullTracks` struct with `pub (in crate)`, make `tracks` and `artist_top_tracks` endpoints return a `Vec<FullTrack>` instead.
Expand Down
34 changes: 13 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,25 @@ rspotify-macros = { path = "rspotify-macros", version = "0.10.0" }
rspotify-model = { path = "rspotify-model", version = "0.10.0" }
rspotify-http = { path = "rspotify-http", version = "0.10.0", default-features = false }

### Client ###
async-stream = { version = "0.3.0", optional = true }
async-trait = { version = "0.1.48", optional = true }
async-stream = { version = "0.3.2", optional = true }
async-trait = { version = "0.1.51", optional = true }
base64 = "0.13.0"
chrono = { version = "0.4.13", features = ["serde", "rustc-serialize"] }
chrono = { version = "0.4.19", features = ["serde", "rustc-serialize"] }
dotenv = { version = "0.15.0", optional = true }
futures = { version = "0.3.8", optional = true }
futures-util = "0.3.8" # TODO
getrandom = "0.2.0"
log = "0.4.11"
maybe-async = "0.2.1"
serde = { version = "1.0.115", features = ["derive"] }
serde_json = "1.0.57"
thiserror = "1.0.20"
futures = { version = "0.3.17", optional = true }
getrandom = "0.2.3"
log = "0.4.14"
maybe-async = "0.2.6"
serde = { version = "1.0.130", default-features = false }
serde_json = "1.0.67"
thiserror = "1.0.29"
url = "2.2.2"
webbrowser = { version = "0.5.5", optional = true }

### Auth ###
# chrono = { version = "0.4.13", features = ["serde", "rustc-serialize"] }
# log = "0.4.11"
# maybe-async = "0.2.1"
# thiserror = "1.0.20"

[dev-dependencies]
env_logger = "0.9.0"
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
futures-util = "0.3.8"
env_logger = { version = "0.9.0", default-features = false }
tokio = { version = "1.11.0", features = ["rt-multi-thread", "macros"] }
futures-util = "0.3.17"

[features]
default = ["client-reqwest", "reqwest-default-tls"]
Expand Down
8 changes: 4 additions & 4 deletions examples/client_creds.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rspotify::{model::Id, prelude::*, ClientCredsSpotify, Credentials};
use rspotify::{model::AlbumId, prelude::*, ClientCredsSpotify, Credentials};

#[tokio::main]
async fn main() {
Expand All @@ -23,16 +23,16 @@ async fn main() {
// ```
let creds = Credentials::from_env().unwrap();

let mut spotify = ClientCredsSpotify::new(creds);
let spotify = ClientCredsSpotify::new(creds);

// Obtaining the access token. Requires to be mutable because the internal
// token will be modified. We don't need OAuth for this specific endpoint,
// so `...` is used instead of `prompt_for_user_token`.
spotify.request_token().await.unwrap();

// Running the requests
let birdy_uri = Id::from_uri("spotify:album:0sNOF9WDwhWunNAHPD3Baj").unwrap();
let albums = spotify.album(birdy_uri).await;
let birdy_uri = AlbumId::from_uri("spotify:album:0sNOF9WDwhWunNAHPD3Baj").unwrap();
let albums = spotify.album(&birdy_uri).await;

println!("Response: {:#?}", albums);
}
2 changes: 1 addition & 1 deletion examples/oauth_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn main() {
let url = spotify.get_authorize_url(false).unwrap();
spotify.prompt_for_token(&url).await.unwrap();

let token = spotify.get_token().await;
let token = spotify.token.lock().await.unwrap();
println!("Access token: {}", token.as_ref().unwrap().access_token);
println!(
"Refresh token: {}",
Expand Down
13 changes: 7 additions & 6 deletions examples/ureq/threading.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This example showcases how the Rspotify client can be used to perform
//! multithreaded requests as well.

use rspotify::{model::Id, prelude::*, ClientCredsSpotify, Credentials};
use rspotify::{model::AlbumId, prelude::*, ClientCredsSpotify, Credentials};
use std::{
sync::{mpsc::channel, Arc},
thread,
Expand All @@ -12,10 +12,11 @@ fn main() {

let spotify = ClientCredsSpotify::new(creds);
let ids = [
Id::from_uri("spotify:album:0sNOF9WDwhWunNAHPD3Baj").unwrap(),
Id::from_uri("spotify:album:5EBb7SSkPgxO9Lmt8NjAPT").unwrap(),
Id::from_uri("spotify:album:3jtOeny1Xh5fp6aSOHahe2").unwrap(),
AlbumId::from_uri("spotify:album:0sNOF9WDwhWunNAHPD3Baj").unwrap(),
AlbumId::from_uri("spotify:album:5EBb7SSkPgxO9Lmt8NjAPT").unwrap(),
AlbumId::from_uri("spotify:album:3jtOeny1Xh5fp6aSOHahe2").unwrap(),
];
let num_ids = ids.len();
let mut handles = Vec::new();
let (wr, rd) = channel();

Expand All @@ -27,14 +28,14 @@ fn main() {
let spotify = Arc::clone(&spotify);
let wr = wr.clone();
let handle = thread::spawn(move || {
let albums = spotify.album(id).unwrap();
let albums = spotify.album(&id).unwrap();
wr.send(albums).unwrap();
});

handles.push(handle);
}

for _ in ids {
for _ in 0..num_ids {
let album = rd.recv().unwrap();
println!("Album: {}", album.name);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/with_auto_reauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async fn main() {
.await
.lock()
.await
.unwrap()
.as_mut()
.map(|x| x.expires_at = Some(now.clone()));
println!(">>> Session two, the token should expire, then re-auth automatically");
Expand All @@ -104,8 +105,9 @@ async fn main() {
.await
.lock()
.await
.unwrap()
.as_mut()
.map(|x| x.expires_at.replace(now));
.map(|x| x.expires_at = Some(now));
println!(">>> New Session two from ClientCredsSpotify, expiring the token and then re-auth automatically");
client_creds_do_things(&spotify).await;
}
14 changes: 7 additions & 7 deletions examples/with_refresh_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
//! tokens](https://github.com/felix-hilden/tekore/issues/86), so in the case of
//! Spotify it doesn't seem to revoke them at all.

use rspotify::{model::Id, prelude::*, scopes, AuthCodeSpotify, Credentials, OAuth};
use rspotify::{model::ArtistId, prelude::*, scopes, AuthCodeSpotify, Credentials, OAuth};

// Sample request that will follow some artists, print the user's
// followed artists, and then unfollow the artists.
async fn do_things(spotify: AuthCodeSpotify) {
let artists = vec![
Id::from_id("3RGLhK1IP9jnYFH4BRFJBS").unwrap(), // The Clash
Id::from_id("0yNLKJebCb8Aueb54LYya3").unwrap(), // New Order
Id::from_id("2jzc5TC5TVFLXQlBNiIUzE").unwrap(), // a-ha
let artists = [
&ArtistId::from_id("3RGLhK1IP9jnYFH4BRFJBS").unwrap(), // The Clash
&ArtistId::from_id("0yNLKJebCb8Aueb54LYya3").unwrap(), // New Order
&ArtistId::from_id("2jzc5TC5TVFLXQlBNiIUzE").unwrap(), // a-ha
];
spotify
.user_follow_artists(artists.clone())
.user_follow_artists(artists)
.await
.expect("couldn't follow artists");
println!("Followed {} artists successfully.", artists.len());
Expand All @@ -42,7 +42,7 @@ async fn do_things(spotify: AuthCodeSpotify) {
);

spotify
.user_unfollow_artists(artists.clone())
.user_unfollow_artists(artists)
.await
.expect("couldn't unfollow artists");
println!("Unfollowed {} artists successfully.", artists.len());
Expand Down
23 changes: 9 additions & 14 deletions rspotify-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ rspotify-model = { path = "../rspotify-model", version = "0.10.0" }

# Temporary until https://github.com/rust-lang/rfcs/issues/2739, for
# `maybe_async`.
async-trait = { version = "0.1.48", optional = true }
base64 = "0.13.0"
futures = { version = "0.3.8", optional = true }
log = "0.4.11"
maybe-async = "0.2.4"
reqwest = { version = "0.11.0", default-features = false, features = ["json", "socks"], optional = true }
serde_json = "1.0.57"
thiserror = "1.0.20"
ureq = { version = "2.0", default-features = false, features = ["json", "cookies"], optional = true }
url = "2.2.2"
async-trait = { version = "0.1.51", optional = true }
log = "0.4.14"
maybe-async = "0.2.6"
serde_json = "1.0.67"
thiserror = "1.0.29"

[dev-dependencies]
env_logger = "0.9.0"
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
# Supported clients
reqwest = { version = "0.11.4", default-features = false, features = ["json", "socks"], optional = true }
ureq = { version = "2.2.0", default-features = false, features = ["json", "cookies"], optional = true }

[features]
default = ["client-reqwest", "reqwest-default-tls"]
Expand All @@ -50,5 +45,5 @@ reqwest-native-tls-vendored = ["reqwest/native-tls-vendored"]
ureq-rustls-tls = ["ureq/tls"]

# Internal features for checking async or sync compilation
__async = ["async-trait", "futures"]
__async = ["async-trait"]
__sync = ["maybe-async/is_sync"]
2 changes: 1 addition & 1 deletion rspotify-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ keywords = ["spotify", "api", "rspotify"]
edition = "2018"

[dev-dependencies]
serde_json = "1.0.57"
serde_json = "1.0.67"
11 changes: 5 additions & 6 deletions rspotify-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ keywords = ["spotify", "api", "rspotify"]
edition = "2018"

[dependencies]
chrono = { version = "0.4.13", features = ["serde", "rustc-serialize"] }
serde = { version = "1.0.115", features = ["derive"] }
strum = { version = "0.21", features = ["derive"] }
thiserror = "1.0.20"
chrono = { version = "0.4.19", features = ["serde", "rustc-serialize"] }
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.67"
strum = { version = "0.21.0", features = ["derive"] }
thiserror = "1.0.29"

[dev-dependencies]
serde_json = "1.0.57"
28 changes: 14 additions & 14 deletions rspotify-model/src/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use serde::{Deserialize, Serialize};

use std::collections::HashMap;

use super::artist::SimplifiedArtist;
use super::image::Image;
use super::page::Page;
use super::track::SimplifiedTrack;
use super::Restriction;
use crate::{AlbumType, Copyright, DatePrecision, Type};
use crate::{
AlbumId, AlbumType, Copyright, DatePrecision, Image, Page, RestrictionReason, SimplifiedArtist,
SimplifiedTrack,
};

/// Simplified Album Object
///
Expand All @@ -25,7 +23,7 @@ pub struct SimplifiedAlbum {
pub available_markets: Vec<String>,
pub external_urls: HashMap<String, String>,
pub href: Option<String>,
pub id: Option<String>,
pub id: Option<AlbumId>,
pub images: Vec<Image>,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -34,9 +32,6 @@ pub struct SimplifiedAlbum {
pub release_date_precision: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub restrictions: Option<Restriction>,
#[serde(rename = "type")]
pub _type: Type,
pub uri: Option<String>,
}

/// Full Album Object
Expand All @@ -52,16 +47,13 @@ pub struct FullAlbum {
pub external_urls: HashMap<String, String>,
pub genres: Vec<String>,
pub href: String,
pub id: String,
pub id: AlbumId,
pub images: Vec<Image>,
pub name: String,
pub popularity: u32,
pub release_date: String,
pub release_date_precision: DatePrecision,
pub tracks: Page<SimplifiedTrack>,
#[serde(rename = "type")]
pub _type: Type,
pub uri: String,
}

/// Full Albums wrapped by Vec object
Expand All @@ -88,3 +80,11 @@ pub struct SavedAlbum {
pub added_at: DateTime<Utc>,
pub album: FullAlbum,
}

/// Album restriction object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-albumrestrictionobject)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Restriction {
pub reason: RestrictionReason,
}
Loading