Class: Rapuncel::Response

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

Defined Under Namespace

Classes: Error, Exception, Fault

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response, deserializer) ⇒ Response

Returns a new instance of Response.



14
15
16
17
18
# File 'lib/rapuncel/response.rb', line 14

def initialize http_response, deserializer
  @http_response, @deserializer = http_response, deserializer
  
  evaluate_status
end

Instance Attribute Details

#deserializerObject

Returns the value of attribute deserializer.



9
10
11
# File 'lib/rapuncel/response.rb', line 9

def deserializer
  @deserializer
end

#http_responseObject

Returns the value of attribute http_response.



9
10
11
# File 'lib/rapuncel/response.rb', line 9

def http_response
  @http_response
end

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/rapuncel/response.rb', line 9

def response
  @response
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/rapuncel/response.rb', line 9

def status
  @status
end

#status_codeObject

Returns the value of attribute status_code.



9
10
11
# File 'lib/rapuncel/response.rb', line 9

def status_code
  @status_code
end

Instance Method Details

#errorObject



52
53
54
# File 'lib/rapuncel/response.rb', line 52

def error
  error? && { :http_code => @status_code, :http_body => body }
end

#error?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rapuncel/response.rb', line 44

def error?
  status == 'error'
end

#evaluate_statusObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rapuncel/response.rb', line 20

def evaluate_status
  @status_code = http_response.code.to_i

  @status = unless http_response.success?
    'error'
  else
    deserialize_response
    
    if Hash === response && response[:faultCode]
      'fault'
    else
      'success'
    end
  end
end

#faultObject



48
49
50
# File 'lib/rapuncel/response.rb', line 48

def fault
  fault? && @response
end

#fault?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rapuncel/response.rb', line 40

def fault?
  status == 'fault'
end

#resultObject



56
57
58
# File 'lib/rapuncel/response.rb', line 56

def result
  success? && @response
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  status == 'success'
end

#to_rubyObject



60
61
62
# File 'lib/rapuncel/response.rb', line 60

def to_ruby
  result || fault || error
end