Class: LastFM::Api::Album

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

Class Method Summary collapse

Class Method Details

.add_tags(params) ⇒ Object

Tag an album using a list of user supplied tags.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required)

    the artist name

  • :album (String, required)

    the album name

  • :tags (Array, required)

    up to 10 tags to apply to this album

See Also:



12
13
14
15
# File 'lib/lastfm/api/album.rb', line 12

def add_tags( params )
  LastFM.requires_authentication
  LastFM.post( "album.addTags", params )
end

Get a list of buy links for an album.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required unless :mbid)

    the artist name

  • :album (String, required unless :mbid)

    the album name

  • :country (String, required)

    a country name, as defined by ISO 3166-1

  • :mbid (String, optional)

    the musicbrainz id for the album

  • :autocorrect (Boolean, optional)

    transform misspelled artist names into correct artist names to be returned in the response

Returns:

  • (Array<LastFM::Buylink>)

    collection of links where this album can be bought or downloaded

See Also:



26
27
28
29
30
31
32
33
# File 'lib/lastfm/api/album.rb', line 26

def get_buylinks( params )
  xml = LastFM.get( "album.getBuylinks", params )
  [:physical, :download].each_with_object([]) do |type, buylinks|
    xml.find("affiliations/#{type}s/affiliation").each do |buylink|
      buylinks << LastFM::Buylink.from_xml( buylink, :type => type )
    end
  end
end

.get_info(params) ⇒ LastFM::Album

Get the metadata for an album.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required unless :mbid)

    the artist name

  • :album (String, required unless :mbid)

    the album name

  • :mbid (String, optional)

    the musicbrainz id for the album

  • :lang (String, optional)

    the language to return the biography in, expressed as an ISO 639 alpha-2 code

  • :autocorrect (Boolean, optional)

    transform misspelled artist names into correct artist names to be returned in the response

  • :username (String, optional)

    username whose playcount for this album is to be returned in the reponse

Returns:

  • (LastFM::Album)

    album constructed from the metadata contained in the response

See Also:



45
46
47
48
# File 'lib/lastfm/api/album.rb', line 45

def get_info( params )
  xml = LastFM.get( "album.getInfo", params )
  LastFM::Album.from_xml( xml )
end

.get_shouts(params) ⇒ Array<LastFM::Shout>

Get shouts for an album.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required unless :mbid)

    the artist name

  • :album (String, required unless :mbid)

    the album name

  • :mbid (String, optional)

    the musicbrainz id for the album

  • :autocorrect (Boolean, optional)

    transform misspelled artist names into correct artist names to be returned in the response

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

Returns:

See Also:



60
61
62
63
64
65
# File 'lib/lastfm/api/album.rb', line 60

def get_shouts( params )
  xml = LastFM.get( "album.getShouts", params )
  xml.find('shouts/shout').map do |shout|
    LastFM::Shout.from_xml( shout )
  end
end

.get_tags(params) ⇒ Object

Get the tags applied by an individual user to an album.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required unless :mbid)

    the artist name

  • :album (String, required unless :mbid)

    the album name

  • :mbid (String, optional)

    the musicbrainz id for the album

  • :autocorrect (Boolean, optional)

    transform misspelled artist names into correct artist names to be returned in the response

  • :user (String, optional)

    if called in non-authenticated mode you must specify the user to look up

See Also:



75
76
77
78
79
80
81
82
# File 'lib/lastfm/api/album.rb', line 75

def get_tags( params )
  secure = !params.include?(:user)
  LastFM.requires_authentication if secure
  xml = LastFM.get( "album.getTags", params, secure )
  xml.find('tags/tag').map do |tag|
    LastFM::Tag.from_xml( tag )
  end
end

.get_top_tags(params) ⇒ Array<LastFM::Tag>

Get the top tags for an album, ordered by popularity.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required unless :mbid)

    the artist name

  • :album (String, required unless :mbid)

    the album name

  • :mbid (String, optional)

    the musicbrainz id for the album

  • :autocorrect (Boolean, optional)

    transform misspelled artist names into correct artist names to be returned in the response

Returns:

  • (Array<LastFM::Tag>)

    list of tags sorted by popularity

See Also:



92
93
94
95
96
97
# File 'lib/lastfm/api/album.rb', line 92

def get_top_tags( params )
  xml = LastFM.get( "album.getTopTags", params )
  xml.find('toptags/tag').map do |tag|
    LastFM::Tag.from_xml( tag )
  end
end

.remove_tag(params) ⇒ Object

Remove a user’s tag from an album.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required)

    the artist name

  • :album (String, required)

    the album name

  • :tag (String, required)

    a single user tag to remove from this album

See Also:



105
106
107
108
# File 'lib/lastfm/api/album.rb', line 105

def remove_tag( params )
  LastFM.requires_authentication
  LastFM.post( "album.removeTag", params )
end

.search(params) ⇒ Array<LastFM::Album>

Search for an album by name. Returns album matches sorted by relevance.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :album (String, required)

    the album name

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

Returns:

See Also:



117
118
119
120
121
122
# File 'lib/lastfm/api/album.rb', line 117

def search( params )
  xml = LastFM.get( "album.search", params )
  xml.find('results/albummatches/album').map do |album|
    LastFM::Album.from_xml( album )
  end
end

.share(params) ⇒ Object

Share an album with one or more Last.fm users or other friends.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :artist (String, required)

    the artist name

  • :album (String, required)

    the album name

  • :recipient (Array, required)

    a list of email addresses or Last.fm usernames. maximum is 10

  • :message (String, optional)

    an optional message to send. if not supplied a default message will be used

  • :public (Boolean, optional)

    optionally show in the sharing users activity feed. defaults to false

See Also:



132
133
134
135
# File 'lib/lastfm/api/album.rb', line 132

def share( params )
  LastFM.requires_authentication
  LastFM.post( "album.share", params )
end