lib/lastfm/response.rb in lastfm-1.27.1 vs lib/lastfm/response.rb in lastfm-1.27.2
- old
+ new
@@ -4,14 +4,16 @@
class Lastfm
class Response
attr_reader :xml
def initialize(body)
+ body = fix_body(body)
+
@xml = XmlSimple.xml_in(body, 'ForceArray' => ['image', 'tag', 'user', 'event', 'correction'])
rescue REXML::ParseException
- @xml = XmlSimple.xml_in(body.encode(Encoding.find("ISO-8859-1"), :undef => :replace),
- 'ForceArray' => ['image', 'tag', 'user', 'event', 'correction'])
+ @xml = XmlSimple.xml_in(body.encode(Encoding.find("ISO-8859-1"), :undef => :replace),
+ 'ForceArray' => ['image', 'tag', 'user', 'event', 'correction'])
end
def success?
@xml['status'] == 'ok'
end
@@ -20,8 +22,22 @@
@xml['error']['content']
end
def error
@xml['error']['code'].to_i
+ end
+
+ private
+
+ def fix_body(body)
+ namespace_attr = 'xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"'
+
+ body.sub(/(<results[^>]*)/) do |str|
+ if str.match(namespace_attr)
+ str
+ else
+ '%s %s' % [str, namespace_attr]
+ end
+ end
end
end
end