Class: Gtt::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/gtt/downloader.rb,
lib/gtt/downloader/version.rb

Constant Summary collapse

VERSION =
"0.1.7"

Instance Method Summary collapse

Constructor Details

#initialize(email = ENV['GMAIL_ADDR'], password = ENV['GMAIL_PASS']) ⇒ Downloader

Returns a new instance of Downloader.



9
10
11
12
13
14
15
16
# File 'lib/gtt/downloader.rb', line 9

def initialize(email = ENV['GMAIL_ADDR'], password = ENV['GMAIL_PASS'])
  unless email && password
    raise 'email or password is not set'
  end

  @email    = email
  @password = password
end

Instance Method Details

#download_label(label) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gtt/downloader.rb', line 18

def download_label(label)
  session = nil

  Capybara.using_wait_time(wait_time) do
    session = signed_in_session

    session.click_on(label)
    # FIXME ラベルが選択されアイテムが表示されるのを待つ
    sleep 10

    # リストにフォーカスを当てておく
    session.find('.gtc-list-body tr:first-child .gtc-listview-col-checkbox .jfk-checkbox').click
    session.find('.gtc-list-body tr:first-child .gtc-listview-col-checkbox .jfk-checkbox').click

    # 全部表示する
    while session.first('#item-count', text: 'of many')
      session.find('body').native.send_key(:arrow_down)
    end

    session.find('#select-menu-button').click
    # FIXME ファイルが選択されるのを待つ
    sleep 10

    archive_path_helper do
      session.find('#download-button').click
      # FIXME ダウンロードを待つ
      begin
        sleep 1
      end while session.windows.length != 1
    end
  end
ensure
  if session
    session.cleanup!
    session.driver.quit
  end
end