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.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/isup.rb +33 -20
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDUzYjY0NDFiMzk2NjIyZjk2MjJmNzQ3MDI2ZjllN2FlMTUzZWYwYg==
4
+ NTAwYjE5Y2U3YTIwZGIyMGI3ZTRkODBkZDE1MzY0NzYzZDQ3Y2VlMQ==
5
5
  data.tar.gz: !binary |-
6
- Yjc1YmVmNzJlZThkNWFhN2RiM2VkNzMwMjkwZWM4ODkwNGIyMWZlYw==
6
+ ZWQ3MDUzOTU0MWU4NjFjMTQxMTc3MGU1OWUxZDM1Y2I1ZmU1ZTRmMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTM4ZTcxYmFlYWQ3YzkwY2FmYzRhNGNmYTYyZGQ2MTI4YWI0NzA5Y2EwMTg2
10
- YTc3MTdmNzBjNTVkM2Q0N2Y0ZGRlNjQyMzJmODQ3OGMwOTBkMmNiYmVlMDk5
11
- MDIwN2I1ZmQyMzQ2MmM2OTZhNjA2MDU5YWQ5MzdmZWEzOTM1OWI=
9
+ ZjMwNDNhYThkZjgyMWMxNTAyNDYxZDQxNDFiOGI3NDFhNmUxMzNiNmY2N2Y2
10
+ ZGUyOTllMTgyOWJhOTZmZGE2YWZiY2NhMGU3MWRjNjA2YTI1MjkxZWFjYjNm
11
+ YmNhYTU4ZjE1MTYxZmIyMGI0MmIzMGI5NTc5YzU1YjQ5MGE3MGI=
12
12
  data.tar.gz: !binary |-
13
- MDllM2ZlMjZiY2EzOGQwYWFlYTE0MTYwNzM4ZmVhOGRjMjQ3MmNhZmMwYjk3
14
- ZTUyMTNjN2UwODgyYzU0MWJjNGYzZTFmMTM2ZWE4OTQzNDg1MzBkMmNiMTQ4
15
- ZjQ1Y2RiZGNhMTIwNGNjZTcxNDZhMGEwNGNkYjM5ZDdkYjQ3NTE=
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
- @parsed.kind_of?(URI::HTTP)
21
- rescue URI::BadURIError
22
- false
23
- rescue URI::InvalidURIError
24
- false
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 "#{@location} is UP" if @up == true
31
- puts "#{@location} is DOWN" if @up != true
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
- @response = Net::HTTP.get_response(URI(uri_str))
38
- case @response
39
- when Net::HTTPSuccess then
40
- @up = true
41
- when Net::HTTPClientError then
42
- @up = false
43
- when Net::HTTPServerError then
44
- @up = false
45
- when Net::HTTPRedirection then
46
- @location = @response['location']
47
- fetch(@location, limit - 1)
48
- else
49
- warn "Unable to complete the request."
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Brinker