Skip to content

Commit

Permalink
Move yadisk.rb to yadisk/main.rb, bump version to 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegorov committed Jan 14, 2024
1 parent 69a28ba commit 4683257
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
yadisk (0.2.0)
yadisk (0.3.0)

GEM
remote: http://www.rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion bin/yadisk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: utf-8

require 'yadisk'
require 'yadisk/main'
require 'yadisk/check_runtime'
require 'optparse'

Expand Down
33 changes: 0 additions & 33 deletions lib/yadisk.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
# encoding: utf-8

require 'cgi'
require 'cgi/util'
require 'uri'
require 'io/console'
require 'json'
require 'net/http'

require 'yadisk/os'

module Yadisk
class Main
BASE_URL = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='
def download(url, folder: ".#{File::SEPARATOR}", wget_options: nil)
enc_url = CGI::escape(url)
response = Net::HTTP.get(URI("#{BASE_URL}#{enc_url}"))
json_res = JSON.parse(response)
download_url = json_res['href']
filename = CGI::parse(URI(download_url).query)["filename"][0]
folder = folder + File::SEPARATOR if not folder.end_with?(File::SEPARATOR)
download_path = folder + filename

wget_options = (wget_options || "") + "--no-check-certificate" if Yadisk::OS.windows?
system("wget #{esc(download_url)} -O #{esc(download_path)} #{wget_options}")
end

private
def esc(str)
"#{escape_symbol}#{str}#{escape_symbol}"
end

def escape_symbol
Yadisk::OS.windows? ? '"' : "'"
end
end
end
37 changes: 37 additions & 0 deletions lib/yadisk/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# encoding: utf-8

require 'cgi'
require 'cgi/util'
require 'uri'
require 'io/console'
require 'json'
require 'net/http'

require 'yadisk/os'

module Yadisk
class Main
BASE_URL = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='
def download(url, folder: ".#{File::SEPARATOR}", wget_options: nil)
enc_url = CGI::escape(url)
response = Net::HTTP.get(URI("#{BASE_URL}#{enc_url}"))
json_res = JSON.parse(response)
download_url = json_res['href']
filename = CGI::parse(URI(download_url).query)["filename"][0]
folder = folder + File::SEPARATOR if not folder.end_with?(File::SEPARATOR)
download_path = folder + filename

wget_options = (wget_options || "") + "--no-check-certificate" if Yadisk::OS.windows?
system("wget #{esc(download_url)} -O #{esc(download_path)} #{wget_options}")
end

private
def esc(str)
"#{escape_symbol}#{str}#{escape_symbol}"
end

def escape_symbol
Yadisk::OS.windows? ? '"' : "'"
end
end
end
2 changes: 1 addition & 1 deletion lib/yadisk/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Yadisk
VERSION = '0.2.0'
VERSION = '0.3.0'
end
2 changes: 1 addition & 1 deletion spec/feature/main_class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'yadisk'
require 'yadisk/main'

RSpec.describe Yadisk::Main do
let(:yadisk) { Yadisk::Main.new }
Expand Down
2 changes: 1 addition & 1 deletion yadisk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.description = "Command line tool for download file from Yandex.Disk through share link"
s.author = "Artem Yegorov"
s.email = 'yegorov0725@yandex.ru'
s.files = ["lib/yadisk.rb", "lib/yadisk/check_runtime.rb", "lib/yadisk/version.rb", "lib/yadisk/os.rb"]
s.files = ["lib/yadisk.rb", "lib/yadisk/main.rb", "lib/yadisk/check_runtime.rb", "lib/yadisk/version.rb", "lib/yadisk/os.rb"]
s.platform = Gem::Platform::RUBY
s.executables << 'yadisk'
s.add_development_dependency 'rspec', '~> 3.9', '< 4.0'
Expand Down

0 comments on commit 4683257

Please sign in to comment.