Class: SmoothOperator::RemoteCall::Base
- Inherits:
-
Object
- Object
- SmoothOperator::RemoteCall::Base
show all
- Extended by:
- Forwardable
- Defined in:
- lib/smooth_operator/remote_call/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response) ⇒ Base
Returns a new instance of Base.
13
14
15
|
# File 'lib/smooth_operator/remote_call/base.rb', line 13
def initialize(response)
@response = response
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
9
10
11
|
# File 'lib/smooth_operator/remote_call/base.rb', line 9
def body
@body
end
|
Returns the value of attribute headers.
9
10
11
|
# File 'lib/smooth_operator/remote_call/base.rb', line 9
def
end
|
#http_status ⇒ Object
Returns the value of attribute http_status.
9
10
11
|
# File 'lib/smooth_operator/remote_call/base.rb', line 9
def http_status
@http_status
end
|
#object ⇒ Object
Returns the value of attribute object.
11
12
13
|
# File 'lib/smooth_operator/remote_call/base.rb', line 11
def object
@object
end
|
#response ⇒ Object
Returns the value of attribute response.
9
10
11
|
# File 'lib/smooth_operator/remote_call/base.rb', line 9
def response
@response
end
|
Instance Method Details
#client_error? ⇒ Boolean
30
31
32
|
# File 'lib/smooth_operator/remote_call/base.rb', line 30
def client_error?
http_status.between?(400, 499)
end
|
#connection_failed? ⇒ Boolean
47
48
49
|
# File 'lib/smooth_operator/remote_call/base.rb', line 47
def connection_failed?
false
end
|
#data ⇒ Object
72
73
74
|
# File 'lib/smooth_operator/remote_call/base.rb', line 72
def data
object.nil? ? parsed_response : object
end
|
#error? ⇒ Boolean
26
27
28
|
# File 'lib/smooth_operator/remote_call/base.rb', line 26
def error?
!ok? && !not_processed?
end
|
#not_found? ⇒ Boolean
39
40
41
|
# File 'lib/smooth_operator/remote_call/base.rb', line 39
def not_found?
http_status == 404
end
|
#not_processed? ⇒ Boolean
22
23
24
|
# File 'lib/smooth_operator/remote_call/base.rb', line 22
def not_processed?
http_status == 422
end
|
#objects ⇒ Object
68
69
70
|
# File 'lib/smooth_operator/remote_call/base.rb', line 68
def objects
object.respond_to?(:length) ? object : []
end
|
#ok? ⇒ Boolean
18
19
20
|
# File 'lib/smooth_operator/remote_call/base.rb', line 18
def ok?
http_status.between?(200, 299) || http_status == 304
end
|
#parsed_response ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/smooth_operator/remote_call/base.rb', line 52
def parsed_response
return nil if body.nil?
require 'json' unless defined? JSON
begin
JSON.parse(body)
rescue JSON::ParserError
nil
end
end
|
#server_error? ⇒ Boolean
34
35
36
|
# File 'lib/smooth_operator/remote_call/base.rb', line 34
def server_error?
http_status.between?(500, 599) || http_status == 0
end
|
#status ⇒ Object
64
65
66
|
# File 'lib/smooth_operator/remote_call/base.rb', line 64
def status
error? ? nil : ok?
end
|
#timeout? ⇒ Boolean
43
44
45
|
# File 'lib/smooth_operator/remote_call/base.rb', line 43
def timeout?
false
end
|