pub struct LastFmClient { /* private fields */ }Expand description
Main Last.fm API client
This is the entry point for interacting with the Last.fm API using the new v2.0 API.
§Example
use lastfm_client::LastFmClient;
use std::time::Duration;
// Create client with custom configuration
let client = LastFmClient::builder()
.api_key("your_api_key")
.timeout(Duration::from_secs(60))
.max_concurrent_requests(10)
.build()
.unwrap();
// Use client.recent_tracks() to fetch dataImplementations§
Source§impl LastFmClient
impl LastFmClient
Sourcepub fn builder() -> ConfigBuilder
pub fn builder() -> ConfigBuilder
Create a new configuration builder
This is the recommended way to create a LastFmClient.
§Example
use lastfm_client::LastFmClient;
let client = LastFmClient::builder()
.api_key("your_api_key")
.build()?;Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new LastFmClient with default configuration
This will automatically try to load the API key from the LAST_FM_API_KEY
environment variable. All other settings use sensible defaults.
§Example
use lastfm_client::LastFmClient;
let client = LastFmClient::new()?;§Errors
Returns an error if the API key is not set and cannot be loaded from environment
Sourcepub fn from_config(config: Config) -> Self
pub fn from_config(config: Config) -> Self
Create a new LastFmClient from a configuration
This automatically sets up retry logic and rate limiting based on the configuration.
Most users should use builder() instead.
Sourcepub fn with_http(config: Config, http: Arc<dyn HttpClient>) -> Self
pub fn with_http(config: Config, http: Arc<dyn HttpClient>) -> Self
Create a new LastFmClient with a custom HTTP client
This is primarily useful for testing with a mock HTTP client.
§Example
use lastfm_client::{LastFmClient, Config, ConfigBuilder};
use lastfm_client::client::MockClient;
use std::sync::Arc;
let config = ConfigBuilder::new()
.api_key("test_key")
.build()?;
let mock = MockClient::new();
let client = LastFmClient::with_http(config, Arc::new(mock));Sourcepub fn recent_tracks(
&self,
username: impl Into<String>,
) -> RecentTracksRequestBuilder
pub fn recent_tracks( &self, username: impl Into<String>, ) -> RecentTracksRequestBuilder
Get a builder for recent tracks requests
§Example
let tracks = client
.recent_tracks("username")
.limit(100)
.fetch()
.await?;Sourcepub fn loved_tracks(
&self,
username: impl Into<String>,
) -> LovedTracksRequestBuilder
pub fn loved_tracks( &self, username: impl Into<String>, ) -> LovedTracksRequestBuilder
Get a builder for loved tracks requests
§Example
let tracks = client
.loved_tracks("username")
.limit(100)
.fetch()
.await?;Sourcepub fn top_tracks(&self, username: impl Into<String>) -> TopTracksRequestBuilder
pub fn top_tracks(&self, username: impl Into<String>) -> TopTracksRequestBuilder
Get a builder for top tracks requests
§Example
let tracks = client
.top_tracks("username")
.limit(100)
.fetch()
.await?;Sourcepub fn top_artists(
&self,
username: impl Into<String>,
) -> TopArtistsRequestBuilder
pub fn top_artists( &self, username: impl Into<String>, ) -> TopArtistsRequestBuilder
Get a builder for top artists requests
§Example
let artists = client
.top_artists("username")
.limit(100)
.fetch()
.await?;Sourcepub fn top_albums(&self, username: impl Into<String>) -> TopAlbumsRequestBuilder
pub fn top_albums(&self, username: impl Into<String>) -> TopAlbumsRequestBuilder
Get a builder for top albums requests
§Example
let albums = client
.top_albums("username")
.limit(100)
.fetch()
.await?;Get a builder for top tags requests
§Example
let tags = client
.top_tags("username")
.limit(20)
.fetch()
.await?;Sourcepub fn weekly_chart_list(
&self,
username: impl Into<String>,
) -> WeeklyChartListRequestBuilder
pub fn weekly_chart_list( &self, username: impl Into<String>, ) -> WeeklyChartListRequestBuilder
Get a builder for user.getWeeklyChartList requests
§Example
let ranges = client.weekly_chart_list("username").fetch().await?;Sourcepub fn weekly_track_chart(
&self,
username: impl Into<String>,
) -> WeeklyTrackChartRequestBuilder
pub fn weekly_track_chart( &self, username: impl Into<String>, ) -> WeeklyTrackChartRequestBuilder
Get a builder for user.getWeeklyTrackChart requests
§Example
let ranges = client.weekly_chart_list("username").fetch().await?;
if let Some(range) = ranges.first() {
let tracks = client.weekly_track_chart("username").range(range).fetch().await?;
}Sourcepub fn weekly_artist_chart(
&self,
username: impl Into<String>,
) -> WeeklyArtistChartRequestBuilder
pub fn weekly_artist_chart( &self, username: impl Into<String>, ) -> WeeklyArtistChartRequestBuilder
Get a builder for user.getWeeklyArtistChart requests
Sourcepub fn weekly_album_chart(
&self,
username: impl Into<String>,
) -> WeeklyAlbumChartRequestBuilder
pub fn weekly_album_chart( &self, username: impl Into<String>, ) -> WeeklyAlbumChartRequestBuilder
Get a builder for user.getWeeklyAlbumChart requests
Sourcepub fn friends(&self, username: impl Into<String>) -> FriendsRequestBuilder
pub fn friends(&self, username: impl Into<String>) -> FriendsRequestBuilder
Get a builder for friends requests
§Example
let friends = client.friends("rj").fetch_all().await?;
for friend in &friends {
println!("{}", friend.name);
}Get a builder for personal tags requests
Returns tracks, artists, or albums that the user has tagged with the given tag.
§Example
let page = client.personal_tags("rj", "rock").fetch_tracks().await?;
for track in &page.tracks {
println!("{} - {}", track.artist_name, track.name);
}Sourcepub fn user_info(&self, username: impl Into<String>) -> UserInfoRequestBuilder
pub fn user_info(&self, username: impl Into<String>) -> UserInfoRequestBuilder
Get a builder for user profile requests
§Example
let info = client.user_info("rj").fetch().await?;
println!("{} has {} scrobbles", info.name, info.play_count);