class SmoothOperator::RemoteCall::Base

Attributes

body[R]
headers[R]
http_status[R]
object[RW]
response[R]

Public Class Methods

new(response) click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 14
def initialize(response)
  @response = response
end

Public Instance Methods

client_error?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 30
def client_error?
  http_status.between?(400, 499)
end
connection_failed?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 46
def connection_failed?
  false
end
data() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 66
def data
  object.nil? ? parsed_response : object
end
error?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 26
def error?
  !ok? && !not_processed?
end
not_found?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 38
def not_found?
  http_status == 404
end
not_processed?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 22
def not_processed?
  http_status == 422
end
ok?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 18
def ok?
  http_status.between?(200, 299) || http_status == 304
end
parsed_response() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 50
def parsed_response
  return nil if body.nil?

  require 'json' unless defined? JSON

  begin
    JSON.parse(body)
  rescue JSON::ParserError
    body
  end
end
server_error?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 34
def server_error?
  http_status.between?(500, 599) || http_status == 0
end
status() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 62
def status
  error? ? nil : ok?
end
timeout?() click to toggle source
# File lib/smooth_operator/remote_call/base.rb, line 42
def timeout?
  false
end