Class: Url_status

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

Instance Method Summary collapse

Instance Method Details

#responsetime(url) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/url_status.rb', line 26

def responsetime(url)
  require 'net/http'
  require 'uri'
  if url=="" then
    @code="not url found"
  else
    begin
      start_time = Time.now
      res = Net::HTTP.get_response(URI(url))
      end_time = Time.now - start_time
    rescue
      @code="Incorrrect url"
    else
      
      @time=end_time
    ensure
      return @time

    end
  end

end

#status(url) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/url_status.rb', line 3

def status(url)
  require 'net/http'
  require 'uri'
  if url=="" then
    @code="not url found"
  else
    begin
     
      res = Net::HTTP.get_response(URI(url))
     
    rescue 
      @code="Incorrrect url"
    else
      @code=res.code
     
    ensure
      return @code
      
    end
  end

end