miteru 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/miteru.rb +1 -1
- data/lib/miteru/cli.rb +1 -1
- data/lib/miteru/http_client.rb +54 -0
- data/lib/miteru/version.rb +1 -1
- data/lib/miteru/website.rb +1 -4
- metadata +3 -3
- data/lib/miteru/downloader.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b6ffb792e263519ab645ef14235c5fb6cfa08919375bbaf2064528515dacd43
|
4
|
+
data.tar.gz: a67289780e2d42dfbbcd0a4b8142487e3ba22c5aa5addeef5707fe107161ecb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e43966e7560b60cc4e09930ef9f390862747380419267b0135dc7b86edf3aec83f1fb18732e3553a8adb805fc08c70654327c89bf973c171d3aa1bc59c70b4b
|
7
|
+
data.tar.gz: 906207242b7cafbba681f19d73df74b4e3c5160d8982e0144cc5d2f30c53917593e3abde329b3666400f2f27db9055c55bef4f880df5f20cc973add7e077ea6c
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Miteru
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/miteru.svg)](https://badge.fury.io/rb/miteru)
|
3
4
|
[![Build Status](https://travis-ci.org/ninoseki/miteru.svg?branch=master)](https://travis-ci.org/ninoseki/miteru)
|
4
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/d90e1b5bbdd9663a17d1/maintainability)](https://codeclimate.com/github/ninoseki/miteru/maintainability)
|
5
6
|
[![Coverage Status](https://coveralls.io/repos/github/ninoseki/miteru/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/miteru?branch=master)
|
data/lib/miteru.rb
CHANGED
data/lib/miteru/cli.rb
CHANGED
@@ -27,7 +27,7 @@ module Miteru
|
|
27
27
|
zip_files.each do |path|
|
28
28
|
target_url = "#{url}/#{path}"
|
29
29
|
begin
|
30
|
-
destination =
|
30
|
+
destination = HTTPClient.download(target_url, base_dir)
|
31
31
|
puts "Download #{target_url} as #{destination}"
|
32
32
|
rescue Down::Error => e
|
33
33
|
puts "Failed to download: #{target_url} (#{e})"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "http"
|
4
|
+
require "down/http"
|
5
|
+
require "securerandom"
|
6
|
+
|
7
|
+
module Miteru
|
8
|
+
class HTTPClient
|
9
|
+
DEFAULT_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
|
10
|
+
attr_reader :ssl_context
|
11
|
+
def initialize
|
12
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
13
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
14
|
+
@ssl_context = ctx
|
15
|
+
end
|
16
|
+
|
17
|
+
def download(url, base_dir)
|
18
|
+
destination = download_to(base_dir, save_filename)
|
19
|
+
down = Down::Http.new(default_options) { |client| client.headers(default_headers) }
|
20
|
+
down.download(url, destination: destination)
|
21
|
+
destination
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.download(url, base_dir = "/tmp")
|
25
|
+
new.download(url, base_dir)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(url)
|
29
|
+
HTTP.headers(default_headers).get(url, default_options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get(url)
|
33
|
+
new.get url
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def default_headers
|
39
|
+
{ user_agent: DEFAULT_UA }
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_options
|
43
|
+
{ ssl_context: ssl_context }
|
44
|
+
end
|
45
|
+
|
46
|
+
def save_filename
|
47
|
+
"#{SecureRandom.alphanumeric}.zip"
|
48
|
+
end
|
49
|
+
|
50
|
+
def download_to(base_dir, save_filename)
|
51
|
+
"#{base_dir}/#{save_filename}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/miteru/version.rb
CHANGED
data/lib/miteru/website.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "http"
|
4
3
|
require "oga"
|
5
4
|
|
6
5
|
module Miteru
|
@@ -49,9 +48,7 @@ module Miteru
|
|
49
48
|
end
|
50
49
|
|
51
50
|
def get
|
52
|
-
|
53
|
-
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
54
|
-
HTTP.get(url, ssl_context: ctx)
|
51
|
+
HTTPClient.get url
|
55
52
|
end
|
56
53
|
|
57
54
|
def doc
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miteru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manabu Niseki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -213,8 +213,8 @@ files:
|
|
213
213
|
- lib/miteru.rb
|
214
214
|
- lib/miteru/cli.rb
|
215
215
|
- lib/miteru/crawler.rb
|
216
|
-
- lib/miteru/downloader.rb
|
217
216
|
- lib/miteru/error.rb
|
217
|
+
- lib/miteru/http_client.rb
|
218
218
|
- lib/miteru/version.rb
|
219
219
|
- lib/miteru/website.rb
|
220
220
|
- miteru.gemspec
|
data/lib/miteru/downloader.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "down"
|
4
|
-
require "securerandom"
|
5
|
-
|
6
|
-
module Miteru
|
7
|
-
class Downloader
|
8
|
-
attr_reader :url, :base_dir
|
9
|
-
def initialize(url, base_dir = "/tmp")
|
10
|
-
@url = url
|
11
|
-
@base_dir = base_dir
|
12
|
-
end
|
13
|
-
|
14
|
-
def save_filename
|
15
|
-
"#{SecureRandom.alphanumeric}.zip"
|
16
|
-
end
|
17
|
-
|
18
|
-
def destination
|
19
|
-
@destination ||= "#{base_dir}/#{save_filename}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def download
|
23
|
-
Down.download(url, destination: destination)
|
24
|
-
destination
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.download(url, base_dir = "/tmp")
|
28
|
-
new(url, base_dir).download
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|