yadisk 0.0.2 → 0.1.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: c1c1bd16617274d0066b92d0ccd1e49bb75eddd1aa22c8f56d670ccb44088a82
4
- data.tar.gz: f8aab0bc3a45f3cf0ea7068350e9f916eeb519a481089b19a49d8bf705b1b1a0
3
+ metadata.gz: 404736ac791c10402f7c3aa6dbc6c32e5df4598297301081101764db491a8495
4
+ data.tar.gz: 941696ff4e49895f5949ac96d7a1e0c5b9c3f1c55c9e471bd48b2c4144c039d9
5
5
  SHA512:
6
- metadata.gz: b56f30327ed62c7df70aa9d971b061accd4673b329f10cba1ce2074af3cb770bcb0e6836ecdb13f16ec61bcb7ab148d36c68de418700446b4fcb8af3b7d9089e
7
- data.tar.gz: 6f25651c072a5c78dda6c6ffefca1c40d8649540dd68e848b329fbd0afbe19125fdc928791dbeae73cb8ea0aad93429aa04410e167357eb60780743a14985da1
6
+ metadata.gz: 49f7b97c24fdd0aeb31e845f18e06e1bbb490a82c1e05d16ee6c3048caf598830aa5d3e6e909a6d53b547694a961af08ab2b1837547da5eb0cb92f616634ad9b
7
+ data.tar.gz: 58afcac2974b54ece72ec09c1074d96355692b39007c9bd3fcdede6393dae0bc7186e45a69007126d68374fb6fb047e8b1e530cb44e2683e6b37c6688eda9eec
data/bin/yadisk CHANGED
@@ -3,18 +3,37 @@
3
3
 
4
4
  require 'yadisk'
5
5
  require 'yadisk/check_runtime'
6
+ require 'optparse'
6
7
 
7
8
  Yadisk::CheckRuntime.check_wget
8
9
 
10
+ options = {}
11
+ parser = OptionParser.new do |opts|
12
+ opts.banner = 'Use: $ yadisk url [/path/to/download/local/folder]'
13
+ opts.separator ''
14
+ opts.separator 'Options:'
15
+ opts.on('-w', '--wget-options=OPTIONS', 'additional options passed to wget process') do |wget_options|
16
+ options[:wget_options] = wget_options
17
+ end
18
+ end
19
+
9
20
  begin
10
- if ARGV.length == 1
11
- Yadisk::Main.new.download(ARGV[0])
12
- elsif ARGV.length == 2
13
- Yadisk::Main.new.download(ARGV[0], folder: ARGV[1])
21
+ parser.parse!
22
+
23
+ url = ARGV.shift
24
+
25
+ if url
26
+ folder = ARGV.shift
27
+ options[:folder] = folder if folder
28
+ Yadisk::Main.new.download(url, **options)
14
29
  else
15
- puts "Use: $ yadisk url [/path/to/download/local/folder]\n"
30
+ puts parser.help
16
31
  end
17
32
  rescue OpenSSL::SSL::SSLError
18
33
  puts 'SSL certificate error while accessing Yandex.'
19
34
  exit(-1)
35
+ rescue OptionParser::ParseError => exception
36
+ puts "Error: #{exception}"
37
+ puts parser.help
38
+ exit(-1)
20
39
  end
@@ -10,7 +10,7 @@ require 'net/http'
10
10
  module Yadisk
11
11
  class Main
12
12
  BASE_URL = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='
13
- def download(url, folder: './')
13
+ def download(url, folder: './', wget_options: nil)
14
14
  enc_url = CGI::escape(url)
15
15
  response = Net::HTTP.get(URI("#{BASE_URL}#{enc_url}"))
16
16
  json_res = JSON.parse(response)
@@ -18,7 +18,7 @@ module Yadisk
18
18
  filename = CGI::parse(URI(download_url).query)["filename"][0]
19
19
  folder = folder + "/" if not folder.end_with?('/')
20
20
 
21
- system("wget '#{download_url}' -O '#{folder}#{filename}'")
21
+ system("wget '#{download_url}' -O '#{folder}#{filename}' #{wget_options}")
22
22
  end
23
23
  end
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module Yadisk
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.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.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Yegorov