class Lastfm::Response

Attributes

xml[R]

Public Class Methods

new(body) click to toggle source
# File lib/lastfm/response.rb, line 8
def initialize(body)
  # workaround for https://github.com/youpy/ruby-lastfm/issues/83
  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'])
end

Public Instance Methods

error() click to toggle source
# File lib/lastfm/response.rb, line 26
def error
  @xml['error']['code'].to_i
end
message() click to toggle source
# File lib/lastfm/response.rb, line 22
def message
  @xml['error']['content']
end
success?() click to toggle source
# File lib/lastfm/response.rb, line 18
def success?
  @xml['status'] == 'ok'
end

Private Instance Methods

fix_body(body) click to toggle source
# File lib/lastfm/response.rb, line 32
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