Module: Checkurl

Defined in:
lib/checkurl.rb,
lib/checkurl/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.response_code(url) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/checkurl.rb', line 7

def response_code url
  begin
    url = URI(url.strip)
    response = Net::HTTP.get_response(url)

    return {code: response.code, message: response.message}
  rescue => e
    return "ERROR: #{e}"
  end
end

.working?(url) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/checkurl.rb', line 18

def working? url
  begin
    url = URI(url.strip)
    response = Net::HTTP.get_response(url)
    !%W(4 5).include?(response.code[0]) || response.code.to_i == 403 # 403 - for unauthorized access of resource
  rescue Errno::ENOENT
    false #false if can't find the server
  rescue => e
    false
  end
end