gtt-downloader 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/exe/gtt-downloader +2 -1
 - data/lib/gtt/downloader.rb +30 -13
 - data/lib/gtt/downloader/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 6bb4e29a797be71e2597dfb5a73ebb244f7aa970
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 088d91cfa40dc9d7870ac2e1b7bcbe2739948233
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6b8755392f21553b240e73a3d77b76f10e8a9e520d46b90eff7303ed86514210c627803d4d7e46557f640d5ea57f66d12cb4f6c58791c1694517317da7baabf4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1b8c4c1aae3787d7cf741fe330396fb1a075d89c57fb0a93f46b97becc4a1f99e4d46a324e50e09a353bb51e1a3e729fdca27b49cf8d1c6803c4352b07b715fe
         
     | 
    
        data/exe/gtt-downloader
    CHANGED
    
    | 
         @@ -13,4 +13,5 @@ end 
     | 
|
| 
       13 
13 
     | 
    
         
             
            downloader   = Gtt::Downloader.new
         
     | 
| 
       14 
14 
     | 
    
         
             
            label        = ENV['LABEL']
         
     | 
| 
       15 
15 
     | 
    
         
             
            archive_path = downloader.download_label(label)
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
            filename     = File.basename(archive_path).gsub(/ \(\d+\)(\.[^.]+)$/) { $1 }
         
     | 
| 
      
 17 
     | 
    
         
            +
            FileUtils.mv(archive_path, File.join(FileUtils.pwd, filename))
         
     | 
    
        data/lib/gtt/downloader.rb
    CHANGED
    
    | 
         @@ -38,7 +38,13 @@ module Gtt 
     | 
|
| 
       38 
38 
     | 
    
         
             
                    # FIXME ファイルが選択されるのを待つ
         
     | 
| 
       39 
39 
     | 
    
         
             
                    sleep 10
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                     
     | 
| 
      
 41 
     | 
    
         
            +
                    if session.first('#item-count', text: '1-1 of 1')
         
     | 
| 
      
 42 
     | 
    
         
            +
                      filename = session.first('.gtc-list-row-select .gtc-listview-doc-col-name > div:first-child').text
         
     | 
| 
      
 43 
     | 
    
         
            +
                    else
         
     | 
| 
      
 44 
     | 
    
         
            +
                      filename = nil
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                    archive_path_helper(filename: filename) do
         
     | 
| 
       42 
48 
     | 
    
         
             
                      session.find('#download-button').click
         
     | 
| 
       43 
49 
     | 
    
         
             
                      # FIXME ダウンロードを待つ
         
     | 
| 
       44 
50 
     | 
    
         
             
                      begin
         
     | 
| 
         @@ -55,12 +61,12 @@ module Gtt 
     | 
|
| 
       55 
61 
     | 
    
         | 
| 
       56 
62 
     | 
    
         
             
                private
         
     | 
| 
       57 
63 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                def archive_path_helper(&action)
         
     | 
| 
       59 
     | 
    
         
            -
                  previous_archive_paths = archive_paths
         
     | 
| 
      
 64 
     | 
    
         
            +
                def archive_path_helper(filename: nil, &action)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  previous_archive_paths = archive_paths(filename)
         
     | 
| 
       60 
66 
     | 
    
         | 
| 
       61 
67 
     | 
    
         
             
                  action.call
         
     | 
| 
       62 
68 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                  downloaded_archive_paths = archive_paths - previous_archive_paths
         
     | 
| 
      
 69 
     | 
    
         
            +
                  downloaded_archive_paths = archive_paths(filename) - previous_archive_paths
         
     | 
| 
       64 
70 
     | 
    
         | 
| 
       65 
71 
     | 
    
         
             
                  if downloaded_archive_paths.count.zero?
         
     | 
| 
       66 
72 
     | 
    
         
             
                    raise "Download failed"
         
     | 
| 
         @@ -73,8 +79,16 @@ module Gtt 
     | 
|
| 
       73 
79 
     | 
    
         
             
                  downloaded_archive_paths[0]
         
     | 
| 
       74 
80 
     | 
    
         
             
                end
         
     | 
| 
       75 
81 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
                def archive_paths
         
     | 
| 
       77 
     | 
    
         
            -
                   
     | 
| 
      
 82 
     | 
    
         
            +
                def archive_paths(filename = nil)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  if filename
         
     | 
| 
      
 84 
     | 
    
         
            +
                    Dir.glob(File.join(download_path, "#{filename}*"))
         
     | 
| 
      
 85 
     | 
    
         
            +
                  else
         
     | 
| 
      
 86 
     | 
    
         
            +
                    Dir.glob(File.join(download_path, 'archive*.zip'))
         
     | 
| 
      
 87 
     | 
    
         
            +
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
                end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                def download_path
         
     | 
| 
      
 91 
     | 
    
         
            +
                  File.expand_path('~/Downloads')
         
     | 
| 
       78 
92 
     | 
    
         
             
                end
         
     | 
| 
       79 
93 
     | 
    
         | 
| 
       80 
94 
     | 
    
         
             
                def gtt_driver
         
     | 
| 
         @@ -89,13 +103,16 @@ module Gtt 
     | 
|
| 
       89 
103 
     | 
    
         | 
| 
       90 
104 
     | 
    
         
             
                def signed_in_session
         
     | 
| 
       91 
105 
     | 
    
         
             
                  session = Capybara::Session.new(gtt_driver)
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                   
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                  Capybara.using_wait_time(2) do
         
     | 
| 
      
 108 
     | 
    
         
            +
                    session.visit(::Gtt::URL)
         
     | 
| 
      
 109 
     | 
    
         
            +
                    session.fill_in  'Email',  with: @email
         
     | 
| 
      
 110 
     | 
    
         
            +
                    session.click_on 'Next' if session.has_button? 'Next'
         
     | 
| 
      
 111 
     | 
    
         
            +
                    session.click_on '次へ' if session.has_button? '次へ'
         
     | 
| 
      
 112 
     | 
    
         
            +
                    session.fill_in  'Passwd', with: @password
         
     | 
| 
      
 113 
     | 
    
         
            +
                    session.click_on 'signIn'
         
     | 
| 
      
 114 
     | 
    
         
            +
                    session
         
     | 
| 
      
 115 
     | 
    
         
            +
                  end
         
     | 
| 
       99 
116 
     | 
    
         
             
                end
         
     | 
| 
       100 
117 
     | 
    
         | 
| 
       101 
118 
     | 
    
         
             
                def wait_time
         
     |