Class: Rockstar::Artist
Instance Attribute Summary collapse
-
#chartposition ⇒ Object
Returns the value of attribute chartposition.
-
#content ⇒ Object
Returns the value of attribute content.
-
#count ⇒ Object
Returns the value of attribute count.
-
#images ⇒ Object
Returns the value of attribute images.
-
#listenercount ⇒ Object
Returns the value of attribute listenercount.
-
#match ⇒ Object
used for similar artists.
-
#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.
-
#streamable ⇒ Object
Returns the value of attribute streamable.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#thumbnail ⇒ Object
Returns the value of attribute thumbnail.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #current_events(format = :ics) ⇒ Object
- #events(force = false) ⇒ Object
- #image(which = :medium) ⇒ Object
-
#initialize(name, o = {}) ⇒ Artist
constructor
A new instance of Artist.
- #load_info(xml = nil) ⇒ Object
- #similar(force = false) ⇒ Object
- #top_albums(force = false) ⇒ Object
- #top_fans(force = false) ⇒ Object
- #top_tags(force = false) ⇒ Object
- #top_tracks(force = false) ⇒ Object
- #user_images(opts = {}) ⇒ Object
Methods inherited from Base
connection, fetch_and_parse, get_instance
Constructor Details
#initialize(name, o = {}) ⇒ Artist
Returns a new instance of Artist.
80 81 82 83 84 85 86 |
# File 'lib/rockstar/artist.rb', line 80 def initialize(name, o={}) raise ArgumentError, "Name is required" if name.blank? @name = name = {:include_info => false}.merge(o) load_info if [:include_info] end |
Instance Attribute Details
#chartposition ⇒ Object
Returns the value of attribute chartposition.
63 64 65 |
# File 'lib/rockstar/artist.rb', line 63 def chartposition @chartposition end |
#content ⇒ Object
Returns the value of attribute content.
62 63 64 |
# File 'lib/rockstar/artist.rb', line 62 def content @content end |
#count ⇒ Object
Returns the value of attribute count.
62 63 64 |
# File 'lib/rockstar/artist.rb', line 62 def count @count end |
#images ⇒ Object
Returns the value of attribute images.
62 63 64 |
# File 'lib/rockstar/artist.rb', line 62 def images @images end |
#listenercount ⇒ Object
Returns the value of attribute listenercount.
61 62 63 |
# File 'lib/rockstar/artist.rb', line 61 def listenercount @listenercount end |
#match ⇒ Object
used for similar artists
66 67 68 |
# File 'lib/rockstar/artist.rb', line 66 def match @match end |
#mbid ⇒ Object
Returns the value of attribute mbid.
61 62 63 |
# File 'lib/rockstar/artist.rb', line 61 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
61 62 63 |
# File 'lib/rockstar/artist.rb', line 61 def name @name end |
#playcount ⇒ Object
Returns the value of attribute playcount.
61 62 63 |
# File 'lib/rockstar/artist.rb', line 61 def playcount @playcount end |
#rank ⇒ Object
Returns the value of attribute rank.
61 62 63 |
# File 'lib/rockstar/artist.rb', line 61 def rank @rank end |
#streamable ⇒ Object
Returns the value of attribute streamable.
62 63 64 |
# File 'lib/rockstar/artist.rb', line 62 def streamable @streamable end |
#summary ⇒ Object
Returns the value of attribute summary.
62 63 64 |
# File 'lib/rockstar/artist.rb', line 62 def summary @summary end |
#thumbnail ⇒ Object
Returns the value of attribute thumbnail.
61 62 63 |
# File 'lib/rockstar/artist.rb', line 61 def thumbnail @thumbnail end |
#url ⇒ Object
Returns the value of attribute url.
61 62 63 |
# File 'lib/rockstar/artist.rb', line 61 def url @url end |
Class Method Details
.new_from_xml(xml, doc = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/rockstar/artist.rb', line 69 def new_from_xml(xml, doc=nil) # occasionally name can be found in root of artist element (<artist name="">) rather than as an element (<name>) name = (xml).at(:name).inner_html if (xml).at(:name) name = xml['name'] if name.nil? && xml['name'] artist = Artist.new(name) artist.load_info(xml) artist end |
Instance Method Details
#current_events(format = :ics) ⇒ Object
125 126 127 128 |
# File 'lib/rockstar/artist.rb', line 125 def current_events(format=:ics) warn "[DEPRECATION] the `current_events` method is deprecated. Please use artist.events" events end |
#events(force = false) ⇒ Object
130 131 132 |
# File 'lib/rockstar/artist.rb', line 130 def events(force=false) get_instance("artist.getEvents", :events, :event, {:artist => @name}, force) end |
#image(which = :medium) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/rockstar/artist.rb', line 154 def image(which=:medium) which = which.to_s raise ArgumentError unless ['small', 'medium', 'large', 'extralarge'].include?(which) load_info if self.images.nil? self.images[which] end |
#load_info(xml = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rockstar/artist.rb', line 88 def load_info(xml=nil) unless xml doc = self.class.fetch_and_parse("artist.getInfo", {:artist => @name}) xml = (doc / :artist).first end return self if xml.nil? self.mbid = (xml).at(:mbid).inner_html if (xml).at(:mbid) self.listenercount = (xml).at(:listeners).inner_html if (xml).at(:listeners) self.playcount = (xml).at(:playcount).inner_html if (xml).at(:playcount) self.chartposition = self.rank = xml['rank'] if xml['rank'] self.chartposition = self.rank = (xml).at(:rank).inner_html if (xml).at(:rank) if self.rank.nil? self.url = Base.fix_url((xml).at(:url).inner_html) if (xml).at(:url) if bio_xml = xml.at(:bio) self.summary = bio_xml.at(:summary).to_plain_text if bio_xml.at(:summary) self.content = bio_xml.at(:content).to_plain_text if bio_xml.at(:content) end self.images = {} (xml/'image').each {|image| self.images[image['size']] = image.inner_html if self.images[image['size']].nil? } self.thumbnail = self.images['small'] self.match = (xml).at(:match).inner_html if (xml).at(:match) # in top artists for tag self.count = xml['count'] if xml['count'] self.streamable = xml['streamable'] if xml['streamable'] self.streamable = (xml).at(:streamable).inner_html == '1' ? 'yes' : 'no' if self.streamable.nil? && (xml).at(:streamable) self end |
#similar(force = false) ⇒ Object
134 135 136 |
# File 'lib/rockstar/artist.rb', line 134 def similar(force=false) get_instance("artist.getSimilar", :similar, :artist, {:artist => @name}, force) end |
#top_albums(force = false) ⇒ Object
146 147 148 |
# File 'lib/rockstar/artist.rb', line 146 def top_albums(force=false) get_instance("artist.getTopAlbums", :top_albums, :album, {:artist => @name}, force) end |
#top_fans(force = false) ⇒ Object
138 139 140 |
# File 'lib/rockstar/artist.rb', line 138 def top_fans(force=false) get_instance("artist.getTopFans", :top_fans, :user, {:artist => @name}, force) end |
#top_tags(force = false) ⇒ Object
150 151 152 |
# File 'lib/rockstar/artist.rb', line 150 def (force=false) get_instance("artist.getTopTags", :top_tags, :tag, {:artist => @name}, force) end |
#top_tracks(force = false) ⇒ Object
142 143 144 |
# File 'lib/rockstar/artist.rb', line 142 def top_tracks(force=false) get_instance("artist.getTopTracks", :top_tracks, :track, {:artist => @name}, force) end |
#user_images(opts = {}) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rockstar/artist.rb', line 161 def user_images(opts={}) if mbid.nil? opts[:artist] = name else opts[:mbid] = mbid end images = [] image_doc = self.class.fetch_and_parse("artist.getImages", opts, false) (image_doc/'image').each do |xml| image_sizes = {} xml.search('/sizes/size').each do |image| image_sizes[image['name']] = image.inner_html end images << image_sizes end images end |