isup 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/isup.rb +27 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDUzYjY0NDFiMzk2NjIyZjk2MjJmNzQ3MDI2ZjllN2FlMTUzZWYwYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yjc1YmVmNzJlZThkNWFhN2RiM2VkNzMwMjkwZWM4ODkwNGIyMWZlYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTM4ZTcxYmFlYWQ3YzkwY2FmYzRhNGNmYTYyZGQ2MTI4YWI0NzA5Y2EwMTg2
|
10
|
+
YTc3MTdmNzBjNTVkM2Q0N2Y0ZGRlNjQyMzJmODQ3OGMwOTBkMmNiYmVlMDk5
|
11
|
+
MDIwN2I1ZmQyMzQ2MmM2OTZhNjA2MDU5YWQ5MzdmZWEzOTM1OWI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDllM2ZlMjZiY2EzOGQwYWFlYTE0MTYwNzM4ZmVhOGRjMjQ3MmNhZmMwYjk3
|
14
|
+
ZTUyMTNjN2UwODgyYzU0MWJjNGYzZTFmMTM2ZWE4OTQzNDg1MzBkMmNiMTQ4
|
15
|
+
ZjQ1Y2RiZGNhMTIwNGNjZTcxNDZhMGEwNGNkYjM5ZDdkYjQ3NTE=
|
data/lib/isup.rb
CHANGED
@@ -5,21 +5,43 @@ class Isup
|
|
5
5
|
|
6
6
|
def initialize(url)
|
7
7
|
@url = url
|
8
|
-
|
8
|
+
if valid?
|
9
|
+
up?
|
10
|
+
else
|
11
|
+
puts "Please input a valid URL"
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
|
-
|
15
|
+
private
|
16
|
+
|
17
|
+
# Checks whether the url that's been inputed is valid.
|
18
|
+
def valid?
|
19
|
+
@parsed = URI.parse(@url)
|
20
|
+
@parsed.kind_of?(URI::HTTP)
|
21
|
+
rescue URI::BadURIError
|
22
|
+
false
|
23
|
+
rescue URI::InvalidURIError
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
# Calls fetch() and then prints whether the site is UP or DOWN.
|
28
|
+
def up?
|
29
|
+
fetch(@url)
|
30
|
+
puts "#{@location} is UP" if @up == true
|
31
|
+
puts "#{@location} is DOWN" if @up != true
|
32
|
+
end
|
12
33
|
|
34
|
+
# Checks the url, follows redirects, and then outputs the result.
|
13
35
|
def fetch(uri_str, limit = 10)
|
14
36
|
raise ArgumentError, 'Unable to complete the lookup.' if limit == 0
|
15
37
|
@response = Net::HTTP.get_response(URI(uri_str))
|
16
38
|
case @response
|
17
39
|
when Net::HTTPSuccess then
|
18
|
-
|
40
|
+
@up = true
|
19
41
|
when Net::HTTPClientError then
|
20
|
-
|
42
|
+
@up = false
|
21
43
|
when Net::HTTPServerError then
|
22
|
-
|
44
|
+
@up = false
|
23
45
|
when Net::HTTPRedirection then
|
24
46
|
@location = @response['location']
|
25
47
|
fetch(@location, limit - 1)
|