Class: Schatz::Input::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/schatz/input/connection.rb

Direct Known Subclasses

ConnectionResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Connection

Returns a new instance of Connection.

Yields:

  • (_self)

Yield Parameters:



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/schatz/input/connection.rb', line 5

def initialize
  @port = 80
  @scheme = "http"
  yield self
  if @port=="" || @port==0
    case @scheme
    when "http"
      @port = 80
    when "https"
      @port = 443
    end
  end 
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



4
5
6
# File 'lib/schatz/input/connection.rb', line 4

def color
  @color
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/schatz/input/connection.rb', line 4

def description
  @description
end

#gcmObject

Returns the value of attribute gcm.



4
5
6
# File 'lib/schatz/input/connection.rb', line 4

def gcm
  @gcm
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/schatz/input/connection.rb', line 4

def host
  @host
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/schatz/input/connection.rb', line 4

def port
  @port
end

#resultObject

Returns the value of attribute result.



4
5
6
# File 'lib/schatz/input/connection.rb', line 4

def result
  @result
end

#schemeObject

Returns the value of attribute scheme.



4
5
6
# File 'lib/schatz/input/connection.rb', line 4

def scheme
  @scheme
end

Instance Method Details

#checkObject



66
67
68
# File 'lib/schatz/input/connection.rb', line 66

def check
  direct? ? host_check : link_check
end

#direct?Boolean

Returns:



45
46
47
# File 'lib/schatz/input/connection.rb', line 45

def direct?
  scheme.downcase == "tcp" || scheme.downcase == "udp"
end

#eql?(b) ⇒ Boolean

Returns:



18
19
20
# File 'lib/schatz/input/connection.rb', line 18

def eql?(b)
  self.scheme == b.scheme && self.host   == b.host && self.port == b.port && self.gcm    == b.gcm ? true : false   
end

#host_checkObject



84
85
86
87
88
89
90
91
# File 'lib/schatz/input/connection.rb', line 84

def host_check
  begin
    self.result = Schemes::DirectTcp.direct_test(self.host, self.port, 0.5) ? "open" : "closed"
  rescue Exception => e
    self.result = "closed"
  end
  self
end

#http?Boolean

Returns:



33
34
35
# File 'lib/schatz/input/connection.rb', line 33

def http?
  @scheme="http"
end

#https?Boolean

Returns:



37
38
39
# File 'lib/schatz/input/connection.rb', line 37

def https?
  @scheme="https"
end

#link?Boolean

Returns:



49
50
51
# File 'lib/schatz/input/connection.rb', line 49

def link?
  scheme.downcase == "http" || scheme.downcase == "https"
end

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/schatz/input/connection.rb', line 69

def link_check
  raise ArgumentError unless @proxy
  begin
    self.result = case scheme
      when "http" 
        Schemes::ProxyHttp.http_test(self, @proxy)
      when "https"
        Schemes::ProxyHttps.https_test(self, @proxy)
    end
  rescue Exception => e
    self.result = e.message
  end
  self          
end

#markObject



41
42
43
# File 'lib/schatz/input/connection.rb', line 41

def mark
  direct? ? mark_hosts : mark_links
end

#mark_hostsObject



53
54
55
# File 'lib/schatz/input/connection.rb', line 53

def mark_hosts
  self.color = result == "open" ? "green" : "red"
end


57
58
59
60
61
62
63
64
# File 'lib/schatz/input/connection.rb', line 57

def mark_links
  self.color, self.description= case result 
    when /30[12]/ then ["green", "Redirection to websso"]
    when "200" then ["green", "OK"]
    when /40[13]/ then ["green", "Error authorization"]
    else ["red", result]
  end
end