Class: SmoothOperator::RemoteCall::Base
- Inherits:
-
Object
- Object
- SmoothOperator::RemoteCall::Base
- Extended by:
- Forwardable
- Defined in:
- lib/smooth_operator/remote_call.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, object_class = nil) ⇒ Base
constructor
A new instance of Base.
- #objects ⇒ Object
- #parsed_response ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(response, object_class = nil) ⇒ Base
Returns a new instance of Base.
19 20 21 |
# File 'lib/smooth_operator/remote_call.rb', line 19 def initialize(response, object_class = nil) @response, @object_class = response, object_class end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
11 12 13 |
# File 'lib/smooth_operator/remote_call.rb', line 11 def object @object end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/smooth_operator/remote_call.rb', line 9 def response @response end |
Instance Method Details
#data ⇒ Object
50 51 52 |
# File 'lib/smooth_operator/remote_call.rb', line 50 def data object.nil? ? parsed_response : object end |
#error? ⇒ Boolean
28 29 30 |
# File 'lib/smooth_operator/remote_call.rb', line 28 def error? http_status.between?(500, 599) end |
#failure? ⇒ Boolean
24 25 26 |
# File 'lib/smooth_operator/remote_call.rb', line 24 def failure? http_status.between?(400, 499) end |
#objects ⇒ Object
46 47 48 |
# File 'lib/smooth_operator/remote_call.rb', line 46 def objects object.respond_to?(:length) ? object : [] end |
#parsed_response ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/smooth_operator/remote_call.rb', line 32 def parsed_response require 'json' unless defined? JSON begin JSON.parse(body) rescue JSON::ParserError nil end end |
#status ⇒ Object
42 43 44 |
# File 'lib/smooth_operator/remote_call.rb', line 42 def status error? ? nil : success? end |