pub struct Token {
pub access_token: String,
pub expires_in: TimeDelta,
pub expires_at: Option<DateTime<Utc>>,
pub refresh_token: Option<String>,
pub scopes: HashSet<String>,
}Expand description
Spotify access token information
Fields§
§access_token: StringAn access token that can be provided in subsequent calls
expires_in: TimeDeltaThe time period for which the access token is valid.
expires_at: Option<DateTime<Utc>>The valid time for which the access token is available represented in ISO 8601 combined date and time.
refresh_token: Option<String>A token that can be sent to the Spotify Accounts service in place of an authorization code
scopes: HashSet<String>A list of scopes
which have been granted for this access_token
You may use the scopes! macro in
rspotify-macros to build it at
compile time easily.
Implementations§
Source§impl Token
impl Token
Sourcepub fn from_cache<T>(path: T) -> Result<Token, ModelError>
pub fn from_cache<T>(path: T) -> Result<Token, ModelError>
Tries to initialize the token from a cache file.
Sourcepub fn write_cache<T>(&self, path: T) -> Result<(), ModelError>
pub fn write_cache<T>(&self, path: T) -> Result<(), ModelError>
Saves the token information into its cache file.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token is expired. It includes a margin of 10 seconds (which is how much a request would take in the worst case scenario).
Sourcepub fn auth_headers(&self) -> HashMap<String, String>
pub fn auth_headers(&self) -> HashMap<String, String>
Generates an HTTP token authorization header with proper formatting
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Token
impl<'de> Deserialize<'de> for Token
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Token, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Token, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Token
impl Serialize for Token
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for Token
impl StructuralPartialEq for Token
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more