factorio-mod 0.4.0 → 0.5.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 +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +15 -2
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/factorio-mod.gemspec +3 -0
- data/lib/factorio/mod.rb +6 -0
- data/lib/factorio/mod/cache.rb +8 -5
- data/lib/factorio/mod/download.rb +5 -3
- data/lib/factorio/mod/exception.rb +2 -0
- data/lib/factorio/mod/mod.rb +47 -14
- data/lib/factorio/mod/version.rb +3 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f87061c490f02e803b9625ad9ee1430d95ade44ea3ec2aad5f7c4dfe467d964b
|
4
|
+
data.tar.gz: baf201035dfccf9c0afdd009c86cadc6699fe24c67cfdde6b937909c6982b666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f0dbbc1048d6544a6fd1354d13e2b609a58451a7b3a8a28bb33944bc8eb7719d0f3cab94591c8785370be804d87fb71eec446780c8fa0e4bf873e6fdfb6ea41
|
7
|
+
data.tar.gz: 199ce9af9186305636a6e7bcd8b46d92a3835c992bbb27ecc3f3dc9dc928151a0125b7295b36dac98bd0c4c477010dd942de10ceb093974645d07bcc3740b2f6
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
factorio-mod (0.
|
4
|
+
factorio-mod (0.5.0)
|
5
|
+
activesupport (~> 5.2)
|
5
6
|
nokogiri (~> 1.8)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
activesupport (5.2.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
10
16
|
ast (2.4.0)
|
11
17
|
bump (0.6.1)
|
12
18
|
coco (0.15.0)
|
13
19
|
coderay (1.1.2)
|
20
|
+
concurrent-ruby (1.1.3)
|
14
21
|
diff-lcs (1.3)
|
22
|
+
i18n (1.1.1)
|
23
|
+
concurrent-ruby (~> 1.0)
|
15
24
|
jaro_winkler (1.5.1)
|
16
25
|
method_source (0.9.0)
|
17
26
|
mini_portile2 (2.3.0)
|
27
|
+
minitest (5.11.3)
|
18
28
|
nokogiri (1.8.5)
|
19
29
|
mini_portile2 (~> 2.3.0)
|
20
30
|
parallel (1.12.1)
|
@@ -48,6 +58,9 @@ GEM
|
|
48
58
|
ruby-progressbar (~> 1.7)
|
49
59
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
50
60
|
ruby-progressbar (1.10.0)
|
61
|
+
thread_safe (0.3.6)
|
62
|
+
tzinfo (1.2.5)
|
63
|
+
thread_safe (~> 0.1)
|
51
64
|
unicode-display_width (1.4.0)
|
52
65
|
|
53
66
|
PLATFORMS
|
@@ -64,4 +77,4 @@ DEPENDENCIES
|
|
64
77
|
rubocop
|
65
78
|
|
66
79
|
BUNDLED WITH
|
67
|
-
1.
|
80
|
+
1.17.1
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/factorio-mod.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'factorio/mod/version'
|
@@ -30,5 +32,6 @@ Gem::Specification.new do |spec|
|
|
30
32
|
spec.add_development_dependency 'pry'
|
31
33
|
spec.add_development_dependency 'rubocop'
|
32
34
|
|
35
|
+
spec.add_dependency 'activesupport', '~> 5.2'
|
33
36
|
spec.add_dependency 'nokogiri', '~> 1.8'
|
34
37
|
end
|
data/lib/factorio/mod.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
|
3
5
|
require 'factorio/mod/version'
|
@@ -11,3 +13,7 @@ require 'open-uri'
|
|
11
13
|
require 'net/http'
|
12
14
|
require 'nokogiri'
|
13
15
|
require 'erb' # for uri encode
|
16
|
+
|
17
|
+
require 'active_support'
|
18
|
+
require 'active_support/core_ext/object/blank.rb'
|
19
|
+
require 'active_support/core_ext/array/access.rb'
|
data/lib/factorio/mod/cache.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Factorio
|
2
4
|
# Cache mod info
|
3
5
|
class Cache
|
@@ -27,12 +29,12 @@ module Factorio
|
|
27
29
|
# @param better [Symbol] get which page if none of the pages exist.
|
28
30
|
# @return [Nokogiri::HTML]
|
29
31
|
def any(better = :information)
|
30
|
-
if @cache.key?
|
31
|
-
|
32
|
-
elsif @cache.
|
33
|
-
|
32
|
+
if @cache.key? better
|
33
|
+
@cache[better]
|
34
|
+
elsif @cache.any?
|
35
|
+
@cache.first.second
|
34
36
|
else
|
35
|
-
|
37
|
+
public_method(better).call
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -42,6 +44,7 @@ module Factorio
|
|
42
44
|
def get(symbol, uri)
|
43
45
|
symbol = symbol.to_sym
|
44
46
|
return @cache[symbol] if @cache.key? symbol
|
47
|
+
|
45
48
|
@cache[symbol] = Nokogiri::HTML(URI.open(uri, 'Cookie' => @cookie))
|
46
49
|
rescue OpenURI::HTTPError => e
|
47
50
|
raise NoMODError.new @name, e.io
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Factorio
|
2
4
|
class Mod
|
3
5
|
# store the entry of the _download_
|
4
6
|
Download = Struct.new(:version, :game_version, :uri, :date, :times) do
|
5
7
|
# `Download` page table header to attribute symbol
|
6
8
|
TABLE_HEADER_TO_SYM = {
|
7
|
-
'Version'
|
9
|
+
'Version' => :version,
|
8
10
|
'Game Version' => :game_version,
|
9
|
-
'Download'
|
11
|
+
'Download' => :uri,
|
10
12
|
'Release Date' => :date,
|
11
|
-
'Downloads'
|
13
|
+
'Downloads' => :times
|
12
14
|
}.freeze
|
13
15
|
|
14
16
|
HANDLE_VALUE = {
|
data/lib/factorio/mod/mod.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Factorio
|
2
4
|
# Info interface
|
3
5
|
#
|
@@ -11,9 +13,9 @@ module Factorio
|
|
11
13
|
# puts "It latest version for factorio 0.16 can download at " \
|
12
14
|
# "#{mod.latest_download('0.16')[:uri]}"
|
13
15
|
# ```
|
14
|
-
class Mod
|
16
|
+
class Mod # rubocop:disable ClassLength
|
15
17
|
# factorio Mod portal website URI
|
16
|
-
MOD_URI = 'https://mods.factorio.com'
|
18
|
+
MOD_URI = 'https://mods.factorio.com'
|
17
19
|
|
18
20
|
attr_reader :name
|
19
21
|
alias id name
|
@@ -29,9 +31,10 @@ module Factorio
|
|
29
31
|
private
|
30
32
|
|
31
33
|
# Get the meta table from Information page.
|
32
|
-
def data_table(key =
|
34
|
+
def data_table(key = nil)
|
33
35
|
table = @mod.information.xpath("//div[@class='mod-page-data-table']")
|
34
|
-
return table if key
|
36
|
+
return table if key.blank?
|
37
|
+
|
35
38
|
xpath = "//td[../td[@class='data-name'][.='#{key}:']]"
|
36
39
|
table.xpath xpath
|
37
40
|
end
|
@@ -50,7 +53,7 @@ module Factorio
|
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
53
|
-
# Get the logged in cookie.
|
56
|
+
# Get the logged in cookie by webdriver.
|
54
57
|
#
|
55
58
|
# @example
|
56
59
|
# # use firefox nightly
|
@@ -58,12 +61,12 @@ module Factorio
|
|
58
61
|
# `which firefox-nightly`.chomp
|
59
62
|
# # open firefox
|
60
63
|
# driver = Selenium::WebDriver.for :firefox
|
61
|
-
# cookie = Factorio::Mod.
|
64
|
+
# cookie = Factorio::Mod.login_cookie_webdriver(driver)
|
62
65
|
# # the browser will automatically close
|
63
66
|
# @param driver [Selenium::WebDriver::Driver] Web Driver
|
64
67
|
# @param autoclose [Bool] automatically close the browser after logging in
|
65
68
|
# @return [String] The logged in cookie
|
66
|
-
def self.
|
69
|
+
def self.login_cookie_webdirver(driver, autoclose = true)
|
67
70
|
begin
|
68
71
|
driver.navigate.to 'https://mods.factorio.com/login'
|
69
72
|
rescue Net::ReadTimeout
|
@@ -77,12 +80,44 @@ module Factorio
|
|
77
80
|
"session=#{session}"
|
78
81
|
end
|
79
82
|
|
83
|
+
# @return [String, String] `csrf_token` and cookie
|
84
|
+
def self.csrf_and_cookie
|
85
|
+
resp = open 'https://mods.factorio.com/login'
|
86
|
+
cookie = resp.meta['set-cookie'].split('; ')[0]
|
87
|
+
csrf_token = Nokogiri::HTML(resp).css('#csrf_token @value').to_s
|
88
|
+
[csrf_token, cookie]
|
89
|
+
end
|
90
|
+
private_class_method :csrf_and_cookie
|
91
|
+
|
92
|
+
# Get the logged in cookie by username and password.
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# print 'username: '
|
96
|
+
# user = gets.chomp
|
97
|
+
# print 'password: '
|
98
|
+
# pass = gets.chomp
|
99
|
+
# cookie = Factorio::Mod.login_cookie user, pass
|
100
|
+
# @param username [String]
|
101
|
+
# @param password [String]
|
102
|
+
# @return [String] The logged in cookie
|
103
|
+
def self.login_cookie(username, password)
|
104
|
+
csrf_token, cookie = csrf_and_cookie
|
105
|
+
data = URI.encode_www_form(
|
106
|
+
'csrf_token' => csrf_token,
|
107
|
+
'username' => username,
|
108
|
+
'password' => password
|
109
|
+
)
|
110
|
+
resp = Net::HTTP.post(URI(MOD_URI + '/login'), data, 'Cookie' => cookie)
|
111
|
+
resp.response['set-cookie'].split('; ').first
|
112
|
+
end
|
113
|
+
|
80
114
|
# Extend relative links to absolute links
|
81
115
|
# @param rel [String] relative link
|
82
116
|
# @return [String] absolute link
|
83
117
|
# @raise [NotLoginError]
|
84
118
|
def self.extend_uri(rel)
|
85
119
|
raise NotLoginError if rel =~ %r{^/login}
|
120
|
+
|
86
121
|
MOD_URI + rel
|
87
122
|
end
|
88
123
|
|
@@ -109,16 +144,13 @@ module Factorio
|
|
109
144
|
# Get the GitHub URI.
|
110
145
|
# @return [String] GitHub URI
|
111
146
|
def github
|
112
|
-
|
113
|
-
return if uri.empty?
|
114
|
-
uri
|
147
|
+
@mod.any.xpath('//a[@class="source-code-link"]/@href').text.presence
|
115
148
|
end
|
116
149
|
|
117
150
|
# Get the git repo URI that can be cloned.
|
118
151
|
# @return [String] git URI
|
119
152
|
def git
|
120
|
-
|
121
|
-
github + '.git'
|
153
|
+
github &.+ '.git'
|
122
154
|
end
|
123
155
|
|
124
156
|
# Get the license that the Mod use.
|
@@ -156,8 +188,9 @@ module Factorio
|
|
156
188
|
# Get the latest _download_ of the Mod.
|
157
189
|
# @param version [String] factorio version
|
158
190
|
# @return [Download]
|
159
|
-
def latest_download(version =
|
160
|
-
return download_list.last if version
|
191
|
+
def latest_download(version = nil)
|
192
|
+
return download_list.last if version.blank?
|
193
|
+
|
161
194
|
download_list.each do |download|
|
162
195
|
return download if download.game_version == version.to_s
|
163
196
|
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.5.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-10
|
11
|
+
date: 2018-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activesupport
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.2'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.2'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: nokogiri
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,6 +147,7 @@ files:
|
|
133
147
|
- ".gitignore"
|
134
148
|
- ".gitlab-ci.yml"
|
135
149
|
- ".rspec"
|
150
|
+
- ".rubocop.yml"
|
136
151
|
- ".yardopts"
|
137
152
|
- Gemfile
|
138
153
|
- Gemfile.lock
|
@@ -167,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
182
|
version: '0'
|
168
183
|
requirements: []
|
169
184
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.7.
|
185
|
+
rubygems_version: 2.7.7
|
171
186
|
signing_key:
|
172
187
|
specification_version: 4
|
173
188
|
summary: Get the info of Factorio's MOD.
|