mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[PR #185] [MERGED] Polish Token and OAuth #297
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#297
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ramsayleung/rspotify/pull/185
Author: @ramsayleung
Created: 2/14/2021
Status: ✅ Merged
Merged: 2/17/2021
Merged by: @marioortizmanero
Base:
master← Head:ramsay_optimize_expire_field📝 Commits (10+)
387bf33Change expires_at from u64 to DateTime3bdffd6Update comment2f685c7Change expire_in from u32 to Duration37f133dAdd test to check token.is_expired34f4423Update CHANGELOG.md72e7c12Change scope from string to hashsetdefad50Use customized module to deserialize/serialize duration48b5488Fix cargo clippy error.1b98a3bUpdate CHANGELOGed9f341Fix failed exampls📊 Changes
15 files changed (+309 additions, -125 deletions)
View changed files
📝
CHANGELOG.md(+6 -0)📝
examples/current_user_recently_played.rs(+5 -4)📝
examples/oauth_tokens.rs(+8 -9)📝
examples/ureq/device.rs(+5 -4)📝
examples/ureq/me.rs(+5 -4)📝
examples/ureq/search.rs(+9 -8)📝
examples/ureq/seek_track.rs(+5 -4)📝
examples/webapp/src/main.rs(+8 -5)📝
examples/with_refresh_token.rs(+2 -1)📝
src/lib.rs(+15 -2)📝
src/model/playlist.rs(+10 -2)📝
src/oauth2.rs(+171 -47)➖
src/util.rs(+0 -21)📝
tests/test_models.rs(+48 -0)📝
tests/test_with_oauth.rs(+12 -14)📄 Description
Description
As @Kestrer pointed out in #127, the
expires_atandexpires_inare not that easy to use:There is no way to store expires information into a signle field, since the response of requesting to
Spotifyfor an access token looks like this:It's possible to deserialize this
expires_intoToken.expirefield, like this:In order to convert expires_in(
elapsed) toInstant, it's necessory to instantiate aInstantobject indeserializefunction, it turns out to be a stateful function. If we serialize theTokeninto cache file and deserialize it toToken, then theexpiresvalue will change unexpectedly.Hence, it's necessary to keep two fields(
expires_in,expires_at) to handle expire information, theexpires_inhas been updated fromu32tostd::time::Duration, and theexpires_atfield has been updated fromu64tochrono::DateTime.For more details about the support of
serdeforstd::time::Instant, check this issue: https://github.com/serde-rs/serde/issues/1375Motivation and Context
To make
rspotifyergonomic to use. Modification:Token.expires_infromu32tostd::time::DurationToken.expires_atfromi64tochrono::DateTime<Utc>Token.scopefromStringtoHashSet.OAuth.scopefromStringtoHashSet.Dependencies
None
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
test_write_tokentest_token_is_expired🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.