Class: Scrobbler::Album
- Inherits:
-
BaseXmlInfo
- Object
- Base
- BaseXml
- BaseXmlInfo
- Scrobbler::Album
- Includes:
- ImageObjectFuncs
- Defined in:
- lib/scrobbler/album.rb
Overview
Class for handling album.* requests to the Last.fm API and reading Album data provided in return.
Instance Attribute Summary (collapse)
-
- (Object) artist
readonly
Returns the value of attribute artist.
-
- (Object) artist_mbid
readonly
Returns the value of attribute artist_mbid.
-
- (Object) chartposition
readonly
Returns the value of attribute chartposition.
-
- (Object) count
readonly
Returns the value of attribute count.
-
- (Object) listeners
readonly
Returns the value of attribute listeners.
-
- (Object) mbid
readonly
Returns the value of attribute mbid.
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) playcount
readonly
Returns the value of attribute playcount.
-
- (Object) position
readonly
Returns the value of attribute position.
-
- (Object) rank
readonly
Returns the value of attribute rank.
-
- (Object) reach
readonly
Returns the value of attribute reach.
-
- (Object) release_date
readonly
Returns the value of attribute release_date.
-
- (Object) tagcount
readonly
Returns the value of attribute tagcount.
-
- (Object) top_tags
readonly
Returns the value of attribute top_tags.
-
- (Object) url
readonly
Returns the value of attribute url.
Class Method Summary (collapse)
- + (Object) new_from_libxml(xml) deprecated Deprecated.
Instance Method Summary (collapse)
-
- (nil) add_tags(session, tags)
Tag an album using a list of user supplied tags.
-
- (Object) buylinks
Get the links to buy this album.
-
- (Album) initialize(data = {})
constructor
Create a new Scrobbler::Artist instance.
-
- (nil) load_from_xml(node)
Load the data for this object out of a XML-Node.
-
- (Object) load_info
Load additional information about this album.
-
- (Object) remove_tag
Remove a user's tag from an album.
- - (Object) search
-
- (Object) share
Share this album with a friend.
-
- (Object) tags
Get the tags applied by an individual user to an album on Last.fm.
Methods included from ImageObjectFuncs
Methods inherited from Base
add_cache, api_key=, #call, #call_pageable, fetch_http, get, load_from_cache, #populate_data, post_request, #request, request, sanitize, save_to_cache, secret=, validate_response_document
Constructor Details
- (Album) initialize(data = {})
Create a new Scrobbler::Artist instance
If the additional parameter :include_info is set to true, additional information is loaded
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scrobbler/album.rb', line 33 def initialize(data={}) raise ArgumentError unless data.kind_of?(Hash) super(data) if @artist.is_a?(String) then @artist = Artist.new(:name => @artist) end raise ArgumentError, "Artist or mbid is required" if @artist.nil? && @mbid.nil? raise ArgumentError, "Name is required" if @name.empty? end |
Instance Attribute Details
- (Object) artist (readonly)
Returns the value of attribute artist
11 12 13 |
# File 'lib/scrobbler/album.rb', line 11 def artist @artist end |
- (Object) artist_mbid (readonly)
Returns the value of attribute artist_mbid
11 12 13 |
# File 'lib/scrobbler/album.rb', line 11 def artist_mbid @artist_mbid end |
- (Object) chartposition (readonly)
Returns the value of attribute chartposition
13 14 15 |
# File 'lib/scrobbler/album.rb', line 13 def chartposition @chartposition end |
- (Object) count (readonly)
Returns the value of attribute count
13 14 15 |
# File 'lib/scrobbler/album.rb', line 13 def count @count end |
- (Object) listeners (readonly)
Returns the value of attribute listeners
12 13 14 |
# File 'lib/scrobbler/album.rb', line 12 def listeners @listeners end |
- (Object) mbid (readonly)
Returns the value of attribute mbid
11 12 13 |
# File 'lib/scrobbler/album.rb', line 11 def mbid @mbid end |
- (Object) name (readonly)
Returns the value of attribute name
11 12 13 |
# File 'lib/scrobbler/album.rb', line 11 def name @name end |
- (Object) playcount (readonly)
Returns the value of attribute playcount
11 12 13 |
# File 'lib/scrobbler/album.rb', line 11 def playcount @playcount end |
- (Object) position (readonly)
Returns the value of attribute position
13 14 15 |
# File 'lib/scrobbler/album.rb', line 13 def position @position end |
- (Object) rank (readonly)
Returns the value of attribute rank
11 12 13 |
# File 'lib/scrobbler/album.rb', line 11 def rank @rank end |
- (Object) reach (readonly)
Returns the value of attribute reach
12 13 14 |
# File 'lib/scrobbler/album.rb', line 12 def reach @reach end |
- (Object) release_date (readonly)
Returns the value of attribute release_date
12 13 14 |
# File 'lib/scrobbler/album.rb', line 12 def release_date @release_date end |
- (Object) tagcount (readonly)
Returns the value of attribute tagcount
13 14 15 |
# File 'lib/scrobbler/album.rb', line 13 def tagcount @tagcount end |
- (Object) top_tags (readonly)
Returns the value of attribute top_tags
12 13 14 |
# File 'lib/scrobbler/album.rb', line 12 def @top_tags end |
- (Object) url (readonly)
Returns the value of attribute url
11 12 13 |
# File 'lib/scrobbler/album.rb', line 11 def url @url end |
Class Method Details
+ (Object) new_from_libxml(xml)
Alias for Album.new(:xml => xml)
18 19 20 |
# File 'lib/scrobbler/album.rb', line 18 def self.new_from_libxml(xml) Album.new(:xml => xml) end |
Instance Method Details
- (nil) add_tags(session, tags)
Tag an album using a list of user supplied tags.
128 129 130 |
# File 'lib/scrobbler/album.rb', line 128 def (session, ) Base.post_request('album.addTags', {:sk => session.key, :signed => true, :tags => .join(',')}) end |
- (Object) buylinks
Get the links to buy this album
145 146 147 |
# File 'lib/scrobbler/album.rb', line 145 def buylinks() raise NotImplementedError end |
- (nil) load_from_xml(node)
Load the data for this object out of a XML-Node
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/scrobbler/album.rb', line 49 def load_from_xml(node) # Get all information from the root's children nodes node.children.each do |child| case child.name.to_s when 'name' @name = child.content when 'title' @name = child.content when 'playcount' @playcount = child.content.to_i when 'tagcount' @tagcount = child.content.to_i when 'mbid' @mbid = child.content when 'url' @url = child.content when 'artist' @artist = Artist.new(:xml => child) when 'image' check_image_node(child) when 'id' @id = child.content.to_s when 'releasedate' @release_date = Time.parse(child.content.strip) when 'listeners' @listeners = child.content.to_i when 'toptags' @top_tags = [] if @top_tags.nil? child.children.each do |tag| next unless tag.name == 'tag' @top_tags << Tag.new_from_libxml(tag) end when 'wiki' # @todo Handle wiki entries when 'text' # ignore, these are only blanks when '#text' # libxml-jruby version of blanks else raise NotImplementedError, "Field '#{child.name}' not known (#{child.content})" end #^ case end #^ do |child| # Get all information from the root's attributes @mbid = node['mbid'].to_s unless node['mbid'].nil? @rank = node['rank'].to_i unless node['rank'].nil? @position = node['position'].to_i unless node['position'].nil? # If we have not found anything in the content of this node yet then # this must be a simple artist node which has the name of the artist # as its content @name = node.content if @name.nil? end |
- (Object) load_info
Parse wiki content
Add language code for wiki translation
Load additional information about this album
Calls "album.getinfo" REST method
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/scrobbler/album.rb', line 111 def load_info return nil if @info_loaded xml = Base.request('album.getinfo', {:artist => @artist.name, :album => @name}) unless xml.root['status'] == 'failed' xml.root.children.each do |childL1| next unless childL1.name == 'album' load_from_xml(childL1) end # xml.children.each do |childL1| @info_loaded = true end end |
- (Object) remove_tag
Remove a user's tag from an album.
139 140 141 142 |
# File 'lib/scrobbler/album.rb', line 139 def remove_tag() # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Object) search
22 23 24 25 |
# File 'lib/scrobbler/album.rb', line 22 def search # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Object) share
Share this album with a friend
150 151 152 |
# File 'lib/scrobbler/album.rb', line 150 def share() raise NotImplementedError end |
- (Object) tags
Get the tags applied by an individual user to an album on Last.fm.
133 134 135 136 |
# File 'lib/scrobbler/album.rb', line 133 def () # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |