factorio-mod 0.3.0 → 0.4.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/Gemfile.lock +9 -3
- data/Rakefile +0 -2
- data/bin/console +4 -4
- data/factorio-mod.gemspec +1 -0
- data/lib/factorio/mod.rb +2 -0
- data/lib/factorio/mod/download.rb +11 -2
- data/lib/factorio/mod/mod.rb +57 -34
- data/lib/factorio/mod/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc46a6267996d8e4e5891e39918998a66ad25b738d85d44814426685662ea89
|
4
|
+
data.tar.gz: 83c21b87bdcd20990724ed98814c9bbde13280fba66a2d6d815dd5113bb10558
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77486d9176c9398349bd7befbfab82ae12d02c3f77e7cdafa42933d4898be00f8b1596c4433e010149ab661de3ea63fbc5628352c7524b7cf7a199d0dd4acbe7
|
7
|
+
data.tar.gz: 5b1902aa35d4dd2a704e0ee50aeb0bab8c9c741aabf30a584c85e1d34cbe5cbc324b9152b1b0a2d66e97ab22fa168e618066d9e035b2d254464e63115f583314
|
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.4.0)
|
5
5
|
nokogiri (~> 1.8)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,15 +10,20 @@ GEM
|
|
10
10
|
ast (2.4.0)
|
11
11
|
bump (0.6.1)
|
12
12
|
coco (0.15.0)
|
13
|
+
coderay (1.1.2)
|
13
14
|
diff-lcs (1.3)
|
14
15
|
jaro_winkler (1.5.1)
|
16
|
+
method_source (0.9.0)
|
15
17
|
mini_portile2 (2.3.0)
|
16
|
-
nokogiri (1.8.
|
18
|
+
nokogiri (1.8.5)
|
17
19
|
mini_portile2 (~> 2.3.0)
|
18
20
|
parallel (1.12.1)
|
19
21
|
parser (2.5.1.2)
|
20
22
|
ast (~> 2.4.0)
|
21
23
|
powerpack (0.1.2)
|
24
|
+
pry (0.11.3)
|
25
|
+
coderay (~> 1.1.0)
|
26
|
+
method_source (~> 0.9.0)
|
22
27
|
rainbow (3.0.0)
|
23
28
|
rake (10.5.0)
|
24
29
|
rspec (3.8.0)
|
@@ -53,9 +58,10 @@ DEPENDENCIES
|
|
53
58
|
bundler (~> 1.16)
|
54
59
|
coco
|
55
60
|
factorio-mod!
|
61
|
+
pry
|
56
62
|
rake (~> 10.0)
|
57
63
|
rspec (~> 3.0)
|
58
64
|
rubocop
|
59
65
|
|
60
66
|
BUNDLED WITH
|
61
|
-
1.16.
|
67
|
+
1.16.6
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -7,8 +7,8 @@ require 'factorio/mod'
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
12
12
|
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|
13
|
+
# require 'irb'
|
14
|
+
# IRB.start(__FILE__)
|
data/factorio-mod.gemspec
CHANGED
data/lib/factorio/mod.rb
CHANGED
@@ -11,9 +11,18 @@ module Factorio
|
|
11
11
|
'Downloads' => :times
|
12
12
|
}.freeze
|
13
13
|
|
14
|
-
|
14
|
+
HANDLE_VALUE = {
|
15
|
+
version: :text.to_proc,
|
16
|
+
game_version: :text.to_proc,
|
17
|
+
uri: Mod.method(:get_href).to_proc,
|
18
|
+
date: :text.to_proc,
|
19
|
+
times: proc { |item| item.text.to_i }
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
# set value by table header
|
15
23
|
def set(name, value)
|
16
|
-
|
24
|
+
sym = TABLE_HEADER_TO_SYM[name]
|
25
|
+
self[sym] = HANDLE_VALUE[sym].call value
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
data/lib/factorio/mod/mod.rb
CHANGED
@@ -36,52 +36,61 @@ module Factorio
|
|
36
36
|
table.xpath xpath
|
37
37
|
end
|
38
38
|
|
39
|
-
# @return [String, String] `csrf_token` and cookie
|
40
|
-
def self.csrf_and_cookie
|
41
|
-
resp = open 'https://mods.factorio.com/login'
|
42
|
-
cookie = resp.meta['set-cookie'].split('; ')[0]
|
43
|
-
csrf_token = Nokogiri::HTML(resp).css('#csrf_token @value').to_s
|
44
|
-
[csrf_token, cookie]
|
45
|
-
end
|
46
|
-
private_class_method :csrf_and_cookie
|
47
|
-
|
48
39
|
public
|
49
40
|
|
50
|
-
# rubocop:disable MethodLength
|
51
|
-
|
52
41
|
# Map each value with table header.
|
53
42
|
# @param table_header [Array] table header in order
|
54
43
|
# @param line [Nokogiri::HTML] `<tr>`
|
55
|
-
# @return [
|
44
|
+
# @return [Download] _download_
|
56
45
|
def self.bind_td_to_th(table_header, line)
|
57
46
|
line.css('td').each_with_index.each_with_object(Download.new) \
|
58
47
|
do |(item, index), obj|
|
59
48
|
key = table_header[index]
|
60
|
-
|
61
|
-
href = item.xpath('a/@href').to_s
|
62
|
-
raise NotLoginError if href =~ %r{^/login}
|
63
|
-
obj.uri = MOD_URI + href
|
64
|
-
else
|
65
|
-
obj.set(key, item.text)
|
66
|
-
end
|
49
|
+
obj.set(key, item)
|
67
50
|
end
|
68
51
|
end
|
69
52
|
|
70
|
-
# rubocop:enable MethodLength
|
71
|
-
|
72
53
|
# Get the logged in cookie.
|
73
|
-
#
|
74
|
-
# @
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# # use firefox nightly
|
57
|
+
# Selenium::WebDriver::Firefox::Binary.path =
|
58
|
+
# `which firefox-nightly`.chomp
|
59
|
+
# # open firefox
|
60
|
+
# driver = Selenium::WebDriver.for :firefox
|
61
|
+
# cookie = Factorio::Mod.login_cookie(driver)
|
62
|
+
# # the browser will automatically close
|
63
|
+
# @param driver [Selenium::WebDriver::Driver] Web Driver
|
64
|
+
# @param autoclose [Bool] automatically close the browser after logging in
|
75
65
|
# @return [String] The logged in cookie
|
76
|
-
def self.login_cookie(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
66
|
+
def self.login_cookie(driver, autoclose = true)
|
67
|
+
begin
|
68
|
+
driver.navigate.to 'https://mods.factorio.com/login'
|
69
|
+
rescue Net::ReadTimeout
|
70
|
+
retry
|
71
|
+
end
|
72
|
+
|
73
|
+
sleep(1) while driver.current_url == 'https://mods.factorio.com/login'
|
74
|
+
session = driver.manage.cookie_named('session')[:value]
|
75
|
+
driver.quit if autoclose
|
76
|
+
|
77
|
+
"session=#{session}"
|
78
|
+
end
|
79
|
+
|
80
|
+
# Extend relative links to absolute links
|
81
|
+
# @param rel [String] relative link
|
82
|
+
# @return [String] absolute link
|
83
|
+
# @raise [NotLoginError]
|
84
|
+
def self.extend_uri(rel)
|
85
|
+
raise NotLoginError if rel =~ %r{^/login}
|
86
|
+
MOD_URI + rel
|
87
|
+
end
|
88
|
+
|
89
|
+
# Get href in Nokogiri node
|
90
|
+
# @param item [Nokogiri::HTML]
|
91
|
+
# @return [String] relative link
|
92
|
+
def self.get_href(item)
|
93
|
+
extend_uri(item.xpath('a/@href').text)
|
85
94
|
end
|
86
95
|
|
87
96
|
# Get the title (also known as _display name_) of the Mod
|
@@ -100,7 +109,7 @@ module Factorio
|
|
100
109
|
# Get the GitHub URI.
|
101
110
|
# @return [String] GitHub URI
|
102
111
|
def github
|
103
|
-
uri =
|
112
|
+
uri = @mod.any.xpath('//a[@class="source-code-link"]/@href').text
|
104
113
|
return if uri.empty?
|
105
114
|
uri
|
106
115
|
end
|
@@ -123,11 +132,18 @@ module Factorio
|
|
123
132
|
def license_uri
|
124
133
|
data_table('License').xpath('a/@href').to_s
|
125
134
|
end
|
135
|
+
alias license_link license_uri
|
126
136
|
|
127
137
|
# Get the author of the Mod.
|
128
138
|
# @return [String] author
|
129
139
|
def author
|
130
|
-
|
140
|
+
@mod.any.xpath('//div[@class="mod-card-author"]/a').text
|
141
|
+
end
|
142
|
+
|
143
|
+
# Whether Mod is deprecated
|
144
|
+
# @return [Bool] is deprecated
|
145
|
+
def deprecated?
|
146
|
+
!@mod.any.xpath('//span[@class="mod-card-title-deprecated"]').empty?
|
131
147
|
end
|
132
148
|
|
133
149
|
# Get the totle number of downloads of Mod.
|
@@ -157,5 +173,12 @@ module Factorio
|
|
157
173
|
Mod.bind_td_to_th head, line
|
158
174
|
end
|
159
175
|
end
|
176
|
+
|
177
|
+
# Get latest download uri by download button in card
|
178
|
+
# @return [String] download uri
|
179
|
+
def latest_download_uri
|
180
|
+
Mod.get_href(@mod.any.css('.mod-download-button'))
|
181
|
+
end
|
182
|
+
alias latest_download_link latest_download_uri
|
160
183
|
end
|
161
184
|
end
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 71e6fd52
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rubocop
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|