Class: Scrobbler::Tag

Inherits:
BaseXml show all
Includes:
StreamableObjectFuncs
Defined in:
lib/scrobbler/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StreamableObjectFuncs

#check_streamable_node, #maybe_streamable_attribute

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 = {}) ⇒ Tag

Create a new Scrobbler::Artist instance

Raises:

  • (ArgumentError)


21
22
23
24
25
# File 'lib/scrobbler/tag.rb', line 21

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

#countObject (readonly)

Returns the value of attribute count



9
10
11
# File 'lib/scrobbler/tag.rb', line 9

def count
  @count
end

#nameObject (readonly)

Returns the value of attribute name



9
10
11
# File 'lib/scrobbler/tag.rb', line 9

def name
  @name
end

#streamableObject (readonly)

Returns the value of attribute streamable



9
10
11
# File 'lib/scrobbler/tag.rb', line 9

def streamable
  @streamable
end

#urlObject (readonly)

Returns the value of attribute url



9
10
11
# File 'lib/scrobbler/tag.rb', line 9

def url
  @url
end

Class Method Details

.new_from_libxml(xml) ⇒ Object

Deprecated.

Alias for Artist.new(:xml => xml)



14
15
16
# File 'lib/scrobbler/tag.rb', line 14

def self.new_from_libxml(xml)
  Tag.new(:xml => xml)
end

.searchObject

Raises:

  • (NotImplementedError)


69
70
71
72
# File 'lib/scrobbler/tag.rb', line 69

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

.top_tagsObject



65
66
67
# File 'lib/scrobbler/tag.rb', line 65

def self.top_tags
    Base.get('tag.gettoptags', :toptags, Tag)
end

Instance Method Details

#load_from_xml(node) ⇒ nil

Load the data for this object out of a XML-Node



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/scrobbler/tag.rb', line 31

def load_from_xml(node)
  # Get all information from the root's children nodes
  node.children.each do |child|
    case child.name
      when 'count'
        @count = child.content.to_i
      when 'url'
        @url = child.content
      when 'name'
        @name = child.content
      when 'streamable'
        check_streamable_node(child)
      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|
end

#similarObject

Search for tags similar to this one. Returns tags ranked by similarity, based on listening data.



77
78
79
# File 'lib/scrobbler/tag.rb', line 77

def similar
    call('tag.getsimilar', :similartags, Tag, {:tag => @name})
end

#top_albumsObject



57
58
59
# File 'lib/scrobbler/tag.rb', line 57

def top_albums
  call('tag.gettopalbums', :topalbums, Album, {:tag => @name})
end

#top_artistsObject

^ load_from_xml



53
54
55
# File 'lib/scrobbler/tag.rb', line 53

def top_artists
  call('tag.gettopartists', :topartists, Artist, {:tag => @name})
end

#top_tracksObject



61
62
63
# File 'lib/scrobbler/tag.rb', line 61

def top_tracks
  call('tag.gettoptracks', :toptracks, Track, {:tag => @name})
end

#weekly_artist_chartObject

Raises:

  • (NotImplementedError)


81
82
83
84
# File 'lib/scrobbler/tag.rb', line 81

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

#weekly_chart_listObject

Raises:

  • (NotImplementedError)


86
87
88
89
# File 'lib/scrobbler/tag.rb', line 86

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