Class: Xunlei::Engine
- Inherits:
-
Object
- Object
- Xunlei::Engine
- Includes:
- Helper::CookieHelper
- Defined in:
- lib/xunlei/engine.rb
Instance Method Summary collapse
- #add_task(target_address) ⇒ Object
- #dump_cookies ⇒ Object
- #dump_tasks ⇒ Object
-
#initialize(username, password, driver = :chrome) ⇒ Engine
constructor
A new instance of Engine.
- #stop ⇒ Object
Methods included from Helper::CookieHelper
Constructor Details
#initialize(username, password, driver = :chrome) ⇒ Engine
Returns a new instance of Engine.
6 7 8 9 10 11 |
# File 'lib/xunlei/engine.rb', line 6 def initialize(username, password, driver = :chrome) @browser = Watir::Browser.new driver @browser.goto "http://lixian.vip.xunlei.com" signin(username, password) wait_till_all_loaded end |
Instance Method Details
#add_task(target_address) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xunlei/engine.rb', line 29 def add_task(target_address) @browser.execute_script("add_task_new(0)") @browser.text_field(:id => 'task_url').wait_until_present @browser.execute_script("document.getElementById('task_url').value = '#{target_address}'") if added_successfully? @browser.(:id => 'down_but').when_present.click else puts "Operation timed out." end end |
#dump_cookies ⇒ Object
15 16 17 18 |
# File 'lib/xunlei/engine.rb', line 15 def wait_till_all_loaded @browser.driver.manage..inject([]) { |, c| << (c) } end |
#dump_tasks ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/xunlei/engine.rb', line 20 def dump_tasks all_files = dump_current_page while next_page? next_page! all_files += dump_current_page end all_files end |
#stop ⇒ Object
41 42 43 |
# File 'lib/xunlei/engine.rb', line 41 def stop @browser.close end |