Class: Scrobbler::Artist

Inherits:
Base
  • Object
show all
Defined in:
lib/scrobbler/artist.rb

Overview

TODO:

Add missing functions that require authentication

TODO:

Integrate search functionality into this class which is already implemented in Scrobbler::Search

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key=, connection, fetch_and_parse, sanitize

Constructor Details

#initialize(name) ⇒ Artist

Returns a new instance of Artist.

Raises:

  • (ArgumentError)


93
94
95
96
# File 'lib/scrobbler/artist.rb', line 93

def initialize(name)
  raise ArgumentError, "Name is required" if name.blank?
  @name = name
end

Instance Attribute Details

#chartpositionObject

Returns the value of attribute chartposition.



64
65
66
# File 'lib/scrobbler/artist.rb', line 64

def chartposition
  @chartposition
end

#countObject

Returns the value of attribute count.



63
64
65
# File 'lib/scrobbler/artist.rb', line 63

def count
  @count
end

#image_largeObject

Returns the value of attribute image_large.



64
65
66
# File 'lib/scrobbler/artist.rb', line 64

def image_large
  @image_large
end

#image_mediumObject

Returns the value of attribute image_medium.



64
65
66
# File 'lib/scrobbler/artist.rb', line 64

def image_medium
  @image_medium
end

#image_smallObject

Returns the value of attribute image_small.



64
65
66
# File 'lib/scrobbler/artist.rb', line 64

def image_small
  @image_small
end

#matchObject

used for similar artists



67
68
69
# File 'lib/scrobbler/artist.rb', line 67

def match
  @match
end

#mbidObject

Returns the value of attribute mbid.



63
64
65
# File 'lib/scrobbler/artist.rb', line 63

def mbid
  @mbid
end

#nameObject

Returns the value of attribute name.



63
64
65
# File 'lib/scrobbler/artist.rb', line 63

def name
  @name
end

#playcountObject

Returns the value of attribute playcount.



63
64
65
# File 'lib/scrobbler/artist.rb', line 63

def playcount
  @playcount
end

#rankObject

Returns the value of attribute rank.



63
64
65
# File 'lib/scrobbler/artist.rb', line 63

def rank
  @rank
end

#streamableObject

Returns the value of attribute streamable.



63
64
65
# File 'lib/scrobbler/artist.rb', line 63

def streamable
  @streamable
end

#urlObject

Returns the value of attribute url.



63
64
65
# File 'lib/scrobbler/artist.rb', line 63

def url
  @url
end

Class Method Details

.new_from_xml(xml, doc = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/scrobbler/artist.rb', line 70

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             = Base::sanitize(xml['name'])          if name.nil? && xml['name']
  name         = Base::sanitize(xml.at('/name').inner_html) if name.nil? && (xml).at(:name)
  a                = Artist.new(name)
  a.mbid           = xml.at(:mbid).inner_html           if xml.at(:mbid)
  a.playcount      = xml.at(:playcount).inner_html      if xml.at(:playcount)
  a.rank           = Base::sanitize(xml['rank'])           if xml['rank']
  a.url            = xml.at(:url).inner_html            if xml.at(:url)
  a.image_small  = xml.at("image[@size='small']").inner_html   if xml.at("image[@size='small']")
  a.image_medium = xml.at("image[@size='medium']'").inner_html if xml.at("image[@size='medium']'")
  a.image_large  = xml.at("image[@size='large']'").inner_html  if xml.at("image[@size='large']'")
  a.match          = xml.at(:match).inner_html          if xml.at(:match)
  a.chartposition = xml.at(:chartposition).inner_html  if xml.at(:chartposition)

  # in top artists for tag
  a.count          = xml.at('/tagcount').inner_html    if xml.at('/tagcount')
  a.streamable     = xml['streamable']                    if xml['streamable']
  a.streamable     = xml.at(:streamable).inner_html == '1' ? 'yes' : 'no' if a.streamable.nil? && xml.at(:streamable)
  a
end

Instance Method Details

#current_events(format = :ics) ⇒ Object

TODO:

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

Raises:

  • (ArgumentError)


102
103
104
105
106
# File 'lib/scrobbler/artist.rb', line 102

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

#image(which = :small) ⇒ Object

Raises:

  • (ArgumentError)


108
109
110
111
112
# File 'lib/scrobbler/artist.rb', line 108

def image(which=:small)
  which = which.to_s
  raise ArgumentError unless ['small', 'medium', 'large'].include?(which)      
  instance_variable_get("@image_#{which}")
end

#similar(force = false) ⇒ Object



114
115
116
# File 'lib/scrobbler/artist.rb', line 114

def similar(force=false)
  get_instance2('artist.getsimilar', :similar, :artist, {'artist'=>@name}, force)
end

#top_albums(force = false) ⇒ Object



126
127
128
# File 'lib/scrobbler/artist.rb', line 126

def top_albums(force=false)
  get_instance2('artist.gettopalbums', :top_albums, :album, {'artist'=>@name}, force)
end

#top_fans(force = false) ⇒ Object



118
119
120
# File 'lib/scrobbler/artist.rb', line 118

def top_fans(force=false)
  get_instance2('artist.gettopfans', :top_fans, :user, {'artist'=>@name}, force)
end

#top_tags(force = false) ⇒ Object



130
131
132
# File 'lib/scrobbler/artist.rb', line 130

def top_tags(force=false)
  get_instance2('artist.gettoptags', :top_tags, :tag, {'artist'=>@name}, force)
end

#top_tracks(force = false) ⇒ Object



122
123
124
# File 'lib/scrobbler/artist.rb', line 122

def top_tracks(force=false)
  get_instance2('artist.gettoptracks', :top_tracks, :track, {'artist'=>@name}, force)
end