-
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.
Implement Yadisk::Main class, write specs, update readme, add .gitignore
- Loading branch information
Showing
6 changed files
with
121 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
### Ruby ### | ||
*.gem | ||
*.rbc | ||
/.config | ||
/coverage/ | ||
/InstalledFiles | ||
/pkg/ | ||
/spec/reports/ | ||
/spec/examples.txt | ||
/test/tmp/ | ||
/test/version_tmp/ | ||
/tmp/ | ||
|
||
# Used by dotenv library to load environment variables. | ||
# .env | ||
|
||
## Specific to RubyMotion: | ||
.dat* | ||
.repl_history | ||
build/ | ||
*.bridgesupport | ||
build-iPhoneOS/ | ||
build-iPhoneSimulator/ | ||
|
||
## Specific to RubyMotion (use of CocoaPods): | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# vendor/Pods/ | ||
|
||
## Documentation cache and generated files: | ||
/.yardoc/ | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
## Environment normalization: | ||
/.bundle/ | ||
/vendor/bundle | ||
/lib/bundler/man/ | ||
|
||
# for a library or gem, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# Gemfile.lock | ||
# .ruby-version | ||
# .ruby-gemset | ||
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc | ||
|
||
# Ignore backup files | ||
*~ | ||
# Ignore download test files | ||
# /spec/files/ |
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 |
---|---|---|
|
@@ -19,12 +19,30 @@ $ gem install --dev yadisk | |
|
||
``` | ||
# Save to current directory | ||
$ yadisk https://yadi.sk/i/UFD | ||
$ yadisk https://yadi.sk/i/HEjuI2Ln3RiRcQ | ||
# Save to other directory | ||
$ yadisk https://yadi.sk/i/UFD /path/to/directory | ||
$ yadisk https://yadi.sk/i/HEjuI2Ln3RiRcQ /path/to/directory | ||
``` | ||
|
||
## How use for development | ||
|
||
``` | ||
# Local build and install to rubygems | ||
$ gem build yadisk.gemspec && gem install yadisk-* | ||
# Remove local file and uninstall from rubygems | ||
$ rm yadisk-*.gem && gem uninstall yadisk | ||
# Run script from local folder | ||
$ ruby -Ilib ./bin/yadisk https://yadi.sk/i/HEjuI2Ln3RiRcQ | ||
``` | ||
|
||
## Dependencies | ||
|
||
* [wget](https://www.gnu.org/software/wget/) | ||
* [ruby](https://www.ruby-lang.org/ru/downloads/) >= 2.2 | ||
|
||
## Test | ||
|
||
For run test use: | ||
|
@@ -39,5 +57,4 @@ Feel free for send me pull request. | |
|
||
## License | ||
|
||
MIT | ||
|
||
License (MIT) Copyright (c) 2018 Yegorov A. [email protected] |
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,8 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# handle ARGV, and execute Yadisk::Main class | ||
# encoding: utf-8 | ||
|
||
require 'yadisk' | ||
require 'yadisk/check_runtime' | ||
|
||
Yadisk::CheckRuntime.check_wget | ||
|
||
if ARGV.length == 1 | ||
Yadisk::Main.new.download(ARGV[0]) | ||
elsif ARGV.length == 2 | ||
Yadisk::Main.new.download(ARGV[0], folder: ARGV[1]) | ||
else | ||
puts "Use: $ yadisk url [/path/to/download/local/folder]\n" | ||
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 +1,25 @@ | ||
# write Yadisk::Main class | ||
# encoding: utf-8 | ||
|
||
require 'cgi' | ||
require 'cgi/util' | ||
require 'uri' | ||
require 'io/console' | ||
require 'json' | ||
|
||
module Yadisk | ||
class Main | ||
BASE_URL = 'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key=' | ||
def download(url, folder: './') | ||
enc_url = CGI::escape(url) | ||
|
||
puts "wget -qO - #{BASE_URL}#{enc_url}" | ||
res = IO.popen("wget -qO - #{BASE_URL}#{enc_url}").read | ||
json_res = JSON.parse(res) | ||
download_url = json_res['href'] | ||
filename = CGI::parse(URI(download_url).query)["filename"][0] | ||
folder = folder + "/" if not folder.end_with?('/') | ||
|
||
system("wget '#{download_url}' -O '#{folder}#{filename}'") | ||
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,6 +1,14 @@ | ||
require 'yadisk' | ||
|
||
RSpec.describe Yadisk::Main do | ||
it "#download" do | ||
yadisk = Yadisk::Main.new | ||
let(:yadisk) { Yadisk::Main.new } | ||
|
||
it "has download method" do | ||
expect(yadisk).to respond_to(:download) | ||
end | ||
|
||
it "must download file" do | ||
yadisk.download("https://yadi.sk/i/HEjuI2Ln3RiRcQ", folder: "./spec/files/") | ||
expect(File.exists?("./spec/files/Обои для рабочего стола.jpg")).to be true | ||
end | ||
end |
Empty file.