Struct spotify_rs::client::Client
source · pub struct Client<A: AuthenticationState, F: AuthFlow> {
pub auto_refresh: bool,
/* private fields */
}Expand description
The client which handles the authentcation and all the Spotify API requests.
Fields§
§auto_refresh: boolDictates whether or not the client will request a new token when the current one is about the expire.
It will check if the token has expired in every request.
Implementations§
source§impl<F: AuthFlow> Client<UnAuthenticated, F>
impl<F: AuthFlow> Client<UnAuthenticated, F>
sourcepub fn new(
auth_flow: F,
redirect_uri: RedirectUrl,
auto_refresh: bool
) -> Client<UnAuthenticated, F>
pub fn new( auth_flow: F, redirect_uri: RedirectUrl, auto_refresh: bool ) -> Client<UnAuthenticated, F>
Create a new unauthenticated, unauthorised client.
You have to choose one of the 3 authorisation flows and a redirect URI.
Authentication = “logging in” with the provided credentials; authorisation = getting permission from a user to make requests on their behalf. You cannot use an unauthenticated client, but you do have access to some methods for an unauthorised client.
source§impl<F: AuthFlow> Client<Token, F>
impl<F: AuthFlow> Client<Token, F>
sourcepub async fn from_refresh_token<I>(
auth_flow: F,
redirect_uri: RedirectUrl,
auto_refresh: bool,
scopes: I,
refresh_token: String
) -> Result<Client<Token, F>>where
I: IntoIterator,
I::Item: Into<Scope>,
pub async fn from_refresh_token<I>( auth_flow: F, redirect_uri: RedirectUrl, auto_refresh: bool, scopes: I, refresh_token: String ) -> Result<Client<Token, F>>where I: IntoIterator, I::Item: Into<Scope>,
Create a new authenticated and authorised client from a refresh token. It’s still required to specify an auth flow and redirect URI, as well as the scopes you want.
This method will fail if the refresh token is invalid or a new one cannot be obtained.
sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Get the current access token.
sourcepub fn refresh_token(&self) -> Option<&str>
pub fn refresh_token(&self) -> Option<&str>
Get the current refresh token. Some auth flows may not provide a refresh token,
in which case it’s None.
sourcepub async fn request_refresh_token(&mut self) -> Result<()>
pub async fn request_refresh_token(&mut self) -> Result<()>
Request a new refresh token that is automatically updated for the client. Only some auth flows allow for token refreshing.
pub fn album(&mut self, id: &str) -> Builder<'_, F, AlbumEndpoint>
pub fn albums<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, AlbumsEndpoint>
pub fn album_tracks( &mut self, album_id: &str ) -> Builder<'_, F, AlbumTracksEndpoint>
pub fn new_releases(&mut self) -> Builder<'_, F, NewReleasesEndpoint>
pub fn artist(&mut self, id: &str) -> Builder<'_, F, ArtistEndpoint>
pub async fn get_artists<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Vec<Artist>>
pub fn audiobook(&mut self, id: &str) -> Builder<'_, F, AudiobookEndpoint>
pub fn audiobooks<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, AudiobooksEndpoint>
pub fn audiobook_chapters( &mut self, audiobook_id: &str ) -> Builder<'_, F, AudiobookChaptersEndpoint>
pub fn browse_category( &mut self, id: &str ) -> Builder<'_, F, BrowseCategoryEndpoint>
pub fn browse_categories(&mut self) -> Builder<'_, F, BrowseCategoriesEndpoint>
sourcepub fn chapter(&mut self, id: &str) -> Builder<'_, F, ChapterEndpoint>
pub fn chapter(&mut self, id: &str) -> Builder<'_, F, ChapterEndpoint>
Note: Spotify’s API returns 500 Server error.
sourcepub fn chapters<T: AsRef<str>>(
&mut self,
ids: &[T]
) -> Builder<'_, F, ChaptersEndpoint>
pub fn chapters<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, ChaptersEndpoint>
Note: Spotify’s API returns 500 Server error.
pub fn episode(&mut self, id: &str) -> Builder<'_, F, EpisodeEndpoint>
pub fn episodes<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, EpisodesEndpoint>
pub async fn get_genre_seeds(&mut self) -> Result<Vec<String>>
pub async fn get_available_markets(&mut self) -> Result<Vec<String>>
pub fn playlist(&mut self, id: &str) -> Builder<'_, F, PlaylistEndpoint>
pub fn change_playlist_details( &mut self, id: &str ) -> Builder<'_, F, ChangePlaylistDetailsEndpoint>
pub fn playlist_items( &mut self, id: &str ) -> Builder<'_, F, PlaylistItemsEndpoint>
pub fn update_playlist_items( &mut self, id: &str, range_start: u32, insert_before: u32 ) -> Builder<'_, F, UpdatePlaylistItemsEndpoint>
pub fn add_items_to_playlist<T: ToString>( &mut self, id: &str, item_uris: &[T] ) -> Builder<'_, F, AddPlaylistItemsEndpoint>
pub fn remove_playlist_items<T: AsRef<str>>( &mut self, id: &str, item_uris: &[T] ) -> Builder<'_, F, RemovePlaylistItemsEndpoint>
pub fn user_playlists( &mut self, user_id: &str ) -> Builder<'_, F, UserPlaylistsEndpoint>
pub fn create_playlist( &mut self, user_id: &str, name: &str ) -> Builder<'_, F, CreatePlaylistEndpoint<'_>>
pub fn featured_playlists( &mut self ) -> Builder<'_, F, FeaturedPlaylistsEndpoint>
pub fn category_playlists( &mut self, category_id: &str ) -> Builder<'_, F, CategoryPlaylistsEndpoint>
pub async fn get_playlist_image(&mut self, id: &str) -> Result<Vec<Image>>
pub async fn add_playlist_image( &mut self, id: &str, image: &[u8] ) -> Result<Nil>
pub fn search( &mut self, query: &str, item_types: &[Item] ) -> Builder<'_, F, SearchEndpoint>
pub fn show(&mut self, id: &str) -> Builder<'_, F, ShowEndpoint>
pub fn shows<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, ShowsEndpoint>
pub fn show_episodes( &mut self, show_id: &str ) -> Builder<'_, F, ShowEpisodesEndpoint>
pub fn track(&mut self, id: &str) -> Builder<'_, F, TrackEndpoint>
pub fn tracks<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, TracksEndpoint>
pub async fn get_track_audio_features( &mut self, id: &str ) -> Result<AudioFeatures>
pub async fn get_tracks_audio_features<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Vec<AudioFeatures>>
pub async fn get_track_audio_analysis( &mut self, id: &str ) -> Result<AudioAnalysis>
pub fn recommendations<S: SeedType, T: AsRef<str>>( &mut self, seed: Seed<'_, T, S> ) -> Builder<'_, F, RecommendationsEndpoint<S>>
pub async fn get_user(&mut self, id: &str) -> Result<User>
pub async fn check_if_users_follow_playlist<T: AsRef<str>>( &mut self, playlist_id: &str, user_ids: &[T] ) -> Result<Vec<bool>>
source§impl<F: AuthFlow + Authorised> Client<Token, F>
impl<F: AuthFlow + Authorised> Client<Token, F>
pub fn saved_albums(&mut self) -> Builder<'_, F, SavedAlbumsEndpoint>
pub async fn save_albums<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>
pub async fn remove_saved_albums<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Nil>
pub async fn check_saved_albums<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Vec<bool>>
pub fn saved_audiobooks(&mut self) -> Builder<'_, F, SavedAudiobooksEndpoint>
pub async fn save_audiobooks<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>
pub async fn remove_saved_audiobooks<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Nil>
pub async fn check_saved_audiobooks<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Vec<bool>>
pub fn saved_episodes(&mut self) -> Builder<'_, F, SavedEpisodesEndpoint>
pub async fn save_episodes<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>
pub async fn remove_saved_episodes<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Nil>
pub async fn check_saved_episodes<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Vec<bool>>
pub fn current_user_playlists( &mut self ) -> Builder<'_, F, CurrentUserPlaylistsEndpoint>
pub fn saved_shows(&mut self) -> Builder<'_, F, SavedShowsEndpoint>
pub async fn save_shows<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>
pub async fn remove_saved_shows<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Nil>
pub async fn check_saved_shows<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Vec<bool>>
pub fn saved_tracks(&mut self) -> Builder<'_, F, SavedTracksEndpoint>
pub async fn save_tracks<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>
pub async fn remove_saved_tracks<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Nil>
pub async fn check_saved_tracks<T: AsRef<str>>( &mut self, ids: &[T] ) -> Result<Vec<bool>>
pub async fn get_current_user_profile(&mut self) -> Result<User>
pub fn current_user_top_items( &mut self, type: UserItemType ) -> Builder<'_, F, UserTopItemsEndpoint>
pub fn follow_playlist( &mut self, id: &str ) -> Builder<'_, F, FollowPlaylistBuilder>
pub async fn unfollow_playlist(&mut self, id: &str) -> Result<Nil>
pub fn followed_artists(&mut self) -> Builder<'_, F, FollowedArtistsBuilder>
pub fn follow_artists<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, FollowUserOrArtistEndpoint>
pub fn follow_users<T: AsRef<str>>( &mut self, ids: &[T] ) -> Builder<'_, F, FollowUserOrArtistEndpoint>
pub async fn get_playback_state( &mut self, market: Option<&str> ) -> Result<PlaybackState>
pub fn transfer_playback( &mut self, device_id: &str ) -> Builder<'_, F, TransferPlaybackEndpoint>
pub async fn get_available_devices(&mut self) -> Result<Vec<Device>>
pub async fn get_currently_playing_track( &mut self, market: Option<&str> ) -> Result<PlaybackState>
pub fn start_playback(&mut self) -> Builder<'_, F, StartPlaybackEndpoint>
pub async fn pause_playback(&mut self, device_id: Option<&str>) -> Result<Nil>
pub async fn skip_to_next(&mut self, device_id: Option<&str>) -> Result<Nil>
pub async fn skip_to_previous(&mut self, device_id: Option<&str>) -> Result<Nil>
pub fn seek_to_position( &mut self, position: u32 ) -> Builder<'_, F, SeekToPositionEndpoint>
sourcepub fn set_repeat_mode(
&mut self,
repeat_mode: RepeatMode
) -> Builder<'_, F, SetRepeatModeEndpoint>
pub fn set_repeat_mode( &mut self, repeat_mode: RepeatMode ) -> Builder<'_, F, SetRepeatModeEndpoint>
Note: This endpoint seems to be broken, returning 403 Forbidden “Player command failed: Restriction violated”
pub fn set_playback_volume( &mut self, volume: u32 ) -> Builder<'_, F, SetPlaybackVolumeEndpoint>
sourcepub fn toggle_playback_shuffle(
&mut self,
shuffle: bool
) -> Builder<'_, F, ToggleShuffleEndpoint>
pub fn toggle_playback_shuffle( &mut self, shuffle: bool ) -> Builder<'_, F, ToggleShuffleEndpoint>
Note: This endpoint seems to be broken, returning 403 Forbidden “Player command failed: Restriction violated”
pub fn recently_played_tracks( &mut self ) -> Builder<'_, F, RecentlyPlayedTracksEndpoint>
pub async fn get_user_queue(&mut self) -> Result<Queue>
pub fn add_item_to_queue( &mut self, uri: &str ) -> Builder<'_, F, AddItemToQueueEndpoint>
source§impl Client<UnAuthenticated, AuthCodeGrantPKCEFlow>
impl Client<UnAuthenticated, AuthCodeGrantPKCEFlow>
Get the authorisation URL and verification tokens, which are used internally to protect against CSRF attacks and the likes.
You must redirect the user to the received URL, which in turn redirects them to
the redirect URI you provided, along with a code and state parameter in the URl.
They are required for the next step in the auth process.
sourcepub async fn authenticate(
self,
auth: AuthorisationPKCE,
auth_code: &str,
csrf_state: &str
) -> Result<Client<Token, AuthCodeGrantPKCEFlow>>
pub async fn authenticate( self, auth: AuthorisationPKCE, auth_code: &str, csrf_state: &str ) -> Result<Client<Token, AuthCodeGrantPKCEFlow>>
This will exchange the auth_code for a token which will allow the client
to make requests.
csrf_state is used for CSRF protection.
source§impl Client<UnAuthenticated, AuthCodeGrantFlow>
impl Client<UnAuthenticated, AuthCodeGrantFlow>
Get the authorisation URL and verification tokens, which are used internally to protect against CSRF attacks and the likes.
You must redirect the user to the received URL, which in turn redirects them to
the redirect URI you provided, along with a code and state parameter in the URl.
They are required for the next step in the auth process.
sourcepub async fn authenticate(
self,
auth: Authorisation,
auth_code: &str,
csrf_state: &str
) -> Result<Client<Token, AuthCodeGrantFlow>>
pub async fn authenticate( self, auth: Authorisation, auth_code: &str, csrf_state: &str ) -> Result<Client<Token, AuthCodeGrantFlow>>
This will exchange the auth_code for a token which will allow the client
to make requests.
csrf_state is used for CSRF protection.
source§impl Client<UnAuthenticated, ClientCredsGrantFlow>
impl Client<UnAuthenticated, ClientCredsGrantFlow>
sourcepub async fn authenticate<I>(
self,
scopes: I
) -> Result<Client<Token, ClientCredsGrantFlow>>where
I: IntoIterator,
I::Item: Into<Scope>,
pub async fn authenticate<I>( self, scopes: I ) -> Result<Client<Token, ClientCredsGrantFlow>>where I: IntoIterator, I::Item: Into<Scope>,
This will exchange the client credentials for an access token used to make requests.
This authentication method doesn’t allow for token refreshing or to access user resources.