Class: Rapuncel::Response
- Inherits:
-
Object
- Object
- Rapuncel::Response
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
#deserializer ⇒ Object
Returns the value of attribute deserializer.
9
10
11
|
# File 'lib/rapuncel/response.rb', line 9
def deserializer
@deserializer
end
|
#http_response ⇒ Object
Returns the value of attribute http_response.
9
10
11
|
# File 'lib/rapuncel/response.rb', line 9
def http_response
@http_response
end
|
#response ⇒ Object
Returns the value of attribute response.
9
10
11
|
# File 'lib/rapuncel/response.rb', line 9
def response
@response
end
|
#status ⇒ Object
Returns the value of attribute status.
9
10
11
|
# File 'lib/rapuncel/response.rb', line 9
def status
@status
end
|
#status_code ⇒ Object
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
#error ⇒ Object
52
53
54
|
# File 'lib/rapuncel/response.rb', line 52
def error
error? && { :http_code => @status_code, :http_body => body }
end
|
#error? ⇒ Boolean
44
45
46
|
# File 'lib/rapuncel/response.rb', line 44
def error?
status == 'error'
end
|
#evaluate_status ⇒ Object
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
|
#fault ⇒ Object
48
49
50
|
# File 'lib/rapuncel/response.rb', line 48
def fault
fault? && @response
end
|
#fault? ⇒ Boolean
40
41
42
|
# File 'lib/rapuncel/response.rb', line 40
def fault?
status == 'fault'
end
|
#result ⇒ Object
56
57
58
|
# File 'lib/rapuncel/response.rb', line 56
def result
success? && @response
end
|
#success? ⇒ Boolean
36
37
38
|
# File 'lib/rapuncel/response.rb', line 36
def success?
status == 'success'
end
|
#to_ruby ⇒ Object
60
61
62
|
# File 'lib/rapuncel/response.rb', line 60
def to_ruby
result || fault || error
end
|