Class: Lastfm::Response
- Inherits:
-
Object
- Object
- Lastfm::Response
- Defined in:
- lib/lastfm/response.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #error ⇒ Object
-
#initialize(body) ⇒ Response
constructor
A new instance of Response.
- #message ⇒ Object
- #success? ⇒ Boolean
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 |
#error ⇒ Object
30 31 32 |
# File 'lib/lastfm/response.rb', line 30 def error self['error'] end |
#message ⇒ Object
26 27 28 |
# File 'lib/lastfm/response.rb', line 26 def self['message'] end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/lastfm/response.rb', line 22 def success? !self['error'] end |