link_checker 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/link_checker.rb +3 -3
- data/lib/link_checker/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
data/lib/link_checker.rb
CHANGED
@@ -3,14 +3,14 @@ require 'net/http'
|
|
3
3
|
|
4
4
|
# Checks whether URL is accessible, following up to 10 redirects.
|
5
5
|
# Example:
|
6
|
-
# LinkChecker.new('http://example.com').
|
6
|
+
# LinkChecker.new('http://example.com').accessible?
|
7
7
|
class LinkChecker
|
8
8
|
def initialize(uri_str, limit = 10)
|
9
9
|
@uri_str, @limit = uri_str, limit
|
10
10
|
@uri_str = "http://#{@uri_str}" unless @uri_str.include?('://')
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def accessible?
|
14
14
|
return false if @limit == 0
|
15
15
|
uri = URI(@uri_str)
|
16
16
|
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
@@ -25,7 +25,7 @@ class LinkChecker
|
|
25
25
|
host_with_protocol = @uri_str[/^[^\:]+\:\/\/[^\/]+/, 0]
|
26
26
|
location = host_with_protocol + location
|
27
27
|
end
|
28
|
-
self.class.new(location, @limit - 1).
|
28
|
+
self.class.new(location, @limit - 1).accessible?
|
29
29
|
else
|
30
30
|
false
|
31
31
|
end
|
data/lib/link_checker/version.rb
CHANGED