Class: SmoothOperator::RemoteCall::Base
- Inherits:
-
Object
- Object
- SmoothOperator::RemoteCall::Base
- Extended by:
- Forwardable
- Defined in:
- lib/smooth_operator/remote_call/base.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #data ⇒ Object
- #error? ⇒ Boolean
- #failure? ⇒ Boolean
-
#initialize(response) ⇒ Base
constructor
A new instance of Base.
- #objects ⇒ Object
- #parsed_response ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(response) ⇒ Base
Returns a new instance of Base.
23 24 25 |
# File 'lib/smooth_operator/remote_call/base.rb', line 23 def initialize(response) @response = response end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
15 16 17 |
# File 'lib/smooth_operator/remote_call/base.rb', line 15 def object @object end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
13 14 15 |
# File 'lib/smooth_operator/remote_call/base.rb', line 13 def response @response end |
Instance Method Details
#data ⇒ Object
54 55 56 |
# File 'lib/smooth_operator/remote_call/base.rb', line 54 def data object.nil? ? parsed_response : object end |
#error? ⇒ Boolean
32 33 34 |
# File 'lib/smooth_operator/remote_call/base.rb', line 32 def error? http_status.between?(500, 599) end |
#failure? ⇒ Boolean
28 29 30 |
# File 'lib/smooth_operator/remote_call/base.rb', line 28 def failure? http_status.between?(400, 499) end |
#objects ⇒ Object
50 51 52 |
# File 'lib/smooth_operator/remote_call/base.rb', line 50 def objects object.respond_to?(:length) ? object : [] end |
#parsed_response ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/smooth_operator/remote_call/base.rb', line 36 def parsed_response require 'json' unless defined? JSON begin JSON.parse(body) rescue JSON::ParserError nil end end |
#status ⇒ Object
46 47 48 |
# File 'lib/smooth_operator/remote_call/base.rb', line 46 def status error? ? nil : success? end |