Class: Xunlei::Engine

Inherits:
Object
  • Object
show all
Includes:
Helper::CookieHelper
Defined in:
lib/xunlei/engine.rb

Instance Method Summary collapse

Methods included from Helper::CookieHelper

#format_cookie

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"
  (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.button(:id => 'down_but').when_present.click
  else
    puts "Operation timed out."
  end
end

#dump_cookiesObject



15
16
17
18
# File 'lib/xunlei/engine.rb', line 15

def dump_cookies
  wait_till_all_loaded
  @browser.driver.manage.all_cookies.inject([]) { |all_cookies, c| all_cookies << format_cookie(c) }
end

#dump_tasksObject



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

#stopObject



41
42
43
# File 'lib/xunlei/engine.rb', line 41

def stop
  @browser.close
end