Class: SmoothOperator::RemoteCall::Base

Inherits:
Object
  • Object
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.



23
24
25
# File 'lib/smooth_operator/remote_call/base.rb', line 23

def initialize(response)
  @response = response
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



15
16
17
# File 'lib/smooth_operator/remote_call/base.rb', line 15

def object
  @object
end

#responseObject (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

#dataObject



54
55
56
# File 'lib/smooth_operator/remote_call/base.rb', line 54

def data
  object.nil? ? parsed_response : object
end

#error?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/smooth_operator/remote_call/base.rb', line 32

def error?
  http_status.between?(500, 599)
end

#failure?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/smooth_operator/remote_call/base.rb', line 28

def failure?
  http_status.between?(400, 499)
end

#objectsObject



50
51
52
# File 'lib/smooth_operator/remote_call/base.rb', line 50

def objects
  object.respond_to?(:length) ? object : []
end

#parsed_responseObject



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

#statusObject



46
47
48
# File 'lib/smooth_operator/remote_call/base.rb', line 46

def status
  error? ? nil : success?
end