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
# File 'lib/boxxspring/response.rb', line 9

def initialize( http_response )

  @code = http_response.code
  @content = decode_response_body( http_response )
  error = @content.respond_to?( :keys ) ? @content[ 'errors' ] : nil

  if @content.respond_to?( :include? ) && @content.include?( 'errors' )
    @error = 
      Boxxspring::Error.new( @content[ 'errors' ][ 'message' ] ) 
  end
  
  @success = 
    http_response.is_a?( Net::HTTPOK ) && 
    @content.present? &&
    @error.nil?
    
  @error = Boxxspring::Error.new( 'unknown' ) \
    if !@success && @error.nil?
    
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/boxxspring/response.rb', line 34

def failure?
  not @success
end

#success?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/boxxspring/response.rb', line 30

def success?
  @success
end