pub struct Client<A: AsRef<str>, U: AsRef<str>> { /* private fields */ }Expand description
A client for the Last.fm API.
Implementations§
Source§impl<A: AsRef<str>, U: AsRef<str>> Client<A, U>
impl<A: AsRef<str>, U: AsRef<str>> Client<A, U>
Sourcepub fn builder() -> ClientBuilder<A, U, ((), (), (), (), ())>
pub fn builder() -> ClientBuilder<A, U, ((), (), (), (), ())>
Create a builder for building Client.
On the builder, call .api_key(...), .username(...), .reqwest_client(...)(optional), .base_url(...)(optional), .retry_strategy(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of Client.
Source§impl<A: AsRef<str>, U: AsRef<str>> Client<A, U>
impl<A: AsRef<str>, U: AsRef<str>> Client<A, U>
Sourcepub fn from_env(username: U) -> Client<String, U>
pub fn from_env(username: U) -> Client<String, U>
Creates a new Client with the given username.
The API key is read from the LASTFM_API_KEY environment variable.
This method is a shortcut for [ClientBuilder::from_env] but, in case of failure, it will panic rather than returning an error.
§Panics
If the environment variable is not set, this function will panic.
Sourcepub fn try_from_env(username: U) -> Result<Client<String, U>, VarError>
pub fn try_from_env(username: U) -> Result<Client<String, U>, VarError>
Creates a new Client with the given username.
The API key is read from the LASTFM_API_KEY environment variable.
If the environment variable is not set, this function will return an error.
Sourcepub async fn now_playing(&self) -> Result<Option<NowPlayingTrack>, Error>
pub async fn now_playing(&self) -> Result<Option<NowPlayingTrack>, Error>
Fetches the currently playing track for the user (if any)
Sourcepub async fn all_tracks(self) -> Result<RecentTracksFetcher, Error>
pub async fn all_tracks(self) -> Result<RecentTracksFetcher, Error>
Creates a new RecentTracksFetcher that can be used to fetch all of the user’s recent tracks.
Sourcepub async fn recent_tracks(
self,
from: Option<i64>,
to: Option<i64>,
) -> Result<RecentTracksFetcher, Error>
pub async fn recent_tracks( self, from: Option<i64>, to: Option<i64>, ) -> Result<RecentTracksFetcher, Error>
Creates a new RecentTracksFetcher that can be used to fetch the user’s recent tracks in a given time range.
The from and to parameters are Unix timestamps (in seconds).