yadisk 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 404736ac791c10402f7c3aa6dbc6c32e5df4598297301081101764db491a8495
4
- data.tar.gz: 941696ff4e49895f5949ac96d7a1e0c5b9c3f1c55c9e471bd48b2c4144c039d9
3
+ metadata.gz: 97c83d9c7b5300337ae2ce74d9074fbdeff05415547da1d8971429655d3eb9c9
4
+ data.tar.gz: 771b27f1b7f51ecf99aa6a716c53ca39340bf72a8d11406c9936cc0b68b60044
5
5
  SHA512:
6
- metadata.gz: 49f7b97c24fdd0aeb31e845f18e06e1bbb490a82c1e05d16ee6c3048caf598830aa5d3e6e909a6d53b547694a961af08ab2b1837547da5eb0cb92f616634ad9b
7
- data.tar.gz: 58afcac2974b54ece72ec09c1074d96355692b39007c9bd3fcdede6393dae0bc7186e45a69007126d68374fb6fb047e8b1e530cb44e2683e6b37c6688eda9eec
6
+ metadata.gz: 1bb0df189317862d8346b55d8529ce39a122d5f5641f89f56102827e3b26520875c31ce15a49a7adccbe7da07f5a18440d6733cf59f355a21cbe4bbf8b9c5130
7
+ data.tar.gz: 175d39680dc345592f4fc99e8a614453511ceff37c300903cea728a6ef991e81ced13c2144bcbe51df2117fb0d2f5fbe737c35779cecbeaa23239f1d581c5c1d
data/bin/yadisk CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- require 'yadisk'
4
+ require 'yadisk/main'
5
5
  require 'yadisk/check_runtime'
6
6
  require 'optparse'
7
7
 
@@ -1,13 +1,25 @@
1
- require "io/console"
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
- output = IO.popen("which wget").read
7
- if output.empty?
8
- puts "Please install wget or add it to 'PATH' and try again\n"
9
- abort
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
@@ -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
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Yadisk
4
+ class OS
5
+ def self.windows?
6
+ RUBY_PLATFORM =~ /win|mingw/
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Yadisk
2
- VERSION = '0.1.0'
2
+ VERSION = '0.3.0'
3
3
  end
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.1.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.8.0
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.8.0
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.0.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: []