factorio-mod 0.5.5 → 0.6.0
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/.rubocop.yml +1 -1
- data/Gemfile.lock +12 -12
- data/lib/factorio/mod/cache.rb +1 -3
- data/lib/factorio/mod/download.rb +2 -2
- data/lib/factorio/mod/exception.rb +0 -7
- data/lib/factorio/mod/mod.rb +14 -27
- data/lib/factorio/mod/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8417b98fa7593e0defd4c676d400840e998ab87fd5a63e2c625df220bb8be24
|
4
|
+
data.tar.gz: ecd77d7c281591a9642d193d135552d6b4ac08079b070ce2c53728e8ed6c7160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95279289b28a0d647187119ae06da9af3c4b334d105f491e6dd85ffe7c30b24fe30d0d64e140b1d7be90cca1a30aae38105292c286637676e199b0b8c6caaf26
|
7
|
+
data.tar.gz: 27b3e5dd78066ef18f123407130598c6a37d1b33f5f3b145f855008e38c64437eb68591264daf5d1d97146f65abe3c87177cfe2df0bff037c4705289d2776e32
|
data/.rubocop.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: '2.
|
2
|
+
TargetRubyVersion: '2.6.0'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
factorio-mod (0.
|
4
|
+
factorio-mod (0.6.0)
|
5
5
|
activesupport (~> 5.2)
|
6
6
|
nokogiri (~> 1.8)
|
7
7
|
|
@@ -14,24 +14,24 @@ GEM
|
|
14
14
|
minitest (~> 5.1)
|
15
15
|
tzinfo (~> 1.1)
|
16
16
|
ast (2.4.0)
|
17
|
-
bump (0.
|
17
|
+
bump (0.7.0)
|
18
18
|
coco (0.15.0)
|
19
19
|
coderay (1.1.2)
|
20
20
|
concurrent-ruby (1.1.4)
|
21
21
|
diff-lcs (1.3)
|
22
|
-
i18n (1.5.
|
22
|
+
i18n (1.5.2)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
|
-
jaro_winkler (1.5.
|
25
|
-
method_source (0.9.
|
24
|
+
jaro_winkler (1.5.2)
|
25
|
+
method_source (0.9.2)
|
26
26
|
mini_portile2 (2.4.0)
|
27
27
|
minitest (5.11.3)
|
28
|
-
nokogiri (1.10.
|
28
|
+
nokogiri (1.10.1)
|
29
29
|
mini_portile2 (~> 2.4.0)
|
30
30
|
parallel (1.12.1)
|
31
|
-
parser (2.5.
|
31
|
+
parser (2.5.3.0)
|
32
32
|
ast (~> 2.4.0)
|
33
33
|
powerpack (0.1.2)
|
34
|
-
pry (0.
|
34
|
+
pry (0.12.2)
|
35
35
|
coderay (~> 1.1.0)
|
36
36
|
method_source (~> 0.9.0)
|
37
37
|
rainbow (3.0.0)
|
@@ -42,26 +42,26 @@ GEM
|
|
42
42
|
rspec-mocks (~> 3.8.0)
|
43
43
|
rspec-core (3.8.0)
|
44
44
|
rspec-support (~> 3.8.0)
|
45
|
-
rspec-expectations (3.8.
|
45
|
+
rspec-expectations (3.8.2)
|
46
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
47
|
rspec-support (~> 3.8.0)
|
48
48
|
rspec-mocks (3.8.0)
|
49
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
50
|
rspec-support (~> 3.8.0)
|
51
51
|
rspec-support (3.8.0)
|
52
|
-
rubocop (0.
|
52
|
+
rubocop (0.62.0)
|
53
53
|
jaro_winkler (~> 1.5.1)
|
54
54
|
parallel (~> 1.10)
|
55
55
|
parser (>= 2.5, != 2.5.1.1)
|
56
56
|
powerpack (~> 0.1)
|
57
57
|
rainbow (>= 2.2.2, < 4.0)
|
58
58
|
ruby-progressbar (~> 1.7)
|
59
|
-
unicode-display_width (~> 1.
|
59
|
+
unicode-display_width (~> 1.4.0)
|
60
60
|
ruby-progressbar (1.10.0)
|
61
61
|
thread_safe (0.3.6)
|
62
62
|
tzinfo (1.2.5)
|
63
63
|
thread_safe (~> 0.1)
|
64
|
-
unicode-display_width (1.4.
|
64
|
+
unicode-display_width (1.4.1)
|
65
65
|
|
66
66
|
PLATFORMS
|
67
67
|
ruby
|
data/lib/factorio/mod/cache.rb
CHANGED
@@ -49,9 +49,7 @@ module Factorio
|
|
49
49
|
# Get from cache or download page
|
50
50
|
def get(symbol, uri)
|
51
51
|
symbol = symbol.to_sym
|
52
|
-
|
53
|
-
|
54
|
-
@cache[symbol] = Nokogiri::HTML(URI.open(uri, 'Cookie' => @cookie))
|
52
|
+
@cache[symbol] ||= Nokogiri::HTML(URI.open(uri, 'Cookie' => @cookie))
|
55
53
|
rescue OpenURI::HTTPError => e
|
56
54
|
raise NoMODError.new "MOD #{@uri.split('/').last} not found", e.io
|
57
55
|
end
|
@@ -18,13 +18,13 @@ module Factorio
|
|
18
18
|
game_version: :text.to_proc,
|
19
19
|
uri: Mod.method(:get_href).to_proc,
|
20
20
|
date: :text.to_proc,
|
21
|
-
times:
|
21
|
+
times: :text.to_proc >> :to_i.to_proc
|
22
22
|
}.freeze
|
23
23
|
|
24
24
|
# set value by table header
|
25
25
|
def set(name, value)
|
26
26
|
sym = TABLE_HEADER_TO_SYM[name]
|
27
|
-
|
27
|
+
tap { |a| a[sym] = HANDLE_VALUE[sym].call value }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -17,13 +17,6 @@ module Factorio
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
# The Exception that can't find download
|
21
|
-
class NoDownloadError < StandardError
|
22
|
-
def initialize(msg)
|
23
|
-
super
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
20
|
# The Exception that try to visit not exist page
|
28
21
|
class NoPageError < StandardError
|
29
22
|
def initialize(msg)
|
data/lib/factorio/mod/mod.rb
CHANGED
@@ -13,7 +13,7 @@ module Factorio
|
|
13
13
|
# puts "It latest version for factorio 0.16 can download at " \
|
14
14
|
# "#{mod.latest_download('0.16')[:uri]}"
|
15
15
|
# ```
|
16
|
-
class Mod
|
16
|
+
class Mod
|
17
17
|
# factorio Mod portal website URI
|
18
18
|
MOD_URI = 'https://mods.factorio.com'
|
19
19
|
|
@@ -35,8 +35,7 @@ module Factorio
|
|
35
35
|
table = @mod.information.xpath("//div[@class='mod-page-data-table']")
|
36
36
|
return table if key.blank?
|
37
37
|
|
38
|
-
xpath
|
39
|
-
table.xpath xpath
|
38
|
+
table.xpath "//td[../td[@class='data-name'][.='#{key}:']]"
|
40
39
|
end
|
41
40
|
|
42
41
|
public
|
@@ -46,10 +45,8 @@ module Factorio
|
|
46
45
|
# @param line [Nokogiri::HTML] `<tr>`
|
47
46
|
# @return [Download] _download_
|
48
47
|
def self.bind_td_to_th(table_header, line)
|
49
|
-
line.css('td').
|
50
|
-
|
51
|
-
key = table_header[index]
|
52
|
-
obj.set(key, item)
|
48
|
+
table_header.zip(line.css('td')).inject(Download.new) do |obj, pair|
|
49
|
+
obj.set(*pair)
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
@@ -72,12 +69,10 @@ module Factorio
|
|
72
69
|
rescue Net::ReadTimeout
|
73
70
|
retry
|
74
71
|
end
|
75
|
-
|
76
72
|
sleep(1) while driver.current_url == 'https://mods.factorio.com/login'
|
77
|
-
session = driver.manage.cookie_named('session')[:value]
|
78
|
-
driver.quit if autoclose
|
79
73
|
|
80
|
-
"session=#{session}"
|
74
|
+
"session=#{driver.manage.cookie_named('session')[:value]}" \
|
75
|
+
.tap { driver.quit if autoclose }
|
81
76
|
end
|
82
77
|
|
83
78
|
# @return [String, String] `csrf_token` and cookie
|
@@ -108,8 +103,8 @@ module Factorio
|
|
108
103
|
'username' => username,
|
109
104
|
'password' => password
|
110
105
|
)
|
111
|
-
|
112
|
-
|
106
|
+
Net::HTTP.post(URI(MOD_URI + '/login'), data, 'Cookie' => cookie) \
|
107
|
+
.response['set-cookie'].split('; ').first
|
113
108
|
end
|
114
109
|
|
115
110
|
# Extend relative links to absolute links
|
@@ -117,9 +112,7 @@ module Factorio
|
|
117
112
|
# @return [String] absolute link
|
118
113
|
# @raise [NotLoginError]
|
119
114
|
def self.extend_uri(rel)
|
120
|
-
raise NotLoginError if
|
121
|
-
|
122
|
-
MOD_URI + rel
|
115
|
+
MOD_URI + rel.tap { |a| raise NotLoginError if a =~ %r{^/login} }
|
123
116
|
end
|
124
117
|
|
125
118
|
# Get href in Nokogiri node
|
@@ -176,7 +169,7 @@ module Factorio
|
|
176
169
|
# Whether Mod is deprecated
|
177
170
|
# @return [Bool] is deprecated
|
178
171
|
def deprecated?
|
179
|
-
|
172
|
+
@mod.any.xpath('//span[@class="mod-card-title-deprecated"]').any?
|
180
173
|
end
|
181
174
|
|
182
175
|
# Get the totle number of downloads of Mod.
|
@@ -189,13 +182,9 @@ module Factorio
|
|
189
182
|
# Get the latest _download_ of the Mod.
|
190
183
|
# @param version [String] factorio version
|
191
184
|
# @return [Download]
|
192
|
-
def latest_download(version = nil)
|
193
|
-
|
194
|
-
|
195
|
-
download_list.each do |download|
|
196
|
-
return download if download.game_version == version.to_s
|
197
|
-
end
|
198
|
-
raise NoDownloadError, "can't found #{name} for factorio #{version}"
|
185
|
+
def latest_download(version = nil, ifnone = nil)
|
186
|
+
version.blank? && download_list.last ||
|
187
|
+
download_list.find(ifnone) { |d| d.game_version == version.to_s }
|
199
188
|
end
|
200
189
|
|
201
190
|
# Get the _download_ for all of version.
|
@@ -203,9 +192,7 @@ module Factorio
|
|
203
192
|
def download_list
|
204
193
|
table = @mod.downloads.css 'table.mod-page-downloads-table'
|
205
194
|
head = table.css('thead tr th').map(&:text)
|
206
|
-
table.css('tbody tr').map
|
207
|
-
Mod.bind_td_to_th head, line
|
208
|
-
end
|
195
|
+
table.css('tbody tr').map { |line| Mod.bind_td_to_th(head, line) }
|
209
196
|
end
|
210
197
|
|
211
198
|
# Get latest download uri by download button in card
|
data/lib/factorio/mod/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factorio-mod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 71e6fd52
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -182,8 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
- !ruby/object:Gem::Version
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
|
-
|
186
|
-
rubygems_version: 2.7.7
|
185
|
+
rubygems_version: 3.0.2
|
187
186
|
signing_key:
|
188
187
|
specification_version: 4
|
189
188
|
summary: Get the info of Factorio's MOD.
|