Class: RTicker::Net
- Inherits:
-
Object
- Object
- RTicker::Net
- Defined in:
- lib/rticker/net.rb
Constant Summary collapse
- @@proxy_host =
nil- @@proxy_port =
nil
Class Method Summary collapse
- .detect_system_proxy ⇒ Object
- .detect_system_proxy_macosx ⇒ Object
- .get_response(url) ⇒ Object
- .proxy ⇒ Object
- .proxy=(proxy) ⇒ Object
Class Method Details
.detect_system_proxy ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rticker/net.rb', line 30 def self.detect_system_proxy () require 'rbconfig' os = Config::CONFIG['host_os'] # Only support mac os x right now return detect_system_proxy_macosx() if os.start_with? "darwin" return nil end |
.detect_system_proxy_macosx ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rticker/net.rb', line 38 def self.detect_system_proxy_macosx () ethernet_enabled = (not %x[networksetup -getinfo ethernet].match(/IP address:/).nil?) airport_enabled = (not %x[networksetup -getinfo airport].match(/IP address:/).nil?) return nil if not (ethernet_enabled or airport_enabled) networkservice = ethernet_enabled ? "ethernet" : "airport" webproxy_info = %x[networksetup -getwebproxy #{networkservice}] return nil if webproxy_info.match(/Enabled: Yes/).nil? host, port, authentication_required = "", "", false host = webproxy_info.match(/Server: ([^\n]*)/)[1] port = webproxy_info.match(/Port: ([^\n]*)/)[1] authentication_required = webproxy_info.match(/Authenticated Proxy Enabled: (0|1)/)[1] == "1" return {:host => host, :port => port, :authentication_required => authentication_required} end |
.get_response(url) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rticker/net.rb', line 22 def self.get_response (url) begin return ::Net::HTTP::Proxy(@@proxy_host, @@proxy_port).get(URI.parse url) rescue Timeout::Error => e return "" end end |
.proxy ⇒ Object
10 11 12 13 14 |
# File 'lib/rticker/net.rb', line 10 def self.proxy () return nil if @@proxy_host.nil? port = @@proxy_port || 80 return "#{@@proxy_host}:#{port}" end |
.proxy=(proxy) ⇒ Object
16 17 18 19 20 |
# File 'lib/rticker/net.rb', line 16 def self.proxy= (proxy) host, port = proxy.split(":") @@proxy_host = host @@proxy_port = port || 80 end |