Class: LastFM::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/lastfm/library.rb

Class Method Summary collapse

Class Method Details

.add_album(params) ⇒ Object

Add an album or collection of albums to a user’s Last.fm library.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artists (Array, required)

    the artist or collection of artists to add

  • :albums (Array, required)

    the album or collection of albums to add. the indices of the albums that you pass MUST correspond to those of the artists

See Also:



10
11
12
13
14
15
16
# File 'lib/lastfm/library.rb', line 10

def add_album( params )
  LastFM.requires_authentication
  # convert :artists and :albums to individual artist[i] and album[i]
  Array(params.delete(:artists)).each_with_index{|val, i| params["artist[#{i}]"] = val}
  Array(params.delete(:albums)).each_with_index{|val, i| params["album[#{i}]"] = val}
  LastFM.post( "library.addAlbum", params )
end

.add_artist(params) ⇒ Object

Add an artist or collection of artists to a user’s Last.fm library.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artists (Array, required)

    the artist or collection of artists to add

See Also:



22
23
24
25
26
# File 'lib/lastfm/library.rb', line 22

def add_artist( params )
  LastFM.requires_authentication
  Array(params.delete(:artists)).each_with_index{|val, i| params["artist[#{i}]"] = val}
  LastFM.post( "library.addArtist", params )
end

.add_track(params) ⇒ Object

Add a track or collection of tracks to a user’s Last.fm library.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artists (Array, required)

    the artist or collection of artists to add

  • :tracks (Array, required)

    the track or collection of tracks to add. the indices of the tracks that you pass MUST correspond to those of the artists

See Also:



33
34
35
36
37
38
# File 'lib/lastfm/library.rb', line 33

def add_track( params )
  LastFM.requires_authentication
  Array(params.delete(:artists)).each_with_index{|val, i| params["artist[#{i}]"] = val}
  Array(params.delete(:tracks)).each_with_index{|val, i| params["track[#{i}]"] = val}
  LastFM.post( "library.addTrack", params )
end

.get_albums(params) ⇒ Object

A paginated list of all the albums in a user’s library, with play counts and tag counts.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :user (String, requried)

    the user whose library you want to fetch

  • :artist (String, optional)

    an artist by which to filter albums

  • :page (Fixnum, optional)

    the page number to fetch. defaults to first page

  • :limit (Fixnum, optional)

    the number of results to fetch per page. defaults to 50

See Also:



47
48
49
# File 'lib/lastfm/library.rb', line 47

def get_albums( params )
  LastFM.get( "library.getAlbums", params )
end

.get_artists(params) ⇒ Object

A paginated list of all the artists in a user’s library, with play counts and tag counts.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :user (String, requried)

    the user whose library you want to fetch

  • :page (Fixnum, optional)

    the page number to fetch. defaults to first page

  • :limit (Fixnum, optional)

    the number of results to fetch per page. defaults to 50

See Also:



57
58
59
# File 'lib/lastfm/library.rb', line 57

def get_artists( params )
   LastFM.get( "library.getArtists", params )
end

.get_tracks(params) ⇒ Object

A paginated list of all the tracks in a user’s library, with play counts and tag counts.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :user (String, requried)

    the user whose library you want to fetch

  • :artist (String, optional)

    an artist by which to filter track

  • :album (String, optional)

    an album by which to filter tracks (requires an associated artist)

  • :page (Fixnum, optional)

    the page number to fetch. defaults to first page

  • :limit (Fixnum, optional)

    the number of results to fetch per page. defaults to 50

See Also:



69
70
71
# File 'lib/lastfm/library.rb', line 69

def get_tracks( params )
  LastFM.get( "library.getTracks", params )
end

.remove_album(params) ⇒ Object

Remove an album from a user’s Last.fm library.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required)

    the artist that composed the album

  • :album (String, required)

    the name of the album to remove

See Also:



78
79
80
81
# File 'lib/lastfm/library.rb', line 78

def remove_album( params )
  LastFM.requires_authentication
  LastFM.post( "library.removeAlbum", params )
end

.remove_artist(params) ⇒ Object

Remove an artist from a user’s Last.fm library.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required)

    the name of the artist to remove

See Also:



87
88
89
90
# File 'lib/lastfm/library.rb', line 87

def remove_artist( params )
  LastFM.requires_authentication
  LastFM.post( "library.removeArtist", params )
end

.remove_scrobble(params) ⇒ Object

Remove a scrobble from a user’s Last.fm library.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required)

    the artist that composed the album

  • :track (String, required)

    the name of the track to remove

  • :timestamp (Time, required)

    the unix timestamp of the scrobble to remove

See Also:



98
99
100
101
# File 'lib/lastfm/library.rb', line 98

def remove_scrobble( params )
  LastFM.requires_authentication
  LastFM.post( "library.removeScrobble", params )
end

.remove_track(params) ⇒ Object

Remove a track from a user’s Last.fm library.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required)

    the artist that composed the track

  • :track (String, required)

    the name of the track to remove

See Also:



108
109
110
111
# File 'lib/lastfm/library.rb', line 108

def remove_track( params )
  LastFM.requires_authentication
  LastFM.post( "library.removeTrack", params )
end