Lastfm

Struct Lastfm 

Source
pub struct Lastfm { /* private fields */ }

Implementations§

Source§

impl Lastfm

Source

pub fn builder() -> LastfmBuilder

Examples found in repository?
examples/auth_get_token.rs (line 11)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm.auth().get_token().send().await?;
17
18    let token = match response {
19        APIResponse::Success(value) => value.token,
20        APIResponse::Error(err) => {
21            format!("Error: {} - {}", err.error, err.message)
22        }
23    };
24    println!("Token: {}", token);
25
26    Ok(())
27}
More examples
Hide additional examples
examples/album_search.rs (line 11)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .search()
19        .album("HIT ME HARD AND SOFT")
20        .limit(30)
21        .page(1)
22        .send()
23        .await?;
24
25    match response {
26        APIResponse::Success(value) => {
27            println!("{}", value);
28        }
29        APIResponse::Error(err) => {
30            println!("Error: {} - {}", err.error, err.message);
31        }
32    }
33
34    Ok(())
35}
examples/album_get_top_tags.rs (line 11)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .get_top_tags()
19        .artist("Billie Eilish")
20        .album("HIT ME HARD AND SOFT")
21        .autocorrect(true)
22        .send()
23        .await?;
24
25    match response {
26        APIResponse::Success(value) => {
27            println!("{:?}", value);
28        }
29        APIResponse::Error(err) => {
30            println!("Error: {} - {}", err.error, err.message);
31        }
32    }
33
34    Ok(())
35}
examples/album_get_info.rs (line 11)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .get_info()
19        .artist("Billie Eilish")
20        .album("HIT ME HARD AND SOFT")
21        .username("uppercase_")
22        .autocorrect(true)
23        .send()
24        .await?;
25
26    match response {
27        APIResponse::Success(value) => {
28            println!("{:?}", value.album);
29        }
30        APIResponse::Error(err) => {
31            println!("Error: {} - {}", err.error, err.message);
32        }
33    }
34
35    Ok(())
36}
examples/album_get_tags.rs (line 11)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .get_tags()
19        .artist("Billie Eilish")
20        .album("HIT ME HARD AND SOFT")
21        .user("uppercase_")
22        .autocorrect(true)
23        .send()
24        .await?;
25
26    match response {
27        APIResponse::Success(value) => {
28            println!("{}", serde_json::json!(value));
29        }
30        APIResponse::Error(err) => {
31            println!("Error: {} - {}", err.error, err.message);
32        }
33    }
34
35    Ok(())
36}
examples/auth_get_session.rs (line 11)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    // Request token
17    let response = lastfm.auth().get_token().send().await?;
18
19    let token = match response {
20        APIResponse::Success(value) => value.token,
21        APIResponse::Error(err) => {
22            return Err(Box::new(err) as Box<dyn Error>);
23        }
24    };
25
26    println!("Token: {}", token);
27
28    // Authorize the token
29    lastfm.auth().pls_authorize(token.to_string());
30
31    // Get session key
32    let response = lastfm.auth().get_session().token(&token).send().await?;
33
34    println!("Session: {}", response);
35
36    Ok(())
37}
Source

pub fn get_client(&self) -> &ReqwestClient

Source

pub fn get_api_key(&self) -> String

Source

pub fn get_api_secret(&self) -> String

Source

pub fn get_base_url(&self) -> &String

Source

pub fn get_sk(&self) -> String

Source

pub fn set_sk(&mut self, sk: String) -> &mut Self

Source

pub fn sign_api(&self, params: &mut HashMap<String, String>) -> String

Source

pub async fn send_request<T>( &self, method: LastfmMethod, params: &mut HashMap<String, String>, http_method: Method, ) -> Result<APIResponse<T>>
where T: for<'de> Deserialize<'de>,

Source

pub fn album(&self) -> Album<'_>

Creates a new Album instance for interacting with album-related methods.

