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: String
An access token that can be provided in subsequent calls
expires_in: TimeDelta
The 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 PartialEq for Token
impl PartialEq for Token
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<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.