Class: LinkChecker::Net::HTTP::Result

Inherits:
Result
  • Object
show all
Defined in:
lib/ruby-link-checker/net/http/result.rb

Instance Attribute Summary collapse

Attributes inherited from Result

#checker, #method, #options, #result_uri, #uri

Instance Method Summary collapse

Methods inherited from Result

#error, #to_s

Constructor Details

#initialize(uri, method, original_uri, request, response, options) ⇒ Result

Returns a new instance of Result.



7
8
9
10
11
# File 'lib/ruby-link-checker/net/http/result.rb', line 7

def initialize(uri, method, original_uri, request, response, options)
  @request = request
  @response = response
  super uri, method, original_uri, options
end

Instance Attribute Details

#requestObject

Returns the value of attribute request.



5
6
7
# File 'lib/ruby-link-checker/net/http/result.rb', line 5

def request
  @request
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/ruby-link-checker/net/http/result.rb', line 5

def response
  @response
end

Instance Method Details

#codeObject



21
22
23
24
25
26
27
# File 'lib/ruby-link-checker/net/http/result.rb', line 21

def code
  @code ||= begin
    response.code.to_i
  rescue StandardError
    -1
  end
end

#error?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/ruby-link-checker/net/http/result.rb', line 13

def error?
  false
end

#failure?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ruby-link-checker/net/http/result.rb', line 17

def failure?
  !success? && !redirect?
end

#redirect?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/ruby-link-checker/net/http/result.rb', line 39

def redirect?
  return false unless response

  [301, 302, 303, 307, 308].include?(code)
end

#redirect_toObject



33
34
35
36
37
# File 'lib/ruby-link-checker/net/http/result.rb', line 33

def redirect_to
  return nil unless response

  response['Location']
end

#request_headersObject



29
30
31
# File 'lib/ruby-link-checker/net/http/result.rb', line 29

def request_headers
  request
end

#success?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/ruby-link-checker/net/http/result.rb', line 45

def success?
  return false unless response

  code >= 200 && code <= 299
end