Examples found in repository?
examples/album_search.rs (line 17)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .search()
19        .album("HIT ME HARD AND SOFT")
20        .limit(30)
21        .page(1)
22        .send()
23        .await?;
24
25    match response {
26        APIResponse::Success(value) => {
27            println!("{}", value);
28        }
29        APIResponse::Error(err) => {
30            println!("Error: {} - {}", err.error, err.message);
31        }
32    }
33
34    Ok(())
35}
More examples
Hide additional examples
examples/album_get_top_tags.rs (line 17)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .get_top_tags()
19        .artist("Billie Eilish")
20        .album("HIT ME HARD AND SOFT")
21        .autocorrect(true)
22        .send()
23        .await?;
24
25    match response {
26        APIResponse::Success(value) => {
27            println!("{:?}", value);
28        }
29        APIResponse::Error(err) => {
30            println!("Error: {} - {}", err.error, err.message);
31        }
32    }
33
34    Ok(())
35}
examples/album_get_info.rs (line 17)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .get_info()
19        .artist("Billie Eilish")
20        .album("HIT ME HARD AND SOFT")
21        .username("uppercase_")
22        .autocorrect(true)
23        .send()
24        .await?;
25
26    match response {
27        APIResponse::Success(value) => {
28            println!("{:?}", value.album);
29        }
30        APIResponse::Error(err) => {
31            println!("Error: {} - {}", err.error, err.message);
32        }
33    }
34
35    Ok(())
36}
examples/album_get_tags.rs (line 17)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm
17        .album()
18        .get_tags()
19        .artist("Billie Eilish")
20        .album("HIT ME HARD AND SOFT")
21        .user("uppercase_")
22        .autocorrect(true)
23        .send()
24        .await?;
25
26    match response {
27        APIResponse::Success(value) => {
28            println!("{}", serde_json::json!(value));
29        }
30        APIResponse::Error(err) => {
31            println!("Error: {} - {}", err.error, err.message);
32        }
33    }
34
35    Ok(())
36}
examples/album_add_tags.rs (line 22)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10    let sk = std::env::var("SK").expect("SK env variable is required");
11
12    let lastfm = Lastfm::builder()
13        .api_key(api_key)
14        .api_secret(api_secret)
15        .session_key(sk)
16        .build()?;
17
18    lastfm.auth();
19    // lastfm.set_sk(sk);
20
21    let response = lastfm
22        .album()
23        .add_tags()
24        .artist("Billie Eilish")
25        .album("HIT ME HARD AND SOFT")
26        .tags("aoty")
27        .send()
28        .await?;
29
30    match response {
31        APIResponse::Success(value) => {
32            println!("{}", value);
33        }
34        APIResponse::Error(err) => {
35            println!("Error: {} - {}", err.error, err.message);
36        }
37    }
38
39    Ok(())
40}
examples/album_remove_tags.rs (line 22)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10    let sk = std::env::var("SK").expect("SK env variable is required");
11
12    let lastfm = Lastfm::builder()
13        .api_key(api_key)
14        .api_secret(api_secret)
15        .session_key(sk)
16        .build()?;
17
18    let _sk = lastfm.auth();
19    // lastfm.set_sk(sk);
20
21    let response = lastfm
22        .album()
23        .remove_tag()
24        .artist("Billie Eilish")
25        .album("HIT ME HARD AND SOFT")
26        .tag("aoty")
27        .send()
28        .await?;
29
30    match response {
31        APIResponse::Success(value) => {
32            println!("{}", value);
33        }
34        APIResponse::Error(err) => {
35            println!("Error: {} - {}", err.error, err.message);
36        }
37    }
38
39    Ok(())
40}
Source

pub fn artist(&self) -> Artist<'_>

Creates a new Artist instance for interacting with artist-related methods.

Source

pub fn auth(&self) -> Auth<'_>

Creates a new Auth instance for interacting with auth-related methods.

