isup 0.0.3 → 0.0.4

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 +27 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGE0ZTdkZmFjODcwN2RmZmJlOGY0YzA2NmI1MWEzOWE2MTBhZGFhZQ==
4
+ MDUzYjY0NDFiMzk2NjIyZjk2MjJmNzQ3MDI2ZjllN2FlMTUzZWYwYg==
5
5
  data.tar.gz: !binary |-
6
- Y2EwMWVmNmE2NzhkYWFkY2JkOWJlNzg2NDEzYTkyMjhjODVmZGIyNw==
6
+ Yjc1YmVmNzJlZThkNWFhN2RiM2VkNzMwMjkwZWM4ODkwNGIyMWZlYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWQ4ZGM0MzUxYjQ3YzdmMDM4YjA1YjEzMDIxZTUyZTg4MjM3ZDg3ZGM3ODk0
10
- MzJhNDBhZTlhNjI1Mzg2ZWIwYWUyOWY3YmMzYzNkMWJkZWEwNDFlMWMyMDI5
11
- OTkwNmI0Yjk2ZWI5MjcwZjhhM2ZmNjQ4YzJhMTI2MjQ2MzVlZWI=
9
+ OTM4ZTcxYmFlYWQ3YzkwY2FmYzRhNGNmYTYyZGQ2MTI4YWI0NzA5Y2EwMTg2
10
+ YTc3MTdmNzBjNTVkM2Q0N2Y0ZGRlNjQyMzJmODQ3OGMwOTBkMmNiYmVlMDk5
11
+ MDIwN2I1ZmQyMzQ2MmM2OTZhNjA2MDU5YWQ5MzdmZWEzOTM1OWI=
12
12
  data.tar.gz: !binary |-
13
- MWRjMTdmNTY3MTVjMDJiODg5YjQyNDFmZmVkMjE3NjBlOTRmNjYxYzEwOGIx
14
- MTkzOWIwMzBjNTUwODY5NDMxZGQ5MzY3NTIxOGFjM2FkNTI1ODcwNmRjZTRk
15
- NDMxOThjZDRiNWEwY2FiMWZmNzZiZTZkODc1MjlhNGQwYjZlMWE=
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
- @response_code = self.fetch(url, 10)
8
+ if valid?
9
+ up?
10
+ else
11
+ puts "Please input a valid URL"
12
+ end
9
13
  end
10
14
 
11
- public
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
- puts "#{@url} is UP"
40
+ @up = true
19
41
  when Net::HTTPClientError then
20
- puts "#{@url} is DOWN"
42
+ @up = false
21
43
  when Net::HTTPServerError then
22
- puts "#{@url} is either DOWN, or your network is."
44
+ @up = false
23
45
  when Net::HTTPRedirection then
24
46
  @location = @response['location']
25
47
  fetch(@location, limit - 1)
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Brinker