Class: ChatworkBridge::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/chatwork_bridge/watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Watcher

Returns a new instance of Watcher.



8
9
10
11
12
13
14
15
16
# File 'lib/chatwork_bridge/watcher.rb', line 8

def initialize(opts={})
  opts = {interval: 1, browser: :phantomjs}.merge(opts)
  @interval = opts.fetch(:interval)
  @browser = opts.fetch(:browser)
  @chatwork_login_url = opts.fetch(:chatwork_login_url)
  @chatwork_email = opts.fetch(:chatwork_email)
  @chatwork_password = opts.fetch(:chatwork_password)
  @notifiers = opts[:notifiers] || []
end

Instance Attribute Details

#notifiersObject

Returns the value of attribute notifiers.



6
7
8
# File 'lib/chatwork_bridge/watcher.rb', line 6

def notifiers
  @notifiers
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chatwork_bridge/watcher.rb', line 18

def run
  begin
    init_driver
    
    inject_code
    loop do
      if Time.now - @last_login_time > 60 * 60 * 6
        # 6 hours
        
      end
      notification = fetch_latest_notification
      unless notification.nil?
        process_notification(notification)
      end
      sleep @interval
    end
  ensure
    quit_driver
  end
end