Class: SmoothOperator::RemoteCall::Base
- Inherits:
-
Object
- Object
- SmoothOperator::RemoteCall::Base
- Extended by:
- Forwardable
- Defined in:
- lib/smooth_operator/remote_call/base.rb
Direct Known Subclasses
Errors::ConnectionFailed, Errors::Timeout, Faraday, Typhoeus
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
-
#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
- #success? ⇒ Boolean (also: #ok?)
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 (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/smooth_operator/remote_call/base.rb', line 9 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/smooth_operator/remote_call/base.rb', line 9 def headers @headers end |
#http_status ⇒ Object (readonly)
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 (readonly)
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
#data ⇒ Object
52 53 54 |
# File 'lib/smooth_operator/remote_call/base.rb', line 52 def data object.nil? ? parsed_response : object end |
#error? ⇒ Boolean
28 29 30 |
# File 'lib/smooth_operator/remote_call/base.rb', line 28 def error? http_status.between?(500, 599) || http_status == 0 end |
#failure? ⇒ Boolean
24 25 26 |
# File 'lib/smooth_operator/remote_call/base.rb', line 24 def failure? http_status.between?(400, 499) end |
#objects ⇒ Object
48 49 50 |
# File 'lib/smooth_operator/remote_call/base.rb', line 48 def objects object.respond_to?(:length) ? object : [] end |
#parsed_response ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/smooth_operator/remote_call/base.rb', line 32 def parsed_response return nil if body.nil? require 'json' unless defined? JSON begin JSON.parse(body) rescue JSON::ParserError nil end end |
#status ⇒ Object
44 45 46 |
# File 'lib/smooth_operator/remote_call/base.rb', line 44 def status error? ? nil : success? end |
#success? ⇒ Boolean Also known as: ok?
18 19 20 |
# File 'lib/smooth_operator/remote_call/base.rb', line 18 def success? http_status.between?(200, 299) end |