Class: Scrobbler::Artist

Inherits:
BaseXmlInfo show all
Includes:
ImageObjectFuncs, StreamableObjectFuncs
Defined in:
lib/scrobbler/artist.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StreamableObjectFuncs

#check_streamable_node, #maybe_streamable_attribute

Methods included from ImageObjectFuncs

#check_image_node, #image

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

#initialize(data = {}) ⇒ Artist

Create a new Scrobbler::Artist instance

Raises:

  • (ArgumentError)


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

#bioObject (readonly)

Returns the value of attribute bio



13
14
15
# File 'lib/scrobbler/artist.rb', line 13

def bio
  @bio
end

#chartpositionObject (readonly)

Returns the value of attribute chartposition



13
14
15
# File 'lib/scrobbler/artist.rb', line 13

def chartposition
  @chartposition
end

#countObject (readonly)

Returns the value of attribute count



12
13
14
# File 'lib/scrobbler/artist.rb', line 12

def count
  @count
end

#listenersObject (readonly)

Returns the value of attribute listeners



12
13
14
# File 'lib/scrobbler/artist.rb', line 12

def listeners
  @listeners
end

#matchObject (readonly)

Returns the value of attribute match



13
14
15
# File 'lib/scrobbler/artist.rb', line 13

def match
  @match
end

#mbidObject (readonly)

Returns the value of attribute mbid



12
13
14
# File 'lib/scrobbler/artist.rb', line 12

def mbid
  @mbid
end

#nameObject (readonly)

Returns the value of attribute name



12
13
14
# File 'lib/scrobbler/artist.rb', line 12

def name
  @name
end

#playcountObject (readonly)

Returns the value of attribute playcount



12
13
14
# File 'lib/scrobbler/artist.rb', line 12

def playcount
  @playcount
end

#rankObject (readonly)

Returns the value of attribute rank



12
13
14
# File 'lib/scrobbler/artist.rb', line 12

def rank
  @rank
end

#streamableObject (readonly)

Returns the value of attribute streamable



13
14
15
# File 'lib/scrobbler/artist.rb', line 13

def streamable
  @streamable
end

#tagcountObject (readonly)

Returns the value of attribute tagcount



13
14
15
# File 'lib/scrobbler/artist.rb', line 13

def tagcount
  @tagcount
end

#urlObject (readonly)

Returns the value of attribute url



12
13
14
# File 'lib/scrobbler/artist.rb', line 12

def url
  @url
end

Class Method Details

.new_from_libxml(xml) ⇒ Object

Deprecated.

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

#==(other_artist) ⇒ Boolean

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

#add_tagsObject

Raises:

  • (NotImplementedError)


185
186
187
188
# File 'lib/scrobbler/artist.rb', line 185

def add_tags
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

#current_events(format = :ics) ⇒ String

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)


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

#eventsObject

Raises:

  • (NotImplementedError)


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

#imagesObject

Raises:

  • (NotImplementedError)


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

#load_from_xml(node) ⇒ nil

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

#load_infonil

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

#remove_tagObject

Raises:

  • (NotImplementedError)


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

#searchObject

Raises:

  • (NotImplementedError)


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

#shareObject

Raises:

  • (NotImplementedError)


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

#shoutObject

Raises:

  • (NotImplementedError)


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

#shoutsObject

Raises:

  • (NotImplementedError)


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

#similarArray<Scrobbler::Artist>

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

#tagsObject

Raises:

  • (NotImplementedError)


205
206
207
208
# File 'lib/scrobbler/artist.rb', line 205

def tags
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

#top_albumsArray<Scrobbler::Album>

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

#top_fansArray<Scrobbler::User>

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

#top_tagsArray<Scrobbler::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 top_tags
  call('artist.gettoptags', :toptags, Tag, {:artist => @name})
end

#top_tracksArray<Scrobbler:Track>

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