pub struct ClientCredsSpotify {
    pub config: Config,
    pub creds: Credentials,
    pub token: Arc<Mutex<Option<Token>>>,
    /* private fields */
}
Expand description

The Client Credentials Flow client for the Spotify API.

This is the most basic flow. It requests a token to Spotify given some client credentials, without user authorization. The only step to take is to call Self::request_token. See this example.

Note: This flow does not include authorization and therefore cannot be used to access or to manage the endpoints related to user private data in OAuthClient.

Fields§

§config: Config§creds: Credentials§token: Arc<Mutex<Option<Token>>>

Implementations§

source§

impl ClientCredsSpotify

source

pub fn new(creds: Credentials) -> Self

Builds a new ClientCredsSpotify given a pair of client credentials and OAuth information.

source

pub fn from_token(token: Token) -> Self

Build a new ClientCredsSpotify from an already generated token. Note that once the token expires this will fail to make requests, as the client credentials aren’t known.

source

pub fn with_config(creds: Credentials, config: Config) -> Self

Same as Self::new but with an extra parameter to configure the client.

source

pub fn read_token_cache(&self) -> ClientResult<Option<Token>>

Tries to read the cache file’s token.

This will return an error if the token couldn’t be read (e.g. it’s not available or the JSON is malformed). It may return Ok(None) if:

  • The read token is expired
  • The cached token is disabled in the config
source

pub fn request_token(&self) -> ClientResult<()>

Obtains the client access token for the app. The resulting token will be saved internally.

Trait Implementations§

source§

impl BaseClient for ClientCredsSpotify

This client has access to the base methods.

source§

fn refetch_token(&self) -> ClientResult<Option<Token>>

Note that refetching a token in the Client Credentials flow is equivalent to requesting a token from scratch, since there’s no refresh token available.

source§

fn get_http(&self) -> &HttpClient

source§

fn get_token(&self) -> Arc<Mutex<Option<Token>>>

Note that the token is wrapped by a Mutex in order to allow interior mutability. This is required so that the entire client doesn’t have to be mutable (the token is accessed to from every endpoint).
source§

fn get_creds(&self) -> &Credentials

source§

fn get_config(&self) -> &Config

source§

fn api_url(&self, url: &str) -> String

Returns the absolute URL for an endpoint in the API.
source§

fn auth_url(&self, url: &str) -> String

Returns the absolute URL for an authentication step in the API.
source§

fn auto_reauth(&self) -> ClientResult<()>

Re-authenticate the client automatically if it’s configured to do so, which uses the refresh token to obtain a new access token.
source§

fn refresh_token(&self) -> ClientResult<()>

Refreshes the current access token given a refresh token. The obtained token will be saved internally.
source§

fn write_token_cache(&self) -> ClientResult<()>

Updates the cache file at the internal cache path. Read more
source§

