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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b6e33c585d39356bacfa4d8fcd3055054429f5c
4
- data.tar.gz: 346f5491ff90cbc54ca7ff298eaa884bf4c8507a
3
+ metadata.gz: 6bb4e29a797be71e2597dfb5a73ebb244f7aa970
4
+ data.tar.gz: 088d91cfa40dc9d7870ac2e1b7bcbe2739948233
5
5
  SHA512:
6
- metadata.gz: 36d24f9e9b0db6cfa5bd5fef9a93a121be7a472ca7037f8e7e6df5efa035337fe2c80f36d1444d4523e7ef209bfe8191fd4f5b27fd929727f6d923e8406fa3a4
7
- data.tar.gz: 8118f251f0485a286ca79bfc0caa76121d0f8065703153cbec026f76ef0da11a36d9c82ad7886c9b61e16385b0e9bb275dd2202c050d49b6bc158a26fac4c89f
6
+ metadata.gz: 6b8755392f21553b240e73a3d77b76f10e8a9e520d46b90eff7303ed86514210c627803d4d7e46557f640d5ea57f66d12cb4f6c58791c1694517317da7baabf4
7
+ data.tar.gz: 1b8c4c1aae3787d7cf741fe330396fb1a075d89c57fb0a93f46b97becc4a1f99e4d46a324e50e09a353bb51e1a3e729fdca27b49cf8d1c6803c4352b07b715fe
@@ -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
- FileUtils.mv(archive_path, File.join(FileUtils.pwd, 'archive.zip'))
16
+ filename = File.basename(archive_path).gsub(/ \(\d+\)(\.[^.]+)$/) { $1 }
17
+ FileUtils.mv(archive_path, File.join(FileUtils.pwd, filename))
@@ -38,7 +38,13 @@ module Gtt
38
38
  # FIXME ファイルが選択されるのを待つ
39
39
  sleep 10
40
40
 
41
- archive_path_helper do
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
- Dir.glob(File.expand_path('~/Downloads/archive*.zip'))
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
- session.visit(::Gtt::URL)
93
- session.fill_in 'Email', with: @email
94
- session.click_on 'Next' if session.has_button? 'Next'
95
- session.click_on '次へ' if session.has_button? '次へ'
96
- session.fill_in 'Passwd', with: @password
97
- session.click_on 'signIn'
98
- session
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
@@ -1,5 +1,5 @@
1
1
  module Gtt
2
2
  class Downloader
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtt-downloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Miyagi