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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 230ff93a3c0eecaeeab87e9ad9e575e941d70765fa3f9ca45d1dd1dd4ae0d2de
4
- data.tar.gz: 26289e99a94ea207a8ffd25257620ceb50b43f6b614b887a0f38bc9f8ff4c25b
3
+ metadata.gz: e1fe1994ad1ca0d18274d7f0498b0ae77843add60e1df9f5a5819ac72dc01441
4
+ data.tar.gz: 3ee07c0916b00959d4aa3a7dc335606f4dee1ede3145b9590033727a20cf087f
5
5
  SHA512:
6
- metadata.gz: b1a5eea41d2a0101528ed4d07f6d3851183c8220c468debda3eef8e64f926366ffea3d2e966321cce61add3d7f435426cf8452be1c1ba07502a9f0a47f5253a4
7
- data.tar.gz: c918610bb533288cb1ddc2253bbbab0230a47da2a428737d916c7d897d210d119923761254dca881da49d3d79ca0daf19ec0edafd84bd0386a951f009ef7be63
6
+ metadata.gz: c05ee95ceab00acb361428458c71129b2800b49a6208ec919213ea5f95c44ed15e8df7335e5a9239db5a70e2d2748f3ca5759f8ff947a6633c479630dde59f19
7
+ data.tar.gz: ff8cf4fb8a9ace8d6831279ef2fd28eae61935e31f7653da669d5b1961212e49e63fbcda1693de92803625f019edd4fc99e1f1f606f8f3fc2d32820fe3fe9ebc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- web_loader (0.9.1)
4
+ web_loader (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -18,4 +18,4 @@ DEPENDENCIES
18
18
  web_loader!
19
19
 
20
20
  BUNDLED WITH
21
- 2.4.9
21
+ 2.4.19
@@ -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
- Cache.write(@cache_dir, url, response.code, body) if @use_cache
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
- load_page(to_redirect_url(uri, response['location']), limit - 1)
69
+ load(to_redirect_url(uri, response['location']), limit - 1)
65
70
  else
66
- puts "error #{url}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebLoader
4
- VERSION = "0.9.1"
4
+ VERSION = "1.0.0"
5
5
  end
data/test.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec rake test
4
+
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.9.1
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-08-01 00:00:00.000000000 Z
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.2.33
63
+ rubygems_version: 3.3.26
63
64
  signing_key:
64
65
  specification_version: 4
65
66
  summary: Web loader.