Class: Yadisk::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/yadisk.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: './', wget_options: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/yadisk.rb', line 13

def download(url, folder: './', 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 + "/" if not folder.end_with?('/')

  system("wget '#{download_url}' -O '#{folder}#{filename}' #{wget_options}")
end