Class: CassetteRack::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/cassette-rack/response.rb,
lib/cassette-rack/response/raise_error.rb

Defined Under Namespace

Classes: Error, RaiseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
# 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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/cassette-rack/response.rb', line 3

def body
  @body
end

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/cassette-rack/response.rb', line 3

def content
  @content
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/cassette-rack/response.rb', line 3

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/cassette-rack/response.rb', line 3

def status
  @status
end

Instance Method Details

#permit(*keys) ⇒ Object



25
26
27
28
29
30
31
32
# 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_headersObject



17
18
19
# File 'lib/cassette-rack/response.rb', line 17

def response_headers
  headers
end

#status_codeObject



13
14
15
# File 'lib/cassette-rack/response.rb', line 13

def status_code
  status
end

#success?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cassette-rack/response.rb', line 21

def success?
  @response.success?
end