-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move yadisk.rb to yadisk/main.rb, bump version to 0.3.0
- Loading branch information
Showing
7 changed files
with
42 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = '[email protected]' | ||
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' | ||
|