lib/lastfm/response.rb in lastfm-0.0.1 vs lib/lastfm/response.rb in lastfm-0.1.0

- old
+ new

@@ -1,34 +1,24 @@ require 'rubygems' -require 'json' +require 'xmlsimple' class Lastfm class Response + attr_reader :xml + def initialize(body) - # API returns XML response when no child node? - if body == '<?xml version="1.0" encoding="utf-8"?> -<lfm status="ok"> -</lfm> -' - @parsed_body = {} - else - @parsed_body = JSON.parse(body) - end + @xml = XmlSimple.xml_in(body, 'ForceArray' => ['image', 'tag', 'user', 'event']) end - def [](key) - @parsed_body[key] - end - def success? - !self['error'] + @xml['status'] == 'ok' end def message - self['message'] + @xml['error']['content'] end def error - self['error'] + @xml['error']['code'].to_i end end end