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.



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

def initialize(response)
  @response = response
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



10
11
12
# File 'lib/smooth_operator/remote_call/base.rb', line 10

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



10
11
12
# File 'lib/smooth_operator/remote_call/base.rb', line 10

def headers
  @headers
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



10
11
12
# File 'lib/smooth_operator/remote_call/base.rb', line 10

def http_status
  @http_status
end

#objectObject

Returns the value of attribute object.



12
13
14
# File 'lib/smooth_operator/remote_call/base.rb', line 12

def object
  @object
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/smooth_operator/remote_call/base.rb', line 10

def response
  @response
end

Instance Method Details

#client_error?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/smooth_operator/remote_call/base.rb', line 30

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

#connection_failed?Boolean

Returns:

  • (Boolean)


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

def connection_failed?
  false
end


70
71
72
# File 'lib/smooth_operator/remote_call/base.rb', line 70

def cookie(header_field = 'set-cookie')
  CookieJar.new.parse(headers[header_field])
end

#dataObject



66
67
68
# File 'lib/smooth_operator/remote_call/base.rb', line 66

def data
  object.nil? ? parsed_response : object
end

#error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/smooth_operator/remote_call/base.rb', line 26

def error?
  !ok? && !not_processed?
end

#not_found?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/smooth_operator/remote_call/base.rb', line 38

def not_found?
  http_status == 404
end

#not_processed?Boolean

Returns:

  • (Boolean)


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

def not_processed?
  http_status == 422
end

#ok?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/smooth_operator/remote_call/base.rb', line 18

def ok?
  http_status.between?(200, 299) || http_status == 304
end

#parsed_responseObject



50
51
52
53
54
55
56
57
58
59
60
# 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?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/smooth_operator/remote_call/base.rb', line 34

def server_error?
  http_status.between?(500, 599) || http_status == 0
end

#statusObject



62
63
64
# File 'lib/smooth_operator/remote_call/base.rb', line 62

def status
  error? ? nil : ok?
end

#timeout?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/smooth_operator/remote_call/base.rb', line 42

def timeout?
  false
end