fn fetch_access_token( &self, payload: &Form<'_>, headers: Option<&Headers> ) -> ClientResult<Token>

Sends a request to Spotify for an access token.
source§

fn track( &self, track_id: TrackId<'_>, market: Option<Market> ) -> ClientResult<FullTrack>

Returns a single track given the track’s ID, URI or URL. Read more
source§

fn tracks<'a>( &self, track_ids: impl IntoIterator<Item = TrackId<'a>> + Send + 'a, market: Option<Market> ) -> ClientResult<Vec<FullTrack>>

Returns a list of tracks given a list of track IDs, URIs, or URLs. Read more
source§

fn artist(&self, artist_id: ArtistId<'_>) -> ClientResult<FullArtist>

Returns a single artist given the artist’s ID, URI or URL. Read more
source§

fn artists<'a>( &self, artist_ids: impl IntoIterator<Item = ArtistId<'a>> + Send + 'a ) -> ClientResult<Vec<FullArtist>>

Returns a list of artists given the artist IDs, URIs, or URLs. Read more
source§

fn artist_albums<'a>( &'a self, artist_id: ArtistId<'a>, include_groups: impl IntoIterator<Item = AlbumType> + Send + Copy + 'a, market: Option<Market> ) -> Paginator<'_, ClientResult<SimplifiedAlbum>>

Get Spotify catalog information about an artist’s albums. Read more
source§

fn artist_albums_manual<'a>( &self, artist_id: ArtistId<'_>, include_groups: impl IntoIterator<Item = AlbumType> + Send + 'a, market: Option<Market>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<SimplifiedAlbum>>

The manually paginated version of Self::artist_albums.
source§

fn artist_top_tracks( &self, artist_id: ArtistId<'_>, market: Option<Market> ) -> ClientResult<Vec<FullTrack>>

Get Spotify catalog information about an artist’s top 10 tracks by country. Read more
Get Spotify catalog information about artists similar to an identified artist. Similarity is based on analysis of the Spotify community’s listening history. Read more
source§

fn album( &self, album_id: AlbumId<'_>, market: Option<Market> ) -> ClientResult<FullAlbum>

Returns a single album given the album’s ID, URIs or URL. Read more
source§

fn albums<'a>( &self, album_ids: impl IntoIterator<Item = AlbumId<'a>> + Send + 'a, market: Option<Market> ) -> ClientResult<Vec<FullAlbum>>

Returns a list of albums given the album IDs, URIs, or URLs. Read more
source§

fn search( &self, q: &str, _type: SearchType, market: Option<Market>, include_external: Option<IncludeExternal>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<SearchResult>

Search for an Item. Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string. Read more
source§

fn album_track<'a>( &'a self, album_id: AlbumId<'a>, market: Option<Market> ) -> Paginator<'_, ClientResult<SimplifiedTrack>>

Get Spotify catalog information about an album’s tracks. Read more
source§

fn album_track_manual( &self, album_id: AlbumId<'_>, market: Option<Market>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<SimplifiedTrack>>

The manually paginated version of Self::album_track.
source§

fn user(&self, user_id: UserId<'_>) -> ClientResult<PublicUser>

Gets basic profile information about a Spotify User. Read more
source§

fn playlist( &self, playlist_id: PlaylistId<'_>, fields: Option<&str>, market: Option<Market> ) -> ClientResult<FullPlaylist>

Get full details about Spotify playlist. Read more
source§

fn user_playlist( &self, user_id: UserId<'_>, playlist_id: Option<PlaylistId<'_>>, fields: Option<&str> ) -> ClientResult<FullPlaylist>

Gets playlist of a user. Read more
source§

fn playlist_check_follow( &self, playlist_id: PlaylistId<'_>, user_ids: &[UserId<'_>] ) -> ClientResult<Vec<bool>>

Check to see if the given users are following the given playlist. Read more
source§

fn get_a_show( &self, id: ShowId<'_>, market: Option<Market> ) -> ClientResult<FullShow>

Get Spotify catalog information for a single show identified by its unique Spotify ID. Read more
source§

fn get_several_shows<'a>( &self, ids: impl IntoIterator<Item = ShowId<'a>> + Send + 'a, market: Option<Market> ) -> ClientResult<Vec<SimplifiedShow>>

Get Spotify catalog information for multiple shows based on their Spotify IDs. Read more
source§

fn get_shows_episodes<'a>( &'a self, id: ShowId<'a>, market: Option<Market> ) -> Paginator<'_, ClientResult<SimplifiedEpisode>>

Get Spotify catalog information about an show’s episodes. Optional parameters can be used to limit the number of episodes returned. Read more
source§

fn get_shows_episodes_manual( &self, id: ShowId<'_>, market: Option<Market>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<SimplifiedEpisode>>

The manually paginated version of Self::get_shows_episodes.
source§

fn get_an_episode( &self, id: EpisodeId<'_>, market: Option<Market> ) -> ClientResult<FullEpisode>

Get Spotify catalog information for a single episode identified by its unique Spotify ID. Read more
source§

fn get_several_episodes<'a>( &self, ids: impl IntoIterator<Item = EpisodeId<'a>> + Send + 'a, market: Option<Market> ) -> ClientResult<Vec<FullEpisode>>

Get Spotify catalog information for multiple episodes based on their Spotify IDs. Read more
source§

fn track_features(&self, track_id: TrackId<'_>) -> ClientResult<AudioFeatures>

Get audio features for a track Read more
source§

fn tracks_features<'a>( &self, track_ids: impl IntoIterator<Item = TrackId<'a>> + Send + 'a ) -> ClientResult<Option<Vec<AudioFeatures>>>

Get Audio Features for Several Tracks Read more
source§

fn track_analysis(&self, track_id: TrackId<'_>) -> ClientResult<AudioAnalysis>

Get Audio Analysis for a Track Read more
source§

fn categories<'a>( &'a self, locale: Option<&'a str>, country: Option<Market> ) -> Paginator<'_, ClientResult<Category>>

Get a list of new album releases featured in Spotify Read more
source§

fn categories_manual( &self, locale: Option<&str>, country: Option<Market>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<Category>>

The manually paginated version of Self::categories.
source§

fn category_playlists<'a>( &'a self, category_id: &'a str, country: Option<Market> ) -> Paginator<'_, ClientResult<SimplifiedPlaylist>>

Get a list of playlists in a category in Spotify Read more
source§

fn category_playlists_manual( &self, category_id: &str, country: Option<Market>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<SimplifiedPlaylist>>

The manually paginated version of Self::category_playlists.
source§

fn featured_playlists( &self, locale: Option<&str>, country: Option<Market>, timestamp: Option<DateTime<Utc>>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<FeaturedPlaylists>

Get a list of Spotify featured playlists. Read more
source§

fn new_releases( &self, country: Option<Market> ) -> Paginator<'_, ClientResult<SimplifiedAlbum>>

Get a list of new album releases featured in Spotify. Read more
source§

fn new_releases_manual( &self, country: Option<Market>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<SimplifiedAlbum>>

The manually paginated version of Self::new_releases.
source§

fn recommendations<'a>( &self, attributes: impl IntoIterator<Item = RecommendationsAttribute> + Send + 'a, seed_artists: Option<impl IntoIterator<Item = ArtistId<'a>> + Send + 'a>, seed_genres: Option<impl IntoIterator<Item = &'a str> + Send + 'a>, seed_tracks: Option<impl IntoIterator<Item = TrackId<'a>> + Send + 'a>, market: Option<Market>, limit: Option<u32> ) -> ClientResult<Recommendations>

Get Recommendations Based on Seeds Read more
source§

fn playlist_items<'a>( &'a self, playlist_id: PlaylistId<'a>, fields: Option<&'a str>, market: Option<Market> ) -> Paginator<'_, ClientResult<PlaylistItem>>

Get full details of the items of a playlist owned by a user. Read more
source§

fn playlist_items_manual( &self, playlist_id: PlaylistId<'_>, fields: Option<&str>, market: Option<Market>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<PlaylistItem>>

The manually paginated version of Self::playlist_items.
source§

fn user_playlists<'a>( &'a self, user_id: UserId<'a> ) -> Paginator<'_, ClientResult<SimplifiedPlaylist>>

Gets playlists of a user. Read more
source§

fn user_playlists_manual( &self, user_id: UserId<'_>, limit: Option<u32>, offset: Option<u32> ) -> ClientResult<Page<SimplifiedPlaylist>>

The manually paginated version of Self::user_playlists.
source§

impl Clone for ClientCredsSpotify

source§

fn clone(&self) -> ClientCredsSpotify

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ClientCredsSpotify

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ClientCredsSpotify

source§

fn default() -> ClientCredsSpotify

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.