class CassetteRack::Response

Attributes

body[R]
content[R]
headers[R]
status[R]

Public Class Methods

new(res) click to toggle source
# File lib/cassette-rack/response.rb, line 5
def initialize(res)
  @response = res
  @status = res.status
  @headers = res.headers
  @body = res.body
  parse_content
end

Public Instance Methods

permit(*keys) click to toggle source
# File lib/cassette-rack/response.rb, line 25
def permit(*keys)
  case content
  when Hash
    content.select { |key| keys.include? key }
  when Array
    content.map { |item| item.select { |key| keys.include? key } }
  end
end
response_headers() click to toggle source
# File lib/cassette-rack/response.rb, line 17
def response_headers
  headers
end
status_code() click to toggle source
# File lib/cassette-rack/response.rb, line 13
def status_code
  status
end
success?() click to toggle source
# File lib/cassette-rack/response.rb, line 21
def success?
  @response.success?
end

Private Instance Methods

parse_content() click to toggle source
# File lib/cassette-rack/response.rb, line 35
def parse_content
  case body
  when nil, '', ' '
    @content = nil
  when 'true'
    @content = true
  when 'false'
    @content = false
  else
    if @response.env.request_headers['accept'] == 'application/json'
      @content = JSON.parse(body)
    else
      @content = body
    end
  end
rescue
  @content = body
end