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.
17 18 19 |
# File 'lib/smooth_operator/remote_call.rb', line 17 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
48 49 50 |
# File 'lib/smooth_operator/remote_call.rb', line 48 def data object.nil? ? parsed_response : object end |
#error? ⇒ Boolean
26 27 28 |
# File 'lib/smooth_operator/remote_call.rb', line 26 def error? http_status.between?(500, 599) end |
#failure? ⇒ Boolean
22 23 24 |
# File 'lib/smooth_operator/remote_call.rb', line 22 def failure? http_status.between?(400, 499) end |
#objects ⇒ Object
44 45 46 |
# File 'lib/smooth_operator/remote_call.rb', line 44 def objects object.respond_to?(:length) ? object : [] end |
#parsed_response ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/smooth_operator/remote_call.rb', line 30 def parsed_response require 'json' unless defined? JSON begin JSON.parse(body) rescue JSON::ParserError nil end end |
#status ⇒ Object
40 41 42 |
# File 'lib/smooth_operator/remote_call.rb', line 40 def status error? ? nil : success? end |