yadisk 0.1.0 → 0.2.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: 6dad6b4c4a02ce2b8a582bded7d9828b98b568e0dfa3b67d93bb2387e6bd9441
4
+ data.tar.gz: f603b1744363d545f916895aba2ca0c56814f3f549dc28af5c703a83d33d7e88
5
5
  SHA512:
6
- metadata.gz: 49f7b97c24fdd0aeb31e845f18e06e1bbb490a82c1e05d16ee6c3048caf598830aa5d3e6e909a6d53b547694a961af08ab2b1837547da5eb0cb92f616634ad9b
7
- data.tar.gz: 58afcac2974b54ece72ec09c1074d96355692b39007c9bd3fcdede6393dae0bc7186e45a69007126d68374fb6fb047e8b1e530cb44e2683e6b37c6688eda9eec
6
+ metadata.gz: f8f05f1e5d4b4291979983d28173b53a6c282bd17ffa6d0b3697dd7123dad3df32db2bd60031f697efe23a4e051ad61a8d270db52f87f2c11843b546a4921c02
7
+ data.tar.gz: dec7fce5eaf4642de3a0bcdd6102e622b2b21bbc7eaa9092db7b277d43714eed95c68ab8eda862258df7b193296c9cde94481d8f2a95d808869774fe45d7831c
@@ -7,18 +7,31 @@ require 'io/console'
7
7
  require 'json'
8
8
  require 'net/http'
9
9
 
10
+ require 'yadisk/os'
11
+
10
12
  module Yadisk
11
13
  class Main
12
14
  BASE_URL = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='
13
- def download(url, folder: './', wget_options: nil)
15
+ def download(url, folder: ".#{File::SEPARATOR}", wget_options: nil)
14
16
  enc_url = CGI::escape(url)
15
17
  response = Net::HTTP.get(URI("#{BASE_URL}#{enc_url}"))
16
18
  json_res = JSON.parse(response)
17
19
  download_url = json_res['href']
18
20
  filename = CGI::parse(URI(download_url).query)["filename"][0]
19
- folder = folder + "/" if not folder.end_with?('/')
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
20
32
 
21
- system("wget '#{download_url}' -O '#{folder}#{filename}' #{wget_options}")
33
+ def escape_symbol
34
+ Yadisk::OS.windows? ? '"' : "'"
22
35
  end
23
36
  end
24
37
  end
@@ -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,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.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Yegorov
@@ -54,6 +54,7 @@ files:
54
54
  - bin/yadisk
55
55
  - lib/yadisk.rb
56
56
  - lib/yadisk/check_runtime.rb
57
+ - lib/yadisk/os.rb
57
58
  - lib/yadisk/version.rb
58
59
  homepage: https://github.com/yegorov/yadisk
59
60
  licenses:
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubygems_version: 3.0.3
78
+ rubygems_version: 3.0.6
78
79
  signing_key:
79
80
  specification_version: 4
80
81
  summary: Download file from Yandex.Disk through share link