yadisk 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/yadisk +1 -1
- data/lib/yadisk/check_runtime.rb +17 -5
- data/lib/yadisk/main.rb +37 -0
- data/lib/yadisk/os.rb +9 -0
- data/lib/yadisk/version.rb +1 -1
- data/lib/yadisk.rb +0 -20
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97c83d9c7b5300337ae2ce74d9074fbdeff05415547da1d8971429655d3eb9c9
|
4
|
+
data.tar.gz: 771b27f1b7f51ecf99aa6a716c53ca39340bf72a8d11406c9936cc0b68b60044
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bb0df189317862d8346b55d8529ce39a122d5f5641f89f56102827e3b26520875c31ce15a49a7adccbe7da07f5a18440d6733cf59f355a21cbe4bbf8b9c5130
|
7
|
+
data.tar.gz: 175d39680dc345592f4fc99e8a614453511ceff37c300903cea728a6ef991e81ced13c2144bcbe51df2117fb0d2f5fbe737c35779cecbeaa23239f1d581c5c1d
|
data/bin/yadisk
CHANGED
data/lib/yadisk/check_runtime.rb
CHANGED
@@ -1,13 +1,25 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
require 'yadisk/os'
|
2
6
|
|
3
7
|
module Yadisk
|
4
8
|
class CheckRuntime
|
5
9
|
def self.check_wget
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
if Yadisk::OS.windows?
|
11
|
+
output = IO.popen("where wget").read
|
12
|
+
abort! unless $?.to_i == 0
|
13
|
+
return
|
10
14
|
end
|
15
|
+
|
16
|
+
output = IO.popen("which wget").read
|
17
|
+
abort! if output.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.abort!
|
21
|
+
puts "Please install wget or add it to 'PATH' and try again\n"
|
22
|
+
abort
|
11
23
|
end
|
12
24
|
end
|
13
25
|
end
|
data/lib/yadisk/main.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
require 'cgi/util'
|
5
|
+
require 'uri'
|
6
|
+
require 'io/console'
|
7
|
+
require 'json'
|
8
|
+
require 'net/http'
|
9
|
+
|
10
|
+
require 'yadisk/os'
|
11
|
+
|
12
|
+
module Yadisk
|
13
|
+
class Main
|
14
|
+
BASE_URL = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='
|
15
|
+
def download(url, folder: ".#{File::SEPARATOR}", wget_options: nil)
|
16
|
+
enc_url = CGI::escape(url)
|
17
|
+
response = Net::HTTP.get(URI("#{BASE_URL}#{enc_url}"))
|
18
|
+
json_res = JSON.parse(response)
|
19
|
+
download_url = json_res['href']
|
20
|
+
filename = CGI::parse(URI(download_url).query)["filename"][0]
|
21
|
+
folder = folder + File::SEPARATOR if not folder.end_with?(File::SEPARATOR)
|
22
|
+
download_path = folder + filename
|
23
|
+
|
24
|
+
wget_options = (wget_options || "") + "--no-check-certificate" if Yadisk::OS.windows?
|
25
|
+
system("wget #{esc(download_url)} -O #{esc(download_path)} #{wget_options}")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def esc(str)
|
30
|
+
"#{escape_symbol}#{str}#{escape_symbol}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def escape_symbol
|
34
|
+
Yadisk::OS.windows? ? '"' : "'"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/yadisk/os.rb
ADDED
data/lib/yadisk/version.rb
CHANGED
data/lib/yadisk.rb
CHANGED
@@ -1,24 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'cgi'
|
4
|
-
require 'cgi/util'
|
5
|
-
require 'uri'
|
6
|
-
require 'io/console'
|
7
|
-
require 'json'
|
8
|
-
require 'net/http'
|
9
|
-
|
10
3
|
module Yadisk
|
11
|
-
class Main
|
12
|
-
BASE_URL = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='
|
13
|
-
def download(url, folder: './', wget_options: nil)
|
14
|
-
enc_url = CGI::escape(url)
|
15
|
-
response = Net::HTTP.get(URI("#{BASE_URL}#{enc_url}"))
|
16
|
-
json_res = JSON.parse(response)
|
17
|
-
download_url = json_res['href']
|
18
|
-
filename = CGI::parse(URI(download_url).query)["filename"][0]
|
19
|
-
folder = folder + "/" if not folder.end_with?('/')
|
20
|
-
|
21
|
-
system("wget '#{download_url}' -O '#{folder}#{filename}' #{wget_options}")
|
22
|
-
end
|
23
|
-
end
|
24
4
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yadisk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Yegorov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-01-25 00:00:00.000000000 Z
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: '3.9'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '4.0'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.
|
29
|
+
version: '3.9'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '4.0'
|
@@ -54,12 +54,14 @@ files:
|
|
54
54
|
- bin/yadisk
|
55
55
|
- lib/yadisk.rb
|
56
56
|
- lib/yadisk/check_runtime.rb
|
57
|
+
- lib/yadisk/main.rb
|
58
|
+
- lib/yadisk/os.rb
|
57
59
|
- lib/yadisk/version.rb
|
58
60
|
homepage: https://github.com/yegorov/yadisk
|
59
61
|
licenses:
|
60
62
|
- MIT
|
61
63
|
metadata: {}
|
62
|
-
post_install_message:
|
64
|
+
post_install_message:
|
63
65
|
rdoc_options: []
|
64
66
|
require_paths:
|
65
67
|
- lib
|
@@ -74,8 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
76
|
- !ruby/object:Gem::Version
|
75
77
|
version: '0'
|
76
78
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
78
|
-
signing_key:
|
79
|
+
rubygems_version: 3.3.7
|
80
|
+
signing_key:
|
79
81
|
specification_version: 4
|
80
82
|
summary: Download file from Yandex.Disk through share link
|
81
83
|
test_files: []
|