Class: Scrobbler::Artist
Instance Attribute Summary collapse
-
#chartposition ⇒ Object
Returns the value of attribute chartposition.
-
#count ⇒ Object
Returns the value of attribute count.
-
#listeners ⇒ Object
Returns the value of attribute listeners.
-
#match ⇒ Object
Returns the value of attribute match.
-
#mbid ⇒ Object
Returns the value of attribute mbid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#playcount ⇒ Object
Returns the value of attribute playcount.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#tagcount ⇒ Object
Returns the value of attribute tagcount.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #==(otherArtist) ⇒ Object
-
#current_events(format = :ics) ⇒ Object
Get the URL to the ical or rss representation of the current events that a artist will play.
-
#initialize(name, data = {}) ⇒ Artist
constructor
A new instance of Artist.
-
#load_info ⇒ Object
Get the metadata.
- #similar(force = false) ⇒ Object
- #top_albums(force = false) ⇒ Object
- #top_fans(force = false) ⇒ Object
- #top_tags(force = false) ⇒ Object
- #top_tracks(force = false) ⇒ Object
Methods inherited from Base
api_key=, connection, get, maybe_streamable_attribute, maybe_streamable_node, post_request, request, sanitize, secret=
Constructor Details
#initialize(name, data = {}) ⇒ Artist
Returns a new instance of Artist.
106 107 108 109 110 111 |
# File 'lib/scrobbler/artist.rb', line 106 def initialize(name, data = {}) super() raise ArgumentError, "Name is required" if name.blank? @name = name populate_data(data) end |
Instance Attribute Details
#chartposition ⇒ Object
Returns the value of attribute chartposition.
66 67 68 |
# File 'lib/scrobbler/artist.rb', line 66 def chartposition @chartposition end |
#count ⇒ Object
Returns the value of attribute count.
65 66 67 |
# File 'lib/scrobbler/artist.rb', line 65 def count @count end |
#listeners ⇒ Object
Returns the value of attribute listeners.
67 68 69 |
# File 'lib/scrobbler/artist.rb', line 67 def listeners @listeners end |
#match ⇒ Object
Returns the value of attribute match.
67 68 69 |
# File 'lib/scrobbler/artist.rb', line 67 def match @match end |
#mbid ⇒ Object
Returns the value of attribute mbid.
65 66 67 |
# File 'lib/scrobbler/artist.rb', line 65 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
65 66 67 |
# File 'lib/scrobbler/artist.rb', line 65 def name @name end |
#playcount ⇒ Object
Returns the value of attribute playcount.
65 66 67 |
# File 'lib/scrobbler/artist.rb', line 65 def playcount @playcount end |
#rank ⇒ Object
Returns the value of attribute rank.
65 66 67 |
# File 'lib/scrobbler/artist.rb', line 65 def rank @rank end |
#tagcount ⇒ Object
Returns the value of attribute tagcount.
67 68 69 |
# File 'lib/scrobbler/artist.rb', line 67 def tagcount @tagcount end |
#url ⇒ Object
Returns the value of attribute url.
65 66 67 |
# File 'lib/scrobbler/artist.rb', line 65 def url @url end |
Class Method Details
.data_from_xml(xml, o = {}) ⇒ Object
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 101 102 103 |
# File 'lib/scrobbler/artist.rb', line 76 def data_from_xml(xml, o={}) data = {} # Get all information from the root's children nodes xml.children.each do |child| data[:playcount] = child.content.to_i if child.name == 'playcount' data[:mbid] = child.content if child.name == 'mbid' data[:url] = child.content if child.name == 'url' data[:match] = child.content.to_i if child.name == 'match' data[:tagcount] = child.content.to_i if child.name == 'tagcount' data[:chartposition] = child.content if child.name == 'chartposition' data[:name] = child.content if child.name == 'name' maybe_streamable_node(data, child) maybe_image_node(data, child) end # 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 data[:name] = xml.content if data == {} # Get all information from the root's attributes data[:name] = xml['name'] if xml['name'] data[:rank] = xml['rank'].to_i if xml['rank'] maybe_streamable_attribute data, xml data[:mbid] = xml['mbid'] if xml['mbid'] data end |
Instance Method Details
#==(otherArtist) ⇒ Object
157 158 159 160 161 162 |
# File 'lib/scrobbler/artist.rb', line 157 def ==(otherArtist) if otherArtist.is_a?(Scrobbler::Artist) return (@name == otherArtist.name) end false end |
#current_events(format = :ics) ⇒ Object
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
131 132 133 134 135 |
# File 'lib/scrobbler/artist.rb', line 131 def current_events(format=:ics) format = :ics if format.to_s == 'ical' raise ArgumentError unless ['ics', 'rss'].include?(format.to_s) "#{API_URL.chop}/2.0/artist/#{CGI::escape(@name)}/events.#{format}" end |
#load_info ⇒ Object
Get the metadata
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/scrobbler/artist.rb', line 115 def load_info doc = Base.request('artist.getinfo', {'artist' => @name}) doc.root.children.each do |child| next unless child.name == 'artist' data = self.class.data_from_xml(child) populate_data(data) @info_loaded = true break end end |
#similar(force = false) ⇒ Object
137 138 139 |
# File 'lib/scrobbler/artist.rb', line 137 def similar(force=false) get_response('artist.getsimilar', :similar, 'similarartists', 'artist', {'artist' => @name}, force) end |
#top_albums(force = false) ⇒ Object
149 150 151 |
# File 'lib/scrobbler/artist.rb', line 149 def top_albums(force=false) get_response('artist.gettopalbums', :top_albums, 'topalbums', 'album', {'artist'=>@name}, force) end |
#top_fans(force = false) ⇒ Object
141 142 143 |
# File 'lib/scrobbler/artist.rb', line 141 def top_fans(force=false) get_response('artist.gettopfans', :top_fans, 'topfans', 'user', {'artist' => @name}, force) end |
#top_tags(force = false) ⇒ Object
153 154 155 |
# File 'lib/scrobbler/artist.rb', line 153 def (force=false) get_response('artist.gettoptags', :top_tags, 'toptags', 'tag', {'artist' => @name}, force) end |
#top_tracks(force = false) ⇒ Object
145 146 147 |
# File 'lib/scrobbler/artist.rb', line 145 def top_tracks(force=false) get_response('artist.gettoptracks', :top_tracks, 'toptracks', 'track', {'artist'=>@name}, force) end |