Examples found in repository?
examples/auth_get_token.rs (line 16)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    let response = lastfm.auth().get_token().send().await?;
17
18    let token = match response {
19        APIResponse::Success(value) => value.token,
20        APIResponse::Error(err) => {
21            format!("Error: {} - {}", err.error, err.message)
22        }
23    };
24    println!("Token: {}", token);
25
26    Ok(())
27}
More examples
Hide additional examples
examples/auth_get_session.rs (line 17)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10
11    let lastfm = Lastfm::builder()
12        .api_key(api_key)
13        .api_secret(api_secret)
14        .build()?;
15
16    // Request token
17    let response = lastfm.auth().get_token().send().await?;
18
19    let token = match response {
20        APIResponse::Success(value) => value.token,
21        APIResponse::Error(err) => {
22            return Err(Box::new(err) as Box<dyn Error>);
23        }
24    };
25
26    println!("Token: {}", token);
27
28    // Authorize the token
29    lastfm.auth().pls_authorize(token.to_string());
30
31    // Get session key
32    let response = lastfm.auth().get_session().token(&token).send().await?;
33
34    println!("Session: {}", response);
35
36    Ok(())
37}
examples/album_add_tags.rs (line 18)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10    let sk = std::env::var("SK").expect("SK env variable is required");
11
12    let lastfm = Lastfm::builder()
13        .api_key(api_key)
14        .api_secret(api_secret)
15        .session_key(sk)
16        .build()?;
17
18    lastfm.auth();
19    // lastfm.set_sk(sk);
20
21    let response = lastfm
22        .album()
23        .add_tags()
24        .artist("Billie Eilish")
25        .album("HIT ME HARD AND SOFT")
26        .tags("aoty")
27        .send()
28        .await?;
29
30    match response {
31        APIResponse::Success(value) => {
32            println!("{}", value);
33        }
34        APIResponse::Error(err) => {
35            println!("Error: {} - {}", err.error, err.message);
36        }
37    }
38
39    Ok(())
40}
examples/album_remove_tags.rs (line 18)
6async fn main() -> Result<(), Box<dyn Error>> {
7    dotenv().ok();
8    let api_key = std::env::var("API_KEY").expect("API_KEY env variable is required");
9    let api_secret = std::env::var("API_SECRET").expect("API_SECRET env variable is required");
10    let sk = std::env::var("SK").expect("SK env variable is required");
11
12    let lastfm = Lastfm::builder()
13        .api_key(api_key)
14        .api_secret(api_secret)
15        .session_key(sk)
16        .build()?;
17
18    let _sk = lastfm.auth();
19    // lastfm.set_sk(sk);
20
21    let response = lastfm
22        .album()
23        .remove_tag()
24        .artist("Billie Eilish")
25        .album("HIT ME HARD AND SOFT")
26        .tag("aoty")
27        .send()
28        .await?;
29
30    match response {
31        APIResponse::Success(value) => {
32            println!("{}", value);
33        }
34        APIResponse::Error(err) => {
35            println!("Error: {} - {}", err.error, err.message);
36        }
37    }
38
39    Ok(())
40}
Source

pub fn chart(&self) -> Chart<'_>

Creates a new Chart instance for interacting with chart-related methods.

Source

pub fn geo(&self) -> Geo<'_>

Creates a new Geo instance for interacting with geo-related methods.

Source

pub fn library(&self) -> Library<'_>

Creates a new Library instance for interacting with library-related methods.

Source

pub fn tag(&self) -> Tag<'_>

Creates a new Tag instance for interacting with tag-related methods.

Source

pub fn track(&self) -> Track<'_>

Creates a new Track instance for interacting with track-related methods.

Source

pub fn user(&self) -> User<'_>

Creates a new User instance for interacting with user-related methods.

Trait Implementations§

Source§

impl Clone for Lastfm

Source§

fn clone(&self) -> Lastfm

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Lastfm

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Lastfm

Source§

fn default() -> Lastfm

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Lastfm

§

impl !RefUnwindSafe for Lastfm

§

impl Send for Lastfm

§

impl Sync for Lastfm

§

impl Unpin for Lastfm

§

impl !UnwindSafe for Lastfm

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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<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
Source§

impl<T> ErasedDestructor for T
where T: 'static,