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
@headers
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
29
30
31
|
# File 'lib/smooth_operator/remote_call/base.rb', line 29
def client_error?
http_status.between?(400, 499)
end
|
#connection_failed? ⇒ Boolean
45
46
47
|
# File 'lib/smooth_operator/remote_call/base.rb', line 45
def connection_failed?
false
end
|
#data ⇒ Object
69
70
71
|
# File 'lib/smooth_operator/remote_call/base.rb', line 69
def data
object.nil? ? parsed_response : object
end
|
#error? ⇒ Boolean
25
26
27
|
# File 'lib/smooth_operator/remote_call/base.rb', line 25
def error?
!ok? && !not_processed?
end
|
#not_found? ⇒ Boolean
37
38
39
|
# File 'lib/smooth_operator/remote_call/base.rb', line 37
def not_found?
http_status == 404
end
|
#not_processed? ⇒ Boolean
21
22
23
|
# File 'lib/smooth_operator/remote_call/base.rb', line 21
def not_processed?
http_status == 422
end
|
#objects ⇒ Object
65
66
67
|
# File 'lib/smooth_operator/remote_call/base.rb', line 65
def objects
object.respond_to?(:length) ? object : []
end
|
#ok? ⇒ Boolean
17
18
19
|
# File 'lib/smooth_operator/remote_call/base.rb', line 17
def ok?
http_status.between?(200, 299) || http_status == 304
end
|
#parsed_response ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/smooth_operator/remote_call/base.rb', line 49
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
33
34
35
|
# File 'lib/smooth_operator/remote_call/base.rb', line 33
def server_error?
http_status.between?(500, 599) || http_status == 0
end
|
#status ⇒ Object
61
62
63
|
# File 'lib/smooth_operator/remote_call/base.rb', line 61
def status
error? ? nil : ok?
end
|
#timeout? ⇒ Boolean
41
42
43
|
# File 'lib/smooth_operator/remote_call/base.rb', line 41
def timeout?
false
end
|