Class: Lastfm::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/lastfm/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Response

Returns a new instance of Response


8
9
10
11
12
# File 'lib/lastfm/response.rb', line 8

def initialize(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

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml


6
7
8
# File 'lib/lastfm/response.rb', line 6

def xml
  @xml
end

Instance Method Details

#errorObject


22
23
24
# File 'lib/lastfm/response.rb', line 22

def error
  @xml['error']['code'].to_i
end

#messageObject


18
19
20
# File 'lib/lastfm/response.rb', line 18

def message
  @xml['error']['content']
end

#success?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/lastfm/response.rb', line 14

def success?
  @xml['status'] == 'ok'
end