Class: Knowtify::Response

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

Constant Summary collapse

ERROR_HTTP_CODES =
[500,501,502,503,504,505,429,0].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count = 0) ⇒ Response

Returns a new instance of Response.



10
11
12
# File 'lib/knowtify/response.rb', line 10

def initialize(count=0)
  @count = count || 0
end

Instance Attribute Details

#bodyObject

String - body from HTTP request



3
4
5
# File 'lib/knowtify/response.rb', line 3

def body
  @body
end

#countObject

String - body from HTTP request



3
4
5
# File 'lib/knowtify/response.rb', line 3

def count
  @count
end

#http_codeObject

String - body from HTTP request



3
4
5
# File 'lib/knowtify/response.rb', line 3

def http_code
  @http_code
end

#raw_responseObject

String - body from HTTP request



3
4
5
# File 'lib/knowtify/response.rb', line 3

def raw_response
  @raw_response
end

Instance Method Details

#authentication_error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/knowtify/response.rb', line 26

def authentication_error?
  http_code == 401
end

#retried?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/knowtify/response.rb', line 18

def retried?
  count != 0
end

#retry?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/knowtify/response.rb', line 14

def retry?
  (((count + 1) <= Knowtify.config.max_retries) && ERROR_HTTP_CODES.include?(http_code))
end

#successful?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/knowtify/response.rb', line 22

def successful?
  http_code == 200
end