Class: SAAL::DINRelay::OutletGroup
- Inherits:
-
Object
- Object
- SAAL::DINRelay::OutletGroup
- Defined in:
- lib/dinrelay.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
2
- DEFAULT_CACHE_TIMEOUT =
60
Instance Attribute Summary collapse
-
#cache_timeout ⇒ Object
Returns the value of attribute cache_timeout.
-
#host ⇒ Object
Returns the value of attribute host.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#port ⇒ Object
Returns the value of attribute port.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ OutletGroup
constructor
A new instance of OutletGroup.
- #set_state(num, state) ⇒ Object
- #state(num) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ OutletGroup
Returns a new instance of OutletGroup.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dinrelay.rb', line 36 def initialize(opts={}) @host = opts[:host] || opts['host'] || 'localhost' @port = opts[:port] || opts['port'] || 80 @user = opts[:user] || opts['user'] || 'admin' @pass = opts[:pass] || opts['pass'] || '1234' @timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT @cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT @cache = nil @cachehit = nil end |
Instance Attribute Details
#cache_timeout ⇒ Object
Returns the value of attribute cache_timeout.
34 35 36 |
# File 'lib/dinrelay.rb', line 34 def cache_timeout @cache_timeout end |
#host ⇒ Object
Returns the value of attribute host.
34 35 36 |
# File 'lib/dinrelay.rb', line 34 def host @host end |
#pass ⇒ Object
Returns the value of attribute pass.
34 35 36 |
# File 'lib/dinrelay.rb', line 34 def pass @pass end |
#port ⇒ Object
Returns the value of attribute port.
34 35 36 |
# File 'lib/dinrelay.rb', line 34 def port @port end |
#timeout ⇒ Object
Returns the value of attribute timeout.
34 35 36 |
# File 'lib/dinrelay.rb', line 34 def timeout @timeout end |
#user ⇒ Object
Returns the value of attribute user.
34 35 36 |
# File 'lib/dinrelay.rb', line 34 def user @user end |
Instance Method Details
#set_state(num, state) ⇒ Object
55 56 57 58 59 |
# File 'lib/dinrelay.rb', line 55 def set_state(num, state) @cachetime = nil response = do_get("/outlet?#{num}=#{state}") response != nil end |
#state(num) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/dinrelay.rb', line 47 def state(num) if !@cachetime or @cachetime < Time.now - @cache_timeout @cache = do_get('/index.htm') @cachetime = Time.now end return @cache ? parse_index_html(@cache.body)[num] : nil end |