Class: Bideo::Client
- Inherits:
-
Object
- Object
- Bideo::Client
- Defined in:
- lib/bideo/client.rb
Instance Attribute Summary collapse
-
#download_urls ⇒ Object
readonly
Returns the value of attribute download_urls.
-
#file_names ⇒ Object
readonly
Returns the value of attribute file_names.
-
#save_directory ⇒ Object
readonly
Returns the value of attribute save_directory.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #download(path = "#{Dir.pwd}/tmp") ⇒ Object
-
#initialize(url = "") ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(url = "") ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 |
# File 'lib/bideo/client.rb', line 5 def initialize(url = "") @session = SecureRandom.hex(8) @file_names = ViddlRb.get_names(url) @url = url @download_urls = ViddlRb.get_urls_exts(url) end |
Instance Attribute Details
#download_urls ⇒ Object (readonly)
Returns the value of attribute download_urls.
3 4 5 |
# File 'lib/bideo/client.rb', line 3 def download_urls @download_urls end |
#file_names ⇒ Object (readonly)
Returns the value of attribute file_names.
3 4 5 |
# File 'lib/bideo/client.rb', line 3 def file_names @file_names end |
#save_directory ⇒ Object (readonly)
Returns the value of attribute save_directory.
3 4 5 |
# File 'lib/bideo/client.rb', line 3 def save_directory @save_directory end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
3 4 5 |
# File 'lib/bideo/client.rb', line 3 def session @session end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/bideo/client.rb', line 3 def url @url end |
Instance Method Details
#download(path = "#{Dir.pwd}/tmp") ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bideo/client.rb', line 12 def download(path = "#{Dir.pwd}/tmp" ) @save_directory = "#{path}/#{self.session}" urls_and_file_names = self.download_urls.zip(self.file_names) Dir.mkdir(@save_directory) urls_and_file_names.each do |download_url, file_name| open("#{@save_directory}/#{file_name}", "wb") do |file| open(download_url[:url]) do |uri| file.write(uri.read) end end end self end |