Class: Yadisk::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/yadisk/main.rb

Constant Summary collapse

BASE_URL =
'https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key='

Instance Method Summary collapse

Instance Method Details

#download(url, folder: ".#{File::SEPARATOR}", wget_options: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/yadisk/main.rb', line 15

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