Class: Scrobbler::Artist
- Inherits:
-
BaseXmlInfo
- Object
- Base
- BaseXml
- BaseXmlInfo
- Scrobbler::Artist
- Includes:
- ImageObjectFuncs, StreamableObjectFuncs
- Defined in:
- lib/scrobbler/artist.rb
Overview
Add missing functions that require authentication
Integrate search functionality into this class which is already implemented in Scrobbler::Search
Instance Attribute Summary (collapse)
-
- (Object) bio
readonly
Returns the value of attribute bio.
-
- (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) match
readonly
Returns the value of attribute match.
-
- (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) rank
readonly
Returns the value of attribute rank.
-
- (Object) streamable
readonly
Returns the value of attribute streamable.
-
- (Object) tagcount
readonly
Returns the value of attribute tagcount.
-
- (Object) url
readonly
Returns the value of attribute url.
Class Method Summary (collapse)
- + (Object) new_from_libxml(xml) deprecated Deprecated.
Instance Method Summary (collapse)
-
- (Boolean) ==(other_artist)
Compare two Artists.
- - (Object) add_tags
-
- (String) current_events(format = :ics)
Get the URL to the ical or rss representation of the current events that a artist will play.
- - (Object) events
- - (Object) images
-
- (Artist) 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.
-
- (nil) load_info
Get the metadata for an artist on Last.fm.
- - (Object) remove_tag
- - (Object) search
- - (Object) share
- - (Object) shout
- - (Object) shouts
-
- (Array<Scrobbler::Artist>) similar
Get all the artists similar to this artist.
- - (Object) tags
-
- (Array<Scrobbler::Album>) top_albums
Get the top albums for an artist on Last.fm, ordered by popularity.
-
- (Array<Scrobbler::User>) top_fans
Get the top fans for an artist on Last.fm, based on listening data.
-
- (Array<Scrobbler::Tags>) top_tags
Get the top tags for an artist on Last.fm, ordered by popularity.
-
- (Array<Scrobbler:Track>) top_tracks
Get the top tracks by an artist on Last.fm, ordered by popularity.
Methods included from StreamableObjectFuncs
#check_streamable_node, #maybe_streamable_attribute
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
- (Artist) initialize(data = {})
Create a new Scrobbler::Artist instance
25 26 27 28 29 |
# File 'lib/scrobbler/artist.rb', line 25 def initialize(data = {}) raise ArgumentError unless data.kind_of?(Hash) super(data) raise ArgumentError, "Name is required" if @name.nil? || @name.strip.empty? end |
Instance Attribute Details
- (Object) bio (readonly)
Returns the value of attribute bio
13 14 15 |
# File 'lib/scrobbler/artist.rb', line 13 def bio @bio end |
- (Object) chartposition (readonly)
Returns the value of attribute chartposition
13 14 15 |
# File 'lib/scrobbler/artist.rb', line 13 def chartposition @chartposition end |
- (Object) count (readonly)
Returns the value of attribute count
12 13 14 |
# File 'lib/scrobbler/artist.rb', line 12 def count @count end |
- (Object) listeners (readonly)
Returns the value of attribute listeners
12 13 14 |
# File 'lib/scrobbler/artist.rb', line 12 def listeners @listeners end |
- (Object) match (readonly)
Returns the value of attribute match
13 14 15 |
# File 'lib/scrobbler/artist.rb', line 13 def match @match end |
- (Object) mbid (readonly)
Returns the value of attribute mbid
12 13 14 |
# File 'lib/scrobbler/artist.rb', line 12 def mbid @mbid end |
- (Object) name (readonly)
Returns the value of attribute name
12 13 14 |
# File 'lib/scrobbler/artist.rb', line 12 def name @name end |
- (Object) playcount (readonly)
Returns the value of attribute playcount
12 13 14 |
# File 'lib/scrobbler/artist.rb', line 12 def playcount @playcount end |
- (Object) rank (readonly)
Returns the value of attribute rank
12 13 14 |
# File 'lib/scrobbler/artist.rb', line 12 def rank @rank end |
- (Object) streamable (readonly)
Returns the value of attribute streamable
13 14 15 |
# File 'lib/scrobbler/artist.rb', line 13 def streamable @streamable end |
- (Object) tagcount (readonly)
Returns the value of attribute tagcount
13 14 15 |
# File 'lib/scrobbler/artist.rb', line 13 def tagcount @tagcount end |
- (Object) url (readonly)
Returns the value of attribute url
12 13 14 |
# File 'lib/scrobbler/artist.rb', line 12 def url @url end |
Class Method Details
+ (Object) new_from_libxml(xml)
Alias for Artist.new(:xml => xml)
18 19 20 |
# File 'lib/scrobbler/artist.rb', line 18 def self.new_from_libxml(xml) Artist.new(:xml => xml) end |
Instance Method Details
- (Boolean) ==(other_artist)
Compare two Artists
They are equal if their names are equal.
163 164 165 166 167 168 |
# File 'lib/scrobbler/artist.rb', line 163 def ==(other_artist) if other_artist.is_a?(Scrobbler::Artist) return (@name == other_artist.name) end false end |
- (Object) add_tags
185 186 187 188 |
# File 'lib/scrobbler/artist.rb', line 185 def # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (String) current_events(format = :ics)
Use the API function and parse that into a common ruby structure
Get the URL to the ical or rss representation of the current events that a artist will play
98 99 100 101 |
# File 'lib/scrobbler/artist.rb', line 98 def current_events(format=:ics) raise ArgumentError unless ['ics', 'rss'].include?(format.to_s) "#{API_URL.chop}/2.0/artist/#{CGI::escape(@name)}/events.#{format.to_s}" end |
- (Object) events
190 191 192 193 |
# File 'lib/scrobbler/artist.rb', line 190 def events # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Object) images
195 196 197 198 |
# File 'lib/scrobbler/artist.rb', line 195 def images # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (nil) load_from_xml(node)
Load the data for this object out of a XML-Node
35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
# File 'lib/scrobbler/artist.rb', line 35 def load_from_xml(node) # Get all information from the root's children nodes node.children.each do |child| case child.name when 'playcount' @playcount = child.content.to_i when 'mbid' @mbid = child.content when 'url' @url = child.content when 'match' @match = child.content.to_i when 'tagcount' @tagcount = child.content.to_i when 'chartposition' @chartposition = child.content when 'name' @name = child.content when 'image' check_image_node(child) when 'streamable' check_streamable_node(child) when 'stats' child.children.each do |childL2| @listeners = childL2.content.to_i if childL2.name == 'listeners' @playcount = childL2.content.to_i if childL2.name == 'playcount' @playcount = childL2.content.to_i if childL2.name == 'plays' end if not child.children.nil? when 'similar' # Ignore them for the moment, they are not stored. when 'bio' child.children.each do |childL2| @bio = childL2.content if childL2.name == 'content' end when 'tags' # Ignore them at the moment, inlude them later # TODO Include a interface for these tags 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 @name = node['name'] unless node['name'].nil? @rank = node['rank'].to_i unless node['rank'].nil? maybe_streamable_attribute(node) @mbid = node['mbid'] unless node['mbid'].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 |
- (nil) load_info
Get the metadata for an artist on Last.fm. Includes biography.
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/scrobbler/artist.rb', line 143 def load_info if @mbid.nil? req_args = {:artist => @name} else req_args = {:mbid => @mbid} end doc = request('artist.getinfo', req_args) doc.root.children.each do |childL1| next unless childL1.name == 'artist' load_from_xml(childL1) end if (not doc.root.nil?) && (not doc.root.children.nil?) @info_loaded = true end |
- (Object) remove_tag
210 211 212 213 |
# File 'lib/scrobbler/artist.rb', line 210 def remove_tag # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Object) search
170 171 172 173 |
# File 'lib/scrobbler/artist.rb', line 170 def search # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Object) share
175 176 177 178 |
# File 'lib/scrobbler/artist.rb', line 175 def share # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Object) shout
180 181 182 183 |
# File 'lib/scrobbler/artist.rb', line 180 def shout # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Object) shouts
200 201 202 203 |
# File 'lib/scrobbler/artist.rb', line 200 def shouts # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Array<Scrobbler::Artist>) similar
Get all the artists similar to this artist
106 107 108 |
# File 'lib/scrobbler/artist.rb', line 106 def similar call('artist.getsimilar', :similarartists, Artist, {:artist => @name}) end |
- (Object) tags
205 206 207 208 |
# File 'lib/scrobbler/artist.rb', line 205 def # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
- (Array<Scrobbler::Album>) top_albums
Get the top albums for an artist on Last.fm, ordered by popularity.
127 128 129 |
# File 'lib/scrobbler/artist.rb', line 127 def top_albums call('artist.gettopalbums', :topalbums, Album, {:artist => @name}) end |
- (Array<Scrobbler::User>) top_fans
Get the top fans for an artist on Last.fm, based on listening data.
113 114 115 |
# File 'lib/scrobbler/artist.rb', line 113 def top_fans call('artist.gettopfans', :topfans, User, {:artist => @name}) end |
- (Array<Scrobbler::Tags>) top_tags
Get the top tags for an artist on Last.fm, ordered by popularity.
134 135 136 |
# File 'lib/scrobbler/artist.rb', line 134 def call('artist.gettoptags', :toptags, Tag, {:artist => @name}) end |
- (Array<Scrobbler:Track>) top_tracks
Get the top tracks by an artist on Last.fm, ordered by popularity
120 121 122 |
# File 'lib/scrobbler/artist.rb', line 120 def top_tracks call('artist.gettoptracks', :toptracks, Track, {:artist => @name}) end |