Class: MediawikiRobot::Robot

Inherits:
Object
  • Object
show all
Defined in:
lib/mediawiki_robot/robot.rb

Constant Summary collapse

API_SUFFIX =
'/api.php'
MAX_SIMULTANEOUS_THREADS =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mw_opts) ⇒ Robot

Returns a new instance of Robot.



16
17
18
19
20
21
22
23
# File 'lib/mediawiki_robot/robot.rb', line 16

def initialize(mw_opts)
  api_url = mw_opts[:base_url] + mw_opts[:normal_prefix] + API_SUFFIX
  @mw = MediawikiRobot::EnhancedGateway.new(api_url, {:ignorewarnings=>1})

  @thread = nil

  @mainloop_sleep_secs = 5.0 # make this non-constant so that it can be overridden for testing
end

Instance Attribute Details

#mwObject

Returns the value of attribute mw.



11
12
13
# File 'lib/mediawiki_robot/robot.rb', line 11

def mw
  @mw
end

Instance Method Details

#is_runningObject



33
34
35
36
37
# File 'lib/mediawiki_robot/robot.rb', line 33

def is_running
  return false if @thread.nil?
  return true unless @thread.status.nil? or @thread.status == false
  return false
end

#startObject



25
26
27
# File 'lib/mediawiki_robot/robot.rb', line 25

def start
  @thread = Thread.new { main_loop }
end

#stopObject



29
30
31
# File 'lib/mediawiki_robot/robot.rb', line 29

def stop
  @thread.kill
end