class SAAL::DINRelay::OutletGroup
Constants
- DEFAULT_CACHE_TIMEOUT
- DEFAULT_TIMEOUT
Attributes
cache_timeout[RW]
host[RW]
pass[RW]
port[RW]
timeout[RW]
user[RW]
Public Class Methods
new(opts={})
click to toggle source
# File lib/dinrelay.rb 36 def initialize(opts={}) 37 @host = opts[:host] || opts['host'] || 'localhost' 38 @port = opts[:port] || opts['port'] || 80 39 @user = opts[:user] || opts['user'] || 'admin' 40 @pass = opts[:pass] || opts['pass'] || '1234' 41 @timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT 42 @cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT 43 @cache = nil 44 @cachehit = nil 45 @cachetime = nil 46 end
Public Instance Methods
set_state(num, state)
click to toggle source
# File lib/dinrelay.rb 56 def set_state(num, state) 57 @cachetime = nil 58 response = do_get("/outlet?#{num}=#{state}") 59 response != nil 60 end
state(num)
click to toggle source
# File lib/dinrelay.rb 48 def state(num) 49 if !@cachetime or @cachetime < Time.now - @cache_timeout 50 @cache = do_get('/index.htm') 51 @cachetime = Time.now 52 end 53 return @cache ? parse_index_html(@cache.body)[num] : nil 54 end
Private Instance Methods
do_get(path)
click to toggle source
# File lib/dinrelay.rb 63 def do_get(path) 64 SAAL::do_http_get(@host, @port, path, @user, @pass, @timeout) 65 end
parse_index_html(str)
click to toggle source
# File lib/dinrelay.rb 66 def parse_index_html(str) 67 doc = Nokogiri::HTML(str) 68 outlets = doc.css('tr[bgcolor="#F4F4F4"]') 69 Hash[*((outlets.enum_for(:each_with_index).map do |el, index| 70 [index+1, el.css('font')[0].content] 71 end).flatten)] 72 end