Class: Boxxspring::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/boxxspring/response.rb', line 9

def initialize( http_response )

  @success = http_response.is_a?( Net::HTTPOK )

  @code = http_response.code
  @resources = []

  content = decode_response_body( http_response )
  if ( content && content.respond_to?( :keys ) )
    Boxxspring::Parser.new( content ) do | parser |
      @resources = parser.resources
      @success = !parser.type_name?( :error )
    end
  else
    @success = false
    @resources << Boxxspring::Error.new( 
      message: "An unknown error occured (#{@code})."
    )
  end
  @body = content
                  
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/boxxspring/response.rb', line 6

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/boxxspring/response.rb', line 5

def code
  @code
end

#resourcesObject (readonly)

Returns the value of attribute resources.



7
8
9
# File 'lib/boxxspring/response.rb', line 7

def resources
  @resources
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/boxxspring/response.rb', line 36

def failure?
  not @success
end

#success?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/boxxspring/response.rb', line 32

def success?
  @success
end