pub struct Token {
pub access_token: String,
pub expires_in: Duration,
pub expires_at: Option<DateTime<Utc>>,
pub refresh_token: Option<String>,
pub scopes: HashSet<String, RandomState>,
}
Expand description
Spotify access token information
Fields
access_token: String
An access token that can be provided in subsequent calls
expires_in: Duration
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, RandomState>
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
sourceimpl Token
impl Token
sourcepub fn from_cache<T>(path: T) -> Result<Token, ModelError> where
T: AsRef<Path>,
pub fn from_cache<T>(path: T) -> Result<Token, ModelError> where
T: AsRef<Path>,
Tries to initialize the token from a cache file.
sourcepub fn write_cache<T>(&self, path: T) -> Result<(), ModelError> where
T: AsRef<Path>,
pub fn write_cache<T>(&self, path: T) -> Result<(), ModelError> where
T: AsRef<Path>,
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, RandomState>
pub fn auth_headers(&self) -> HashMap<String, String, RandomState>
Generates an HTTP token authorization header with proper formatting
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Token
impl<'de> Deserialize<'de> for Token
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for Token
impl Serialize for Token
sourcefn 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,
Serialize this value into the given Serde serializer. Read more
impl Eq for Token
impl StructuralEq for Token
impl StructuralPartialEq for Token
Auto Trait Implementations
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more