Class: EchoNest::Artist
- Inherits:
-
Object
- Object
- EchoNest::Artist
- Defined in:
- lib/echonest/artist.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id = nil) ⇒ Artist
constructor
A new instance of Artist.
Constructor Details
#initialize(id = nil) ⇒ Artist
Returns a new instance of Artist.
6 7 8 |
# File 'lib/echonest/artist.rb', line 6 def initialize(id=nil) @id = id if id end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/echonest/artist.rb', line 4 def id @id end |
Class Method Details
.find(query, options = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/echonest/artist.rb', line 54 def self.find(query, ={}) = {:query => query}.merge() request = ApiRequest.new("search_artists", ) results = Xml::ArtistSearchResults.parse(request.fetch) results.artists end |
.service(name, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/echonest/artist.rb', line 10 def self.service(name, = {}) define_method "get_#{name.to_s}" do |*args| = args[0] if args.length == 1 = {:id => id}.merge() request = ApiRequest.new("get_#{name.to_s}", ) "Xml::#{name.to_s.titleize}Result".constantize.parse request.fetch end if ![:singular] define_method name do return instance_variable_get("@#{name.to_s}") if instance_variable_get("@#{name.to_s}") result = self.send("get_#{name.to_s}") pager = Proc.new { |start, rows| self.send("get_#{name.to_s}", :start => start, :rows => rows).results } page = PagedResult.new result.results, pager instance_variable_set("@#{name.to_s}", page) end else if ![:provides] define_method name do return instance_variable_get("@#{name.to_s}") if instance_variable_get("@#{name.to_s}") result = self.send("get_#{name.to_s}") instance_variable_set("@#{name.to_s}", result.artist.send(name)) end else define_method name do return instance_variable_get("@#{name.to_s}") if instance_variable_get("@#{name.to_s}") result = self.send("get_#{name.to_s}") instance_variable_set("@#{name.to_s}", result.artist) end [:provides].each do |prop| define_method prop do return instance_variable_get("@#{prop.to_s}") if instance_variable_get("@#{prop.to_s}") instance_variable_set("@#{prop.to_s}", self.send(name).send(prop)) end end end end end |