isup 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/isup.rb +33 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTAwYjE5Y2U3YTIwZGIyMGI3ZTRkODBkZDE1MzY0NzYzZDQ3Y2VlMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWQ3MDUzOTU0MWU4NjFjMTQxMTc3MGU1OWUxZDM1Y2I1ZmU1ZTRmMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjMwNDNhYThkZjgyMWMxNTAyNDYxZDQxNDFiOGI3NDFhNmUxMzNiNmY2N2Y2
|
10
|
+
ZGUyOTllMTgyOWJhOTZmZGE2YWZiY2NhMGU3MWRjNjA2YTI1MjkxZWFjYjNm
|
11
|
+
YmNhYTU4ZjE1MTYxZmIyMGI0MmIzMGI5NTc5YzU1YjQ5MGE3MGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWYwMTI1YjYwYmIyODM2NzUxM2U3YzU0YWIzYzVlMTU1YWIyMTBhZTQwM2Nh
|
14
|
+
MTQ4ZGQ3OTFlYjFiNjNmNGI5ZmJkNmExZDRiY2Q4YzQwNmM4MjhhZmEyMTM1
|
15
|
+
MTYxZTJmZDJiOGU0ZWJmYWUwMjRkZDJkM2UxODJhM2JiZDk3ZDg=
|
data/lib/isup.rb
CHANGED
@@ -16,37 +16,50 @@ class Isup
|
|
16
16
|
|
17
17
|
# Checks whether the url that's been inputed is valid.
|
18
18
|
def valid?
|
19
|
+
if !(@url.include? 'http://')
|
20
|
+
@url = "http://" + @url
|
21
|
+
end
|
19
22
|
@parsed = URI.parse(@url)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
begin
|
24
|
+
@parsed.kind_of?(URI::HTTP)
|
25
|
+
rescue URI::BadURIError
|
26
|
+
false
|
27
|
+
rescue URI::InvalidURIError
|
28
|
+
false
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
# Calls fetch() and then prints whether the site is UP or DOWN.
|
28
33
|
def up?
|
29
34
|
fetch(@url)
|
30
|
-
puts "#{@
|
31
|
-
puts "#{@
|
35
|
+
puts "#{@url} is UP" if @up == true
|
36
|
+
puts "#{@url} is DOWN" if @up != true
|
32
37
|
end
|
33
38
|
|
34
39
|
# Checks the url, follows redirects, and then outputs the result.
|
35
40
|
def fetch(uri_str, limit = 10)
|
36
41
|
raise ArgumentError, 'Unable to complete the lookup.' if limit == 0
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
begin
|
43
|
+
@response = Net::HTTP.get_response(URI(uri_str))
|
44
|
+
rescue SocketError
|
45
|
+
false
|
46
|
+
rescue Errno::ECONNRESET
|
47
|
+
@up = true
|
48
|
+
false
|
49
|
+
else
|
50
|
+
case @response
|
51
|
+
when Net::HTTPSuccess then
|
52
|
+
@up = true
|
53
|
+
when Net::HTTPClientError then
|
54
|
+
@up = false
|
55
|
+
when Net::HTTPServerError then
|
56
|
+
@up = false
|
57
|
+
when Net::HTTPRedirection then
|
58
|
+
@location = @response['location']
|
59
|
+
fetch(@location, limit - 1)
|
60
|
+
else
|
61
|
+
warn "Unable to complete the request."
|
62
|
+
end
|
50
63
|
end
|
51
64
|
end
|
52
65
|
|