Class: SimpleSpotify::Response
- Inherits:
-
Object
- Object
- SimpleSpotify::Response
- Defined in:
- lib/simplespotify/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#initialize(code, body, request) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(code, body, request) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/simplespotify/response.rb', line 6 def initialize code, body, request @code = code @request = request if (200..299).include? code begin @body = JSON.parse(body, symbolize_names: true) rescue raise SimpleSpotify::Error::BadResponse.new(code, body, request) end else body = JSON.parse(body, symbolize_names: true) rescue nil raise SimpleSpotify::Error.for(code).new(code, body, request) end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/simplespotify/response.rb', line 4 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/simplespotify/response.rb', line 4 def code @code end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
4 5 6 |
# File 'lib/simplespotify/response.rb', line 4 def request @request end |