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: bool

Dictates 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>

source

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>

source

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>

source

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>

source

pub fn access_token(&self) -> &str

Get the current access token.

source

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.

source

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.

source

pub fn album( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, AlbumEndpoint>

source

pub fn albums<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, AlbumsEndpoint>

source

pub fn album_tracks( &mut self, album_id: impl Into<String>, ) -> Builder<'_, F, V, AlbumTracksEndpoint>

source

pub fn new_releases(&mut self) -> Builder<'_, F, V, NewReleasesEndpoint>

source

pub fn artist( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, ArtistEndpoint>

source

pub async fn get_artists<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<Artist>>

source

pub fn audiobook( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, AudiobookEndpoint>

source

pub fn audiobooks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, AudiobooksEndpoint>

source

pub fn audiobook_chapters( &mut self, audiobook_id: impl Into<String>, ) -> Builder<'_, F, V, AudiobookChaptersEndpoint>

source

pub fn browse_category( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, BrowseCategoryEndpoint>

source

pub fn browse_categories( &mut self, ) -> Builder<'_, F, V, BrowseCategoriesEndpoint>

source

pub fn chapter( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, ChapterEndpoint>

Note: Spotify’s API returns 500 Server error.

source

pub fn chapters<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, ChaptersEndpoint>

Note: Spotify’s API returns 500 Server error.

source

pub fn episode( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, EpisodeEndpoint>

source

pub fn episodes<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, EpisodesEndpoint>

source

pub async fn get_genre_seeds(&mut self) -> Result<Vec<String>>

source

pub async fn get_available_markets(&mut self) -> Result<Vec<String>>

source

pub fn playlist( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, PlaylistEndpoint>

source

pub fn change_playlist_details( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, ChangePlaylistDetailsEndpoint>

source

pub fn playlist_items( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, PlaylistItemsEndpoint>

source

pub fn update_playlist_items( &mut self, id: impl Into<String>, range_start: u32, insert_before: u32, ) -> Builder<'_, F, V, UpdatePlaylistItemsEndpoint>

source

pub fn add_items_to_playlist<T: ToString>( &mut self, id: impl Into<String>, item_uris: &[T], ) -> Builder<'_, F, V, AddPlaylistItemsEndpoint>

source

pub fn remove_playlist_items<T: AsRef<str>>( &mut self, id: impl Into<String>, item_uris: &[T], ) -> Builder<'_, F, V, RemovePlaylistItemsEndpoint>

source

pub fn user_playlists( &mut self, user_id: impl Into<String>, ) -> Builder<'_, F, V, UserPlaylistsEndpoint>

source

pub fn create_playlist( &mut self, user_id: impl Into<String>, name: impl Into<String>, ) -> Builder<'_, F, V, CreatePlaylistEndpoint<'_>>

source

pub fn featured_playlists( &mut self, ) -> Builder<'_, F, V, FeaturedPlaylistsEndpoint>

source

pub fn category_playlists( &mut self, category_id: impl Into<String>, ) -> Builder<'_, F, V, CategoryPlaylistsEndpoint>

source

pub async fn get_playlist_image( &mut self, id: impl Into<String>, ) -> Result<Vec<Image>>

source

pub async fn add_playlist_image( &mut self, id: impl Into<String>, image: &[u8], ) -> Result<Nil>

source

pub fn search( &mut self, query: impl Into<String>, item_types: &[Item], ) -> Builder<'_, F, V, SearchEndpoint>

source

pub fn show(&mut self, id: impl Into<String>) -> Builder<'_, F, V, ShowEndpoint>

source

pub fn shows<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, ShowsEndpoint>

source

pub fn show_episodes( &mut self, show_id: impl Into<String>, ) -> Builder<'_, F, V, ShowEpisodesEndpoint>

source

pub fn track( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, TrackEndpoint>

source

pub fn tracks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, TracksEndpoint>

source

pub async fn get_track_audio_features( &mut self, id: impl Into<String>, ) -> Result<AudioFeatures>

source

pub async fn get_tracks_audio_features<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<AudioFeatures>>

source

pub async fn get_track_audio_analysis( &mut self, id: impl Into<String>, ) -> Result<AudioAnalysis>

source

pub fn recommendations<S: SeedType, T: AsRef<str>>( &mut self, seed: Seed<'_, T, S>, ) -> Builder<'_, F, V, RecommendationsEndpoint<S>>

source

pub async fn get_user(&mut self, id: impl Into<String>) -> Result<User>

source

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>

source

pub fn saved_albums(&mut self) -> Builder<'_, F, V, SavedAlbumsEndpoint>

source

pub async fn save_albums<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>

source

pub async fn remove_saved_albums<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Nil>

source

pub async fn check_saved_albums<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<bool>>

source

pub fn saved_audiobooks(&mut self) -> Builder<'_, F, V, SavedAudiobooksEndpoint>

source

pub async fn save_audiobooks<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>

source

pub async fn remove_saved_audiobooks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Nil>

source

pub async fn check_saved_audiobooks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<bool>>

source

pub fn saved_episodes(&mut self) -> Builder<'_, F, V, SavedEpisodesEndpoint>

source

pub async fn save_episodes<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>

source

pub async fn remove_saved_episodes<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Nil>

source

pub async fn check_saved_episodes<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<bool>>

source

pub fn current_user_playlists( &mut self, ) -> Builder<'_, F, V, CurrentUserPlaylistsEndpoint>

source

pub fn saved_shows(&mut self) -> Builder<'_, F, V, SavedShowsEndpoint>

source

pub async fn save_shows<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>

source

pub async fn remove_saved_shows<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Nil>

source

pub async fn check_saved_shows<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<bool>>

source

pub fn saved_tracks(&mut self) -> Builder<'_, F, V, SavedTracksEndpoint>

source

pub async fn save_tracks<T: AsRef<str>>(&mut self, ids: &[T]) -> Result<Nil>

source

pub async fn remove_saved_tracks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Nil>

source

pub async fn check_saved_tracks<T: AsRef<str>>( &mut self, ids: &[T], ) -> Result<Vec<bool>>

source

pub async fn get_current_user_profile(&mut self) -> Result<User>

source

pub fn current_user_top_items( &mut self, type: UserItemType, ) -> Builder<'_, F, V, UserTopItemsEndpoint>

source

pub fn follow_playlist( &mut self, id: impl Into<String>, ) -> Builder<'_, F, V, FollowPlaylistBuilder>

source

pub async fn unfollow_playlist(&mut self, id: impl Into<String>) -> Result<Nil>

source

pub fn followed_artists(&mut self) -> Builder<'_, F, V, FollowedArtistsBuilder>

source

pub fn follow_artists<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, FollowUserOrArtistEndpoint>

source

pub fn follow_users<T: AsRef<str>>( &mut self, ids: &[T], ) -> Builder<'_, F, V, FollowUserOrArtistEndpoint>

source

pub async fn get_playback_state( &mut self, market: Option<&str>, ) -> Result<PlaybackState>

source

pub fn transfer_playback( &mut self, device_id: impl Into<String>, ) -> Builder<'_, F, V, TransferPlaybackEndpoint>

source

pub async fn get_available_devices(&mut self) -> Result<Vec<Device>>

source

pub async fn get_currently_playing_track( &mut self, market: Option<&str>, ) -> Result<PlaybackState>

source

pub fn start_playback(&mut self) -> Builder<'_, F, V, StartPlaybackEndpoint>

source

pub async fn pause_playback(&mut self, device_id: Option<&str>) -> Result<Nil>

source

pub async fn skip_to_next(&mut self, device_id: Option<&str>) -> Result<Nil>

source

pub async fn skip_to_previous(&mut self, device_id: Option<&str>) -> Result<Nil>

source

pub fn seek_to_position( &mut self, position: u32, ) -> Builder<'_, F, V, SeekToPositionEndpoint>

source

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”

source

pub fn set_playback_volume( &mut self, volume: u32, ) -> Builder<'_, F, V, SetPlaybackVolumeEndpoint>

source

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”

source

pub fn recently_played_tracks( &mut self, ) -> Builder<'_, F, V, RecentlyPlayedTracksEndpoint>

source

pub async fn get_user_queue(&mut self) -> Result<Queue>

source

pub fn add_item_to_queue( &mut self, uri: impl Into<String>, ) -> Builder<'_, F, V, AddItemToQueueEndpoint>

source§

impl Client<UnAuthenticated, AuthCodeFlow, CsrfVerifier>

source

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>

source

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>

source

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.

Trait Implementations§

source§

impl<A: Debug + AuthenticationState, F: Debug + AuthFlow, V: Debug + Verifier> Debug for Client<A, F, V>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A, F, V> Freeze for Client<A, F, V>
where A: Freeze, V: Freeze,

§

impl<A, F, V> !RefUnwindSafe for Client<A, F, V>

§

impl<A, F, V> Send for Client<A, F, V>
where A: Send, V: Send, F: Send,

§

impl<A, F, V> Sync for Client<A, F, V>
where A: Sync, V: Sync, F: Sync,

§

impl<A, F, V> Unpin for Client<A, F, V>
where A: Unpin, V: Unpin, F: Unpin,

§

impl<A, F, V> !UnwindSafe for Client<A, F, V>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more