Class: SimpleSpotify::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/simplespotify/response.rb', line 4

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/simplespotify/response.rb', line 4

def code
  @code
end

#requestObject (readonly)

Returns the value of attribute request.



4
5
6
# File 'lib/simplespotify/response.rb', line 4

def request
  @request
end