Class: Lastfm::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/lastfm/response.rb', line 6

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
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  @parsed_body[key]
end

#errorObject



30
31
32
# File 'lib/lastfm/response.rb', line 30

def error
  self['error']
end

#messageObject



26
27
28
# File 'lib/lastfm/response.rb', line 26

def message
  self['message']
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  !self['error']
end