class SierraApiResponse

Attributes

response[RW]

Public Class Methods

new(response) click to toggle source
# File lib/sierra_api_response.rb, line 4
def initialize(response)
  @response = response
end

Public Instance Methods

body() click to toggle source
# File lib/sierra_api_response.rb, line 20
def body
  return @response.body if @response.code == '204' 

  # If response Content-Type indicates body is json
  if /^application\/json/ =~ @response['Content-Type'] 
    begin
      JSON.parse(@response.body)
    rescue => e
      raise SierraApiResponseError.new(response), "Error parsing response (#{response.code}): #{response.body}"
    end
  else
    @response.body
  end
end
code() click to toggle source
# File lib/sierra_api_response.rb, line 8
def code
  @response.code.to_i
end
error?() click to toggle source
# File lib/sierra_api_response.rb, line 12
def error?
  code >= 400
end
success?() click to toggle source
# File lib/sierra_api_response.rb, line 16
def success?
  (200...300).include? code
end