Class: Rox::Core::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rox/core/network/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, text, content_type = 'application/octet-stream') ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
# File 'lib/rox/core/network/response.rb', line 9

def initialize(status_code, text, content_type = 'application/octet-stream')
  @status_code = status_code
  @text = text
  @content_type = content_type
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



7
8
9
# File 'lib/rox/core/network/response.rb', line 7

def content_type
  @content_type
end

#status_codeObject

Returns the value of attribute status_code.



7
8
9
# File 'lib/rox/core/network/response.rb', line 7

def status_code
  @status_code
end

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/rox/core/network/response.rb', line 7

def text
  @text
end

Instance Method Details

#missing_via_response_body?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/rox/core/network/response.rb', line 23

def missing_via_response_body?
  # api send state respons returns 200 'OK', application/json filters it
  @status_code == 200 && @content_type == 'application/json' && @text && [404, '404'].include?(JSON.parse(text)['result'])
rescue JSON::ParserError
  Logging.logger.error("Failed to parse JSON response: #{text}")
  false
end

#status_code_success?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rox/core/network/response.rb', line 19

def status_code_success?
  @status_code >= 200 && @status_code < 300
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rox/core/network/response.rb', line 15

def success?
  status_code_success? && !missing_via_response_body?
end