Struct spotify_rs::client::Client
source · pub struct Client<A: AuthenticationState, F: AuthFlow, V: Verifier> {
pub auto_refresh: bool,
/* private fields */
}Expand description
The client which handles the authentication and all the Spotify API requests.
It is recommended to use one of the following: AuthCodeClient, AuthCodePkceClient or ClientCredsClient,
depending on the chosen auth flow.
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 Client<UnAuthenticated, AuthCodeFlow, CsrfVerifier>
impl Client<UnAuthenticated, AuthCodeFlow, CsrfVerifier>
sourcepub fn new(
_: AuthCodeFlow,
redirect_uri: RedirectUrl,
auto_refresh: bool,
) -> (Self, Url)
pub fn new( _: AuthCodeFlow, redirect_uri: RedirectUrl, auto_refresh: bool, ) -> (Self, Url)
Create a new client and generate an authorisation URL
You must redirect the user to the returned 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.
source§impl Client<UnAuthenticated, AuthCodePkceFlow, PkceVerifier>
impl Client<UnAuthenticated, AuthCodePkceFlow, PkceVerifier>
sourcepub fn new(
_: AuthCodePkceFlow,
redirect_uri: RedirectUrl,
auto_refresh: bool,
) -> (Self, Url)
pub fn new( _: AuthCodePkceFlow, redirect_uri: RedirectUrl, auto_refresh: bool, ) -> (Self, Url)
Create a new client and generate an authorisation URL
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.
source§impl<F: AuthFlow> Client<Token, F, NoVerifier>
impl<F: AuthFlow> Client<Token, F, NoVerifier>
sourcepub async fn from_refresh_token(
auth_flow: F,
auto_refresh: bool,
refresh_token: String,
) -> Result<Client<Token, F, NoVerifier>>
pub async fn from_refresh_token( auth_flow: F, auto_refresh: bool, refresh_token: String, ) -> Result<Client<Token, F, NoVerifier>>
Create a new authenticated and authorised client from a refresh token. It’s still required to specify an auth flow.
This method will fail if the refresh token is invalid or a new one cannot be obtained.
source§impl<F: AuthFlow, V: Verifier> Client<Token, F, V>
impl<F: AuthFlow, V: Verifier> Client<Token, F, V>
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 and updates it in the client. Only some auth flows allow for token refreshing.
pub fn album( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, AlbumEndpoint>
pub fn albums<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, AlbumsEndpoint>
pub fn album_tracks( &mut self, album_id: impl Into<String>, ) -> Builder<'_, F, V, AlbumTracksEndpoint>
pub fn new_releases(&mut self) -> Builder<'_, F, V, NewReleasesEndpoint>
pub fn artist( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, ArtistEndpoint>
pub async fn get_artists<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<Artist>>
pub fn audiobook( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, AudiobookEndpoint>
pub fn audiobooks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, AudiobooksEndpoint>
pub fn audiobook_chapters( &mut self, audiobook_id: impl Into<String>, ) -> Builder<'_, F, V, AudiobookChaptersEndpoint>
pub fn browse_category( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, BrowseCategoryEndpoint>
pub fn browse_categories( &mut self, ) -> Builder<'_, F, V, BrowseCategoriesEndpoint>
sourcepub fn chapter(
&mut self,
id: impl Into<String>,
) -> Builder<'_, F, V, ChapterEndpoint>
pub fn chapter( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, ChapterEndpoint>
Note: Spotify’s API returns 500 Server error.
sourcepub fn chapters<T: AsRef<str>>(
&mut self,
ids: &[T],
) -> Builder<'_, F, V, ChaptersEndpoint>
pub fn chapters<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, ChaptersEndpoint>
Note: Spotify’s API returns 500 Server error.
pub fn episode( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, EpisodeEndpoint>
pub fn episodes<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, 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: impl Into<String>, ) -> Builder<'_, F, V, PlaylistEndpoint>
pub fn change_playlist_details( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, ChangePlaylistDetailsEndpoint>
pub fn playlist_items( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, PlaylistItemsEndpoint>
pub fn update_playlist_items( &mut self, id: impl Into<String>, range_start: u32, insert_before: u32, ) -> Builder<'_, F, V, UpdatePlaylistItemsEndpoint>
pub fn add_items_to_playlist<T: ToString>( &mut self, id: impl Into<String>, item_uris: &[T], ) -> Builder<'_, F, V, AddPlaylistItemsEndpoint>
pub fn remove_playlist_items<T: AsRef<str>>( &mut self, id: impl Into<String>, item_uris: &[T], ) -> Builder<'_, F, V, RemovePlaylistItemsEndpoint>
pub fn user_playlists( &mut self, user_id: impl Into<String>, ) -> Builder<'_, F, V, UserPlaylistsEndpoint>
pub fn create_playlist( &mut self, user_id: impl Into<String>, name: impl Into<String>, ) -> Builder<'_, F, V, CreatePlaylistEndpoint<'_>>
pub fn featured_playlists( &mut self, ) -> Builder<'_, F, V, FeaturedPlaylistsEndpoint>
pub fn category_playlists( &mut self, category_id: impl Into<String>, ) -> Builder<'_, F, V, CategoryPlaylistsEndpoint>
pub async fn get_playlist_image( &mut self, id: impl Into<String>, ) -> Result<Vec<Image>>
pub async fn add_playlist_image( &mut self, id: impl Into<String>, image: &[u8], ) -> Result<Nil>
pub fn search( &mut self, query: impl Into<String>, item_types: &[Item], ) -> Builder<'_, F, V, SearchEndpoint>
pub fn show(&mut self, id: impl Into<String>) -> Builder<'_, F, V, ShowEndpoint>
pub fn shows<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, ShowsEndpoint>
pub fn show_episodes( &mut self, show_id: impl Into<String>, ) -> Builder<'_, F, V, ShowEpisodesEndpoint>
pub fn track( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, TrackEndpoint>
pub fn tracks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, TracksEndpoint>
pub async fn get_track_audio_features( &mut self, id: impl Into<String>, ) -> 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: impl Into<String>, ) -> Result<AudioAnalysis>
pub fn recommendations<S: SeedType, T: AsRef<str>>( &mut self, seed: Seed<'_, T, S>, ) -> Builder<'_, F, V, RecommendationsEndpoint<S>>
pub async fn get_user(&mut self, id: impl Into<String>) -> Result<User>
pub async fn check_if_users_follow_playlist<T: AsRef<str>>( &mut self, playlist_id: impl Into<String>, user_ids: &[T], ) -> Result<Vec<bool>>
source§impl<F: AuthFlow + Authorised, V: Verifier> Client<Token, F, V>
impl<F: AuthFlow + Authorised, V: Verifier> Client<Token, F, V>
pub fn saved_albums(&mut self) -> Builder<'_, F, V, 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, V, 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, V, 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, V, CurrentUserPlaylistsEndpoint>
pub fn saved_shows(&mut self) -> Builder<'_, F, V, 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, V, 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, V, UserTopItemsEndpoint>
pub fn follow_playlist( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, FollowPlaylistBuilder>
pub async fn unfollow_playlist(&mut self, id: impl Into<String>) -> Result<Nil>
pub fn followed_artists(&mut self) -> Builder<'_, F, V, FollowedArtistsBuilder>
pub fn follow_artists<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, FollowUserOrArtistEndpoint>
pub fn follow_users<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, FollowUserOrArtistEndpoint>
pub async fn get_playback_state( &mut self, market: Option<&str>, ) -> Result<PlaybackState>
pub fn transfer_playback( &mut self, device_id: impl Into<String>, ) -> Builder<'_, F, V, 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, V, 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, V, SeekToPositionEndpoint>
sourcepub fn set_repeat_mode(
&mut self,
repeat_mode: RepeatMode,
) -> Builder<'_, F, V, SetRepeatModeEndpoint>
pub fn set_repeat_mode( &mut self, repeat_mode: RepeatMode, ) -> Builder<'_, F, V, 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, V, SetPlaybackVolumeEndpoint>
sourcepub fn toggle_playback_shuffle(
&mut self,
shuffle: bool,
) -> Builder<'_, F, V, ToggleShuffleEndpoint>
pub fn toggle_playback_shuffle( &mut self, shuffle: bool, ) -> Builder<'_, F, V, 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, V, RecentlyPlayedTracksEndpoint>
pub async fn get_user_queue(&mut self) -> Result<Queue>
pub fn add_item_to_queue( &mut self, uri: impl Into<String>, ) -> Builder<'_, F, V, AddItemToQueueEndpoint>
source§impl Client<UnAuthenticated, AuthCodeFlow, CsrfVerifier>
impl Client<UnAuthenticated, AuthCodeFlow, CsrfVerifier>
sourcepub async fn authenticate(
self,
auth_code: impl Into<String>,
csrf_state: impl AsRef<str>,
) -> Result<Client<Token, AuthCodeFlow, NoVerifier>>
pub async fn authenticate( self, auth_code: impl Into<String>, csrf_state: impl AsRef<str>, ) -> Result<Client<Token, AuthCodeFlow, NoVerifier>>
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, AuthCodePkceFlow, PkceVerifier>
impl Client<UnAuthenticated, AuthCodePkceFlow, PkceVerifier>
sourcepub async fn authenticate(
self,
auth_code: impl Into<String>,
csrf_state: impl AsRef<str>,
) -> Result<Client<Token, AuthCodePkceFlow, NoVerifier>>
pub async fn authenticate( self, auth_code: impl Into<String>, csrf_state: impl AsRef<str>, ) -> Result<Client<Token, AuthCodePkceFlow, NoVerifier>>
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, ClientCredsFlow, NoVerifier>
impl Client<UnAuthenticated, ClientCredsFlow, NoVerifier>
sourcepub async fn authenticate(
__arg0: ClientCredsFlow,
) -> Result<Client<Token, ClientCredsFlow, NoVerifier>>
pub async fn authenticate( __arg0: ClientCredsFlow, ) -> Result<Client<Token, ClientCredsFlow, NoVerifier>>
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.