Skip to content

Commit

Permalink
Allowing artist to be looked up by mbid
Browse files Browse the repository at this point in the history
  • Loading branch information
johnu authored and bitboxer committed Aug 6, 2011
1 parent 19c83ee commit f2a291f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/rockstar/artist.rb
Expand Up @@ -77,17 +77,21 @@ def new_from_xml(xml, doc=nil)
end
end

def initialize(name, o={})
raise ArgumentError, "Name is required" if name.blank?
@name = name
def initialize(o={})
raise ArgumentError, "Name or mbid is required" if o[:name].nil? && o[:mbid].nil?

@name = o[:name] unless o[:name].nil?
@mbid = o[:mbid] unless o[:mbid].nil?

options = {:include_info => false}.merge(o)
load_info if options[:include_info]
end

def load_info(xml=nil)
unless xml
doc = self.class.fetch_and_parse("artist.getInfo", {:artist => @name})
params = @mbid.nil? ? {:artist => @name} : {:mbid => @mbid}

doc = self.class.fetch_and_parse("artist.getInfo", params)
xml = (doc / :artist).first
end

Expand Down

0 comments on commit f2a291f

Please sign in to comment.