Class: BadLinkFinder::Link
- Inherits:
-
Object
- Object
- BadLinkFinder::Link
- Defined in:
- lib/bad_link_finder/link.rb
Instance Attribute Summary collapse
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(page_url, link) ⇒ Link
constructor
A new instance of Link.
- #valid? ⇒ Boolean
Constructor Details
#initialize(page_url, link) ⇒ Link
Returns a new instance of Link.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bad_link_finder/link.rb', line 7 def initialize(page_url, link) @page_url = page_url @link = link @url = get_url_from_link(link) verify_url(@url) validate_with_request rescue URI::InvalidURIError => exception record_error("This link is in a bad format", exception) rescue Mechanize::ResponseCodeError => exception if [405, 500].include?(exception.response_code.to_i) && !@head_unsupported @head_unsupported = true retry else record_error("This request returned a #{exception.response_code}", exception) end rescue Mechanize::UnauthorizedError => exception record_error("This link requires authorisation", exception) rescue Mechanize::UnsupportedSchemeError => exception record_error("This link has a scheme we can't load (should be http or https)", exception) rescue Mechanize::RedirectLimitReachedError => exception record_error("This link might be in a redirect loop", exception) rescue Mechanize::RobotsDisallowedError => exception record_error("This link is blocked by robots.txt or nofollow attributes", exception) rescue Mechanize::Error, Net::HTTP::Persistent::Error, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError, SocketError => exception # Thanks Net::HTTP record_error("The server failed to serve this page properly", exception) end |
Instance Attribute Details
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
5 6 7 |
# File 'lib/bad_link_finder/link.rb', line 5 def @error_message end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
5 6 7 |
# File 'lib/bad_link_finder/link.rb', line 5 def exception @exception end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
5 6 7 |
# File 'lib/bad_link_finder/link.rb', line 5 def link @link end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/bad_link_finder/link.rb', line 5 def url @url end |
Instance Method Details
#valid? ⇒ Boolean
38 39 40 |
# File 'lib/bad_link_finder/link.rb', line 38 def valid? @error_message.nil? end |