Class: CortexClient::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/cortex_client/http/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
# File 'lib/cortex_client/http/response.rb', line 6

def initialize(http_response)
  @response_code = http_response.code
  @body = http_response.body
  @http_response = http_response
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/cortex_client/http/response.rb', line 4

def body
  @body
end

#response_codeObject (readonly)

Returns the value of attribute response_code.



4
5
6
# File 'lib/cortex_client/http/response.rb', line 4

def response_code
  @response_code
end

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/cortex_client/http/response.rb', line 20

def accepted?
  @response_code == 202
end

#bad_request?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/cortex_client/http/response.rb', line 24

def bad_request?
  @response_code == 400
end

#created?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/cortex_client/http/response.rb', line 16

def created?
  @response_code == 201
end

#forbidden?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cortex_client/http/response.rb', line 28

def forbidden?
  @response_code == 403
end

#network_error?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/cortex_client/http/response.rb', line 55

def network_error?
  server_error_codes = [502, 503, 504]

  server_error_codes.include?(@response_code)
end

#not_found?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cortex_client/http/response.rb', line 36

def not_found?
  @response_code == 404
end

#ok?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/cortex_client/http/response.rb', line 12

def ok?
  @response_code == 200
end

#server_error?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/cortex_client/http/response.rb', line 49

def server_error?
  server_error_codes = [500, 502, 503, 504]

  server_error_codes.include?(@response_code)
end

#successful?Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/cortex_client/http/response.rb', line 44

def successful?
  successful_codes = [200, 201, 202]
  successful_codes.include?(@response_code)
end

#unauthorized?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cortex_client/http/response.rb', line 32

def unauthorized?
  @response_code == 401
end

#unprocessable_entity?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cortex_client/http/response.rb', line 40

def unprocessable_entity?
  @response_code == 422
end