web_loader 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/web_loader/command.rb +14 -6
- data/lib/web_loader/version.rb +1 -1
- data/test.sh +4 -0
- data/web_loader.iml +0 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1fe1994ad1ca0d18274d7f0498b0ae77843add60e1df9f5a5819ac72dc01441
|
4
|
+
data.tar.gz: 3ee07c0916b00959d4aa3a7dc335606f4dee1ede3145b9590033727a20cf087f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c05ee95ceab00acb361428458c71129b2800b49a6208ec919213ea5f95c44ed15e8df7335e5a9239db5a70e2d2748f3ca5759f8ff947a6633c479630dde59f19
|
7
|
+
data.tar.gz: ff8cf4fb8a9ace8d6831279ef2fd28eae61935e31f7653da669d5b1961212e49e63fbcda1693de92803625f019edd4fc99e1f1f606f8f3fc2d32820fe3fe9ebc
|
data/Gemfile.lock
CHANGED
data/lib/web_loader/command.rb
CHANGED
@@ -25,21 +25,23 @@ module WebLoader
|
|
25
25
|
@cache_dir = File.expand_path(CACHE_DIR)
|
26
26
|
@user_agent = "#{USER_AGENT}/#{VERSION}"
|
27
27
|
@binary = false
|
28
|
+
@verbose = false
|
28
29
|
end
|
29
30
|
|
30
31
|
attr_reader :load_cache_page
|
31
|
-
attr_accessor :use_cache, :cache_dir, :binary, :user_agent
|
32
|
+
attr_accessor :use_cache, :cache_dir, :binary, :user_agent, :verbose
|
32
33
|
|
33
34
|
def load(url, limit = 10)
|
34
35
|
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
35
|
-
|
36
|
+
log("Load: #{url}", @verbose)
|
36
37
|
@load_cache_page = false
|
37
38
|
content = try_load_cache(url)
|
38
39
|
if content
|
40
|
+
log("Load cache: #{url}", @verbose)
|
39
41
|
@load_cache_page = true
|
40
42
|
return content
|
41
43
|
end
|
42
|
-
|
44
|
+
log("Load server: #{url}", @verbose)
|
43
45
|
uri = URI.parse(url)
|
44
46
|
http = Net::HTTP.new(uri.host, uri.port)
|
45
47
|
if uri.scheme == 'https'
|
@@ -58,12 +60,15 @@ module WebLoader
|
|
58
60
|
encoding = response.type_params['charset']
|
59
61
|
body = toutf8(body, encoding)
|
60
62
|
end
|
61
|
-
|
63
|
+
if @use_cache
|
64
|
+
log("Write cache: #{url}", @verbose)
|
65
|
+
Cache.write(@cache_dir, url, response.code, body)
|
66
|
+
end
|
62
67
|
return body
|
63
68
|
when Net::HTTPRedirection
|
64
|
-
|
69
|
+
load(to_redirect_url(uri, response['location']), limit - 1)
|
65
70
|
else
|
66
|
-
|
71
|
+
log("error #{url}", true)
|
67
72
|
# それ以外は対応した例外を発生
|
68
73
|
response.value
|
69
74
|
end
|
@@ -76,5 +81,8 @@ module WebLoader
|
|
76
81
|
Cache.load_content(@cache_dir, url)
|
77
82
|
end
|
78
83
|
|
84
|
+
def log(msg, put_log)
|
85
|
+
puts msg if put_log
|
86
|
+
end
|
79
87
|
end
|
80
88
|
end
|
data/lib/web_loader/version.rb
CHANGED
data/test.sh
ADDED
data/web_loader.iml
CHANGED
@@ -7,8 +7,6 @@
|
|
7
7
|
</content>
|
8
8
|
<orderEntry type="inheritedJdk" />
|
9
9
|
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.10, rbenv: 3.1.4) [gem]" level="application" />
|
11
|
-
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, rbenv: 3.1.4) [gem]" level="application" />
|
12
10
|
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.1.4) [gem]" level="application" />
|
13
11
|
</component>
|
14
12
|
<component name="RakeTasksCache">
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- src
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Web loader.
|
14
14
|
email:
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/web_loader/utils.rb
|
37
37
|
- lib/web_loader/version.rb
|
38
38
|
- sig/web_loader.rbs
|
39
|
+
- test.sh
|
39
40
|
- web_loader.iml
|
40
41
|
homepage: https://srcw.net
|
41
42
|
licenses:
|
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: '0'
|
61
62
|
requirements: []
|
62
|
-
rubygems_version: 3.
|
63
|
+
rubygems_version: 3.3.26
|
63
64
|
signing_key:
|
64
65
|
specification_version: 4
|
65
66
|
summary: Web loader